How To Use - Schwenkner/SugarSyncNet GitHub Wiki
To use SugarSyncNet services you need to create an instance of the SugarSyncNet.Client class. This class supports all the requests necessary for accessing SugarSync services.
SugarSyncNet.Client client = new SugarSyncNet.Client("API Key", "API private", "Application Id");
SugarSync requires an authentication bofore you can Access the services. It is a kind of oauth but without web authentication. To get the oauth token a refresh token has to be requested once.
client.UserLogin = await client.GetRefreshTokenAsync("userName", "password")
The response from GetRefreshToken / GetRefreshTokenAsync is a UserLogin containing the oauth token which can be used for further Logins. It is not necessary to get the refresh token everytime. Assigning the responded UserLogin to the client is suficciant for further requests.
The refresh token can be saved within the application.
string refreshToken = client.UserLogin.RefreshToken;
If the refresh token is already present, you can login using it.
client.UserLog = new SugarSyncNet.UserLogin("refreshToken");
In SugarSync a User has several predefined collections.
- Workspaces
- SyncFolders
- Deleted
- Magic briefcase
- Web Archive
- Mobile photos
- Albums
To access these top level collections the User informations must be fetched fom SugarSync with a Get request.
User user = await client.GetAsync<User>(Client.SugarSyncUrl + "user");
The User class then allows access to the predefines collections telling it's reference URLs.
SugarSync is organized in collections. A CollectionContents is similar to a folder, it can contain files or other collections. A CollectionContents is referenced by a "refernce URL".
To get collections informations you have to execute a Get request, i.e., the ollectionsContents of the users sync folder.
CollectionContents contents = await client.GetAsync<CollectionContents>(user.SyncFolders)
For other CollectionContents use the according reference URLs.
The CollectionContens class provides you with the following Information:
-
Collections
A list of further collections within this CollectionContent
-
Files
A list of files within this CollectionContent