2 This is a library for adding remoteStorage support to your client-side app. See http://tutorial.unhosted.5apps.com/ for example usage. [[Download](https://github.com/unhosted/remoteStorage.js/raw/master/build/latest/remoteStorage.js)]
11 <script src="./path/to/remoteStorage.js"></script>
12 <script src="./path/to/your/app.js"></script>
21 remoteStorage.getStorageInfo('user@example.com', function(err, storageInfo) {
22 var token = remoteStorage.receiveToken();
24 //we can access the 'notes' category on the remoteStorage of user@example.com:
25 var client = remoteStorage.createClient(storageInfo, 'notes', token);
26 client.put('foo', 'bar', function(err) {
27 client.get('foo', function(err, data) {
28 client.delete('foo', function(err) {
33 //get an access token for 'notes' by dancing OAuth with the remoteStorage of user@example.com:
34 window.location = remoteStorage.createOAuthAddress(storageInfo, ['notes'], window.location.href);
40 ### remoteStorage.getStorageInfo(userAddress, callback)
42 userAddress: string of the form 'user@host'
43 callback: function(err, storageInfo)
44 -err: null, or a string describing what went wrong
45 -storageInfo: an object describing some details of the user's remoteStorage
47 ### remoteStorage.createOAuthAddress(storageInfo, categories, redirectUri)
49 storageInfo: the object you got from the getStorageInfo call
50 categories: an array of strings describing categories of data you will be accessing.
51 @returns: string, the url you should go to for the OAuth dance
52 See https://github.com/unhosted/website/wiki/categories for a list of categories you might want to access.
54 ### remoteStorage.receiveToken()
56 @returns: when coming back from the OAuth dance, a string containing the bearer token. Otherwise, null.
58 ### remoteStorage.createClient(storageInfo, category, bearerToken)
60 storageInfo: the object you got from the getStorageInfo call
61 category: one of the strings from the array you passed to createOAuthAddress earlier
64 ### Client.get(key, callback)
66 key: a string, identifying which element you want to retrieve
67 callback: function(err, data)
68 -err: null, or a string describing what went wrong
69 -data: undefined, or a string, that is the current value of 'key' within 'category' on the user's remoteStorage
71 #### Client.put(key, value, callback)
73 key: a string, identifying which element you want to assign value to
74 value: a string you want to assign to the element identified by key
75 data: a string that, if successful, will be the new value of 'key' within 'category' on the user's remoteStorage
76 callback: function(err)
77 -err: null, or a string describing what went wrong
79 ### Client.delete(key, callback)
81 key: a string, identifying which element you want to reset to undefined
82 callback: function(err)
83 -err: null, or a string describing what went wrong
86 This library relies heavily on [CORS](http://caniuse.com/#search=cors).
88 Known to work: Firefox, Chrome, Safari, Safari iOS.
90 Might work: Firefox Mobile, Android stock browser, Opera 12+, Opera Mobile 12+, IE 10+.
92 Planned: IE 8 & 9 (please [help with this](https://groups.google.com/d/topic/unhosted/Xk1hJMr9i9c/discussion)!).
94 ## Version and license
95 This is version 0.5.2 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). To build: