2 This is a library for adding remoteStorage support to your client-side app. See http://tutorial.unhosted.5apps.com/ for example usage.
5 This is version 0.4.5 of the library, and you can use it under AGPL or MIT license - whatever floats your boat. Pull requests are very welcome (if you're not on github you can email them to michiel at unhosted.org).
8 This library relies heavily on [cors](http://caniuse.com/#search=cors).
9 Known to work: Firefox, Chrome, Safari, Safari-iOS.
10 Might work: Firefox-mobile, Android-native, Opera 12+, Opera-mobile 12+, IE 10+.
11 Coming soon: IE 8 & 9 (please help with this!).
21 <script src="./path/to/require.js"></script>
22 <script src="./path/to/your/app.js"></script>
31 require(['./path/to/remoteStorage'], function(remoteStorage) {
32 remoteStorage.getStorageInfo('user@example.com', function(err, storageInfo) {
33 var token = remoteStorage.receiveToken();
35 //we can access the 'notes' category on the remoteStorage of user@example.com:
36 var client = remoteStorage.createClient(storageInfo, 'notes', bearerToken);
37 client.put('foo', 'bar', function(err) {
38 client.get('foo', function(err, data) {
39 client.delete('foo', function(err) {
44 //get an access token for 'notes' by dancing OAuth with the remoteStorage of user@example.com:
45 window.location = remoteStorage.createOAuthAddress(storageInfo, ['notes'], window.location.href);
52 ### remoteStorage.getStorageInfo(userAddress, callback)
54 userAddress: string of the form 'user@host'
55 callback: function(err, storageInfo)
56 -err: null, or a string describing what went wrong
57 -storageInfo: an object describing some details of the user's remoteStorage
59 ### remoteStorage.createOAuthAddress(storageInfo, categories, redirectUri)
61 storageInfo: the object you got from the getStorageInfo call
62 categories: an array of strings describing categories of data you will be accessing.
63 @returns: string, the url you should go to for the OAuth dance
64 See https://github.com/unhosted/website/wiki/categories for a list of categories you might want to access.
66 ### remoteStorage.receiveToken()
68 @returns: when coming back from the OAuth dance, a string containing the bearer token. Otherwise, null.
70 ### remoteStorage.createClient(storageInfo, category, bearerToken)
72 storageInfo: the object you got from the getStorageInfo call
73 category: one of the strings from the array you passed to createOAuthAddress earlier
76 ### Client.get(key, callback)
78 key: a string, identifying which element you want to retrieve
79 callback: function(err, data)
80 -err: null, or a string describing what went wrong
81 -data: undefined, or a string, that is the current value of 'key' within 'category' on the user's remoteStorage
83 #### Client.put(key, value, callback)
85 key: a string, identifying which element you want to assign value to
86 value: a string you want to assign to the element identified by key
87 data: a string that, if successful, will be the new value of 'key' within 'category' on the user's remoteStorage
88 callback: function(err)
89 -err: null, or a string describing what went wrong
91 ### Client.delete(key, callback)
93 key: a string, identifying which element you want to reset to undefined
94 callback: function(err)
95 -err: null, or a string describing what went wrong