A beta version of CSPro 8.1 was released this week. In the run-up to the release, we will highlight some new features.
Prior to this version, when connecting to a synchronization service using syncconnect, you had to specify the type of the service. For example:
Now, synchronization connection strings allow you to define all aspects of the connection in a single string. The above code could be rewritten as:
Connections strings have been used for data sources for several releases, and now are extended to synchronization connections. Specifying properties is the same as with data sources. This logic shows the old way of specifying a username and password, and how to do so by using the connection string:
syncconnect("https://example.org/csweb/api|username=jackw&password=MyPa%24%24w0rd%21")
When constructing property names and values from dynamic input, you can use the encode function to ensure that the strings are properly encoded:
"https://example.org/csweb/api|username=%s&password=%s",
encode(PercentEncoding, "jackw"),
encode(PercentEncoding, "MyPa$$w0rd!")
);
syncconnect(cswebConnection);
Because a single string contains all information needed to make the connection, it is easy to change the synchronization service used by your application. For example, while testing, you may want to synchronize your data locally simply to test your application, and then may change to Dropbox for production. You could declare a variable that you can change once you move to production:
string SyncService = "./local-sync-files|createDirectory=true";
// for production, comment the line above and enable the one below
// string SyncService = "Dropbox";
syncconnect(SyncService);