rhoconnect 3.3.1.beta2 → 3.3.1.beta3

Sign up to get free protection for your applications and to get access to all the features.
data/doc/rest-api.txt CHANGED
@@ -25,17 +25,21 @@ All API calls will return http 200 and requested data (if applied). Otherwise, A
25
25
 
26
26
  handle_api_error("Can't get license information") do
27
27
  @license_info = JSON.parse(
28
- RestClient.post(
29
- "#{server}/api/get_license_info",
30
- { :api_token => @token }.to_json,
31
- :content_type => :json
28
+ RestClient.get(
29
+ "#{server}/rc/v1/system/license",
30
+ {'X-RhoConnect-API-TOKEN' => @api_token}
32
31
  ).body
33
32
  )
34
33
  end
35
34
 
36
- ## API Methods
35
+ ## API Methods (REST API version 1)
37
36
 
38
- ### `login`
37
+ NOTE: All routes that require admin privileges must pass the API token using the special header
38
+ 'X-RhoConnect-API-TOKEN':api_token_string
39
+
40
+ ### System Resource (requires API token)
41
+
42
+ #### `POST /rc/v1/system/login`
39
43
  Before you can use RhoConnect API you should login to the RhoConnect server and get API token:
40
44
 
41
45
  :::ruby
@@ -46,355 +50,285 @@ Before you can use RhoConnect API you should login to the RhoConnect server and
46
50
  login = "rhoadmin"
47
51
  password = ""
48
52
 
49
- token = RestClient.post("#{server}/login", { :login => login, :password => password }.to_json, :content_type => :json)
53
+ @api_token = RestClient.post("#{server}/rc/v1/system/login", { :login => login, :password => password }.to_json, :content_type => :json)
50
54
 
51
- ### `get_license_info`
55
+ #### `GET /rc/v1/system/license`
52
56
  Returns license information of the currently used license
53
57
 
54
58
  :::ruby
55
- license_info = RestClient.post(
56
- "#{server}/api/get_license_info",
57
- {:api_token => token}.to_json, :content_type => :json
59
+ license_info = RestClient.get(
60
+ "#{server}/rc/v1/system/license",
61
+ {'X-RhoConnect-API-TOKEN' => @api_token}
58
62
  ).body
59
63
 
60
- ### `reset`
64
+ #### `POST /rc/v1/system/reset`
61
65
  Reset the server: flush db and re-bootstrap server
62
66
 
63
67
  :::ruby
64
- RestClient.post("#{server}/api/reset",
65
- { :api_token => token }.to_json,
66
- :content_type => :json
68
+ RestClient.post("#{server}/rc/v1/system/reset",
69
+ {}.to_json,
70
+ {:content_type => :json,
71
+ 'X-RhoConnect-API-TOKEN' => @api_token}
67
72
  )
68
73
 
69
- ### `ping`
70
- Sends PUSH message to all devices of the specified user(s):
74
+ #### `GET /rc/v1/system/appserver`
75
+ Returns the url of the plugin's backend from the RhoConnect server.
71
76
 
72
77
  :::ruby
73
- # :message - message which will be used to display notification popup dialog on the device
74
- # :badge - iphone specific badge
75
- # :sound - name of the sound file to play upon receiving PUSH notification
76
- # :vibrate - number of seconds to vibrate upon receiving PUSH notification
77
- # :sources - list of data source names to be synced upon receiving PUSH notification
78
- ping_params = {
79
- :api_token => token,
80
- :user_id => [array_of_users],
81
- :sources => source_name,
82
- :message => 'hello world',
83
- :vibrate => 2000,
84
- :sound => 'hello.mp3'
85
- }
86
-
87
- RestClient.post(
88
- "#{server}/api/ping",ping_params.to_json,
89
- :content_type => :json
90
- )
91
-
92
- ### `push_objects`
93
- Push new objects or object updates to RhoConnect. These changes will be sent to device next time it synchronizes.
78
+ adapter_url = RestClient.get(
79
+ "#{server}/rc/v1/system/appserver",
80
+ {'X-RhoConnect-API-TOKEN' => @api_token}
81
+ ).body
94
82
 
95
- **NOTE: you may use [ping](/rhoconnect/push) to notify client and trigger sync.**
83
+ #### `POST /rc/v1/system/appserver`
84
+ Saves the url of the plugin's backend to the RhoConnect server.
96
85
 
97
86
  :::ruby
98
- # list of objects in the canonical hash of hashes structure
99
- data = {
100
- '5' => {
101
- 'name' => 'iPhone'
102
- }
103
- }
104
87
  RestClient.post(
105
- "#{server}/api/push_objects",
106
- {
107
- :api_token => token,
108
- :user_id => user_id,
109
- :source_id => source_name,
110
- :objects => data
111
- }.to_json,
112
- :content_type => :json
113
- )
88
+ "#{server}/rc/v1/system/appserver",
89
+ {
90
+ :adapter_url => url
91
+ }.to_json,
92
+ {:content_type => :json,
93
+ 'X-RhoConnect-API-TOKEN' => @api_token}
94
+ )
114
95
 
115
- **NOTE: Normally, `push_objects` method will refresh the whole :md document in Redis. However, in case of large-size
116
- documents, `push_objects` method can be optimized by invoking only the necessary updates. This can help reducing
117
- the number of transactions with Redis. To force the optimization, user can use the `:rebuild_md => false` flag
118
- in the `push_objects` parameters hash.**
119
-
120
- ### `push_deletes`
121
- Delete objects from RhoConnect. These objects will be deleted from the device the next time it synchronizes.
122
-
123
- **NOTE: You may use [ping](/rhoconnect/push) to notify client and trigger sync.**
96
+ #### `GET /rc/v1/system/stats`
97
+ Retrieves stats for a given metric key:
124
98
 
125
99
  :::ruby
126
- # object_ids is an array of objects to be deleted
127
100
  RestClient.post(
128
- "/api/push_deletes",
129
- {
130
- :api_token => api_token,
131
- :user_id => user_id,
132
- :source_id => source_name,
133
- :objects => object_ids
134
- }.to_json,
135
- :content_type => :json
136
- )
137
-
138
- **NOTE: Normally, `push_deletes` method will refresh the whole :md document in Redis. However, in case of large-size
139
- documents, `push_deletes` method can be optimized by invoking only the necessary updates. This can help reducing
140
- the number of transactions with Redis. To force the optimization, user can use the `:rebuild_md => false` flag
141
- in the `push_deletes` parameters hash.
142
-
143
- ### `fast_insert`
144
- Push new objects to RhoConnect. Changes are inserted into the Redis set without any checking for previous existence.
145
- This way, the insert is very fast, but user must ensure that the object didn't exist before. No safeguards are implemented.
146
- Use this method only when you can ensure the integrity of the data.
101
+ "#{server}/rc/v1/system/stats",
102
+ {
103
+ 'X-RhoConnect-API-TOKEN' => @api_token,
104
+ :params => {:metric => 'foo',
105
+ :start => 0,
106
+ :finish => -1}
107
+ }
108
+ )
147
109
 
148
- **NOTE: you may use [ping](/rhoconnect/push) to notify client after the insert and trigger sync.**
110
+ Retrieves a list of metric keys matching a given pattern. This supports 'glob' or '*' style pattern matching. For example, all metric keys associated with 'Product' source adapter methods:
149
111
 
150
112
  :::ruby
151
- # list of objects in the canonical hash of hashes structure
152
- data = {
153
- '5' => {
154
- 'name' => 'iPhone'
155
- }
156
- }
157
113
  RestClient.post(
158
- "#{server}/api/fast_insert",
114
+ "#{server}/rc/v1/system/stats",
159
115
  {
160
- :api_token => token,
161
- :user_id => user_id,
162
- :source_id => source_name,
163
- :data => data
164
- }.to_json,
165
- :content_type => :json
116
+ 'X-RhoConnect-API-TOKEN' => @api_token,
117
+ :params => {:names => 'sources:*:Product'}
118
+ }
166
119
  )
167
120
 
168
- ### `fast_update`
169
- Push object updates to RhoConnect. This method doesn't involve pulling the existing data out of Redis. Instead it required user to provide the previous state of the data. This way, this method allows for very fast updates (since it just removes the previous data from set and adds new ones). However, no data integrity checks are performed. Therefore, this method must be used only if user can ensure the integrity of the data (i.e. previous state must exist, otherwise it won't be properly deleted). Also, this method can be used to perform fast appends and deletes for any of the object's attributes (However, you shoudn't use this method to remove all of the attributes, `fast_delete` should be used instead.)
121
+ ### Store Resource (requires API token)
170
122
 
171
- **NOTE: you may use [ping](/rhoconnect/push) to notify client after the update and trigger sync.**
123
+ #### `GET /rc/v1/store/:doc`
124
+ Return content of a given document stored in Redis.
172
125
 
173
126
  :::ruby
174
- # list of objects in the canonical hash of hashes structure
175
- # delete_data contains previous state of the object (to be deleted)
176
- delete_data = {
177
- '5' => {
178
- 'name' => 'iPhone'
179
- }
180
- }
181
- # data contains new state of the object
182
- # to be inserted
183
- data = {
184
- '5' => {
185
- 'name' => 'HTC'
186
- }
187
- }
188
- RestClient.post(
189
- "#{server}/api/fast_update",
127
+ res = RestClient.get(
128
+ "#{server}/rc/v1/store/<docname>",
190
129
  {
191
- :api_token => token,
192
- :user_id => user_id,
193
- :source_id => source_name,
194
- :delete_data => delete_data,
195
- :data => data
196
- }.to_json,
197
- :content_type => :json
198
- )
199
-
200
- ### `fast_delete`
201
- Push object deletes to RhoConnect. This method doesn't involve pulling the existing data out of Redis and removing all of its attributes. Instead it required user to provide all of the object's data in the hash to be removed. This way, this method allows for very fast deletes (since it just removes the object's data from set). However, no data integrity checks are performed. Therefore, this method must be used only if user can ensure the integrity of the data (i.e. supply all of the object's data to be removed, otherwise some object's data will remain in Redis).
130
+ 'X-RhoConnect-API-TOKEN' => @api_token
131
+ }
132
+ ).body
202
133
 
203
- **NOTE: you may use [ping](/rhoconnect/push) to notify client after the delete and trigger sync.**
134
+ #### `POST /rc/v1/store/:doc`
135
+ Sets the content of the specified server document. Data should be either a string or hash of hashes.
136
+ If `append` flag is set to `true` , the data is appended to the current doc (if it exists) instead of replacing it.
204
137
 
205
138
  :::ruby
206
- # list of objects in the canonical hash of hashes structure
207
- # data contains all of the object's data (to be deleted)
208
- data = {
209
- '5' => {
210
- 'name' => 'iPhone'
211
- }
212
- }
213
139
  RestClient.post(
214
- "#{server}/api/fast_delete",
140
+ "#{server}/rc/v1/store/<docname>",
215
141
  {
216
- :api_token => token,
217
- :user_id => user_id,
218
- :source_id => source_name,
219
- :data => data
142
+ :data => data,
143
+ :append => false
220
144
  }.to_json,
221
- :content_type => :json
222
- )
223
-
224
- ### `get_adapter`
225
- Returns the url of the source adapter from the RhoConnect server.
226
-
227
- :::ruby
228
- adapter_url = RestClient.post(
229
- "#{server}/api/get_adapter",
230
- {
231
- :api_token => token
232
- }.to_json,
233
- :content_type => :json
234
- ).body
235
-
236
- ### `save_adapter`
237
- Saves the url of the source adapter to the RhoConnect server.
238
-
239
- :::ruby
240
- RestClient.post(
241
- "#{server}/api/save_adapter",
242
- {
243
- :api_token => token,
244
- :adapter_url => url
245
- }.to_json,
246
- :content_type => :json
145
+ {:content_type => :json,
146
+ 'X-RhoConnect-API-TOKEN' => @api_token}
247
147
  )
248
148
 
249
- ### `upload_file`
250
- Upload a file to the RhoConnect server.
251
-
252
- :::ruby
253
- RestClient.post(
254
- "#{server}/api/upload_file",
255
- {
256
- :api_token => token,
257
- :upload_file => path_to_file
258
- }.to_json,
259
- :content_type => :json
260
- )
261
-
262
- ### `list_users`
263
- List users registered with this RhoConnect application.
149
+ ### User Resource (requires API token)
264
150
 
265
- :::ruby
266
- users = RestClient.post(
267
- "#{server}/api/list_users",
268
- { :api_token => token }.to_json,
269
- :content_type => :json
270
- ).body
271
-
272
- ### `create_user`
151
+ #### `POST /rc/v1/users`
273
152
  Create a user in this RhoConnect application.
274
153
 
275
154
  :::ruby
276
- RestClient.post("#{server}/api/create_user",
277
- {
278
- :api_token => token,
155
+ RestClient.post("#{server}/rc/v1/users",
156
+ {
279
157
  :attributes => {
280
158
  :login => login,
281
159
  :password => password
282
160
  }
283
161
  }.to_json,
284
- :content_type => :json
162
+ {:content_type => :json,
163
+ 'X-RhoConnect-API-TOKEN' => @api_token}
285
164
  )
286
165
 
287
- ### `delete_user`
166
+ #### `DELETE /rc/v1/users/:user_id`
288
167
  Delete User and all associated devices from the RhoConnect application.
289
168
 
290
169
  :::ruby
291
- RestClient.post(
292
- "#{server}/api/delete_user",
170
+ RestClient.delete(
171
+ "#{server}/rc/v1/users/<user_id>",
293
172
  {
294
- :api_token => token,
295
- :user_id => user_id
296
- }.to_json,
297
- :content_type => :json
173
+ 'X-RhoConnect-API-TOKEN' => @api_token
174
+ }
298
175
  )
299
176
 
300
- ### `update_user`
177
+ #### `PUT /rc/v1/users/:user_id`
301
178
  Update attributes for a user on this RhoConnect application.
302
179
 
303
180
  :::ruby
304
- RestClient.post(
305
- "#{server}/api/update_user",
181
+ RestClient.put(
182
+ "#{server}/rc/v1/users/<user_id>",
306
183
  {
307
- :api_token => token,
308
- :user_id => user_id
309
184
  :attributes => {
310
185
  :a_user_specific_attribute => a_user_specific_attribute_value
311
186
  }
312
187
  }.to_json,
313
- :content_type => :json
188
+ {:content_type => :json,
189
+ 'X-RhoConnect-API-TOKEN' => @api_token}
314
190
  )
315
191
 
316
- ### `list_clients`
192
+ #### `GET /rc/v1/users`
193
+ List users registered with this RhoConnect application.
194
+
195
+ :::ruby
196
+ users = RestClient.get(
197
+ "#{server}/rc/v1/users",
198
+ {
199
+ 'X-RhoConnect-API-TOKEN' => @api_token
200
+ }
201
+ ).body
202
+
203
+ #### `GET /rc/v1/users/:user_id`
204
+ Returns the information for the specified user.
205
+
206
+ :::ruby
207
+ user_info = RestClient.get(
208
+ "#{server}/rc/v1/users/<user_id>",
209
+ {
210
+ 'X-RhoConnect-API-TOKEN' => @api_token
211
+ }
212
+ ).body
213
+
214
+ #### `GET /rc/v1/users/:user_id/clients`
317
215
  List clients (devices) associated with given user.
318
216
 
319
217
  :::ruby
320
- clients = RestClient.post("#{server}/api/list_clients",
218
+ clients = RestClient.get("#{server}/rc/v1/users/<user_id>/clients",
321
219
  {
322
- :api_token => token,
323
- :user_id => user_id
324
- }.to_json,
325
- :content_type => :json
220
+ 'X-RhoConnect-API-TOKEN' => @api_token
221
+ }
326
222
  ).body
327
223
 
328
224
  Returns list of client ids.
329
225
 
330
- ### `create_client`
331
- Creates a client (device) for a given user.
332
-
226
+ #### `DELETE /rc/v1/users/:user_id/clients/:client_id`
227
+ Deletes the specified client (device) for the given user.
228
+
333
229
  :::ruby
334
- RestClient.post(
335
- "#{server}/api/create_client",
230
+ RestClient.delete(
231
+ "#{server}/rc/v1/users/<user_id>/clients/<client_id>",
336
232
  {
337
- :api_token => token,
338
- :user_id => user_id
339
- }.to_json,
340
- :content_type => :json
233
+ 'X-RhoConnect-API-TOKEN' => @api_token
234
+ }
235
+ )
236
+
237
+ #### `GET /rc/v1/users/:user_id/sources/:source_id/docnames`
238
+ Return list of document keys associated with given source and user.
239
+
240
+ If `:user_id` set to '*', this call will return list of keys for 'shared' documents.
241
+
242
+ :::ruby
243
+ docs = RestClient.get(
244
+ "#{server}/rc/v1/users/<user_id>/sources/<source_id>/docnames",
245
+ {
246
+ 'X-RhoConnect-API-TOKEN' => @api_token
247
+ }
341
248
  ).body
342
249
 
343
- ### `delete_client`
344
- Deletes the specified client (device).
250
+
251
+ #### `POST /rc/v1/users/ping`
252
+ Sends PUSH message to all devices of the specified user(s):
345
253
 
346
254
  :::ruby
255
+ # :message - message which will be used to display notification popup dialog on the device
256
+ # :badge - iphone specific badge
257
+ # :sound - name of the sound file to play upon receiving PUSH notification
258
+ # :vibrate - number of seconds to vibrate upon receiving PUSH notification
259
+ # :sources - list of data source names to be synced upon receiving PUSH notification
260
+ ping_params = {
261
+ :api_token => token,
262
+ :user_id => [array_of_users],
263
+ :sources => source_name,
264
+ :message => 'hello world',
265
+ :vibrate => 2000,
266
+ :sound => 'hello.mp3'
267
+ }
268
+
347
269
  RestClient.post(
348
- "#{server}/api/delete_client",
270
+ "#{server}/rc/v1/users/ping", ping_params.to_json,
271
+ { :content_type => :json,
272
+ 'X-RhoConnect-API-TOKEN' => @api_token }
273
+ )
274
+
275
+ #### `GET /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
276
+ Return content of a given source document for the specified user.
277
+
278
+ :::ruby
279
+ res = RestClient.get(
280
+ "#{server}/rc/v1/users/<user_id>/sources/<source_id>/docs/<docname>",
349
281
  {
350
- :api_token => token,
351
- :user_id => user_id,
352
- :client_id => client_id
353
- }.to_json,
354
- :content_type => :json
355
- )
282
+ 'X-RhoConnect-API-TOKEN' => @api_token
283
+ }
284
+ ).body
356
285
 
357
- ### `get_client_params`
358
- Returns client (device) attributes, such as `device_type`, `device_pin`, `device_port`. These attributes used by [RhoConnect push](/rhoconnect/push).
286
+ #### `POST /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
287
+ Sets the content of the specified source document for the given user. Data should be either a string or hash of hashes.
288
+ If `append` flag is set to `true` , the data is appended to the current doc (if it exists) instead of replacing it.
359
289
 
360
290
  :::ruby
361
291
  RestClient.post(
362
- "#{server}/api/get_client_params",
292
+ "#{server}/rc/v1/users/<user_id>/sources/<source_id>/docs/<docname>",
363
293
  {
364
- :api_token => token,
365
- :client_id => client_id
294
+ :data => data,
295
+ :append => false
366
296
  }.to_json,
367
- :content_type => :json
368
- ).body
297
+ {:content_type => :json,
298
+ 'X-RhoConnect-API-TOKEN' => @api_token}
299
+ )
300
+
301
+ ### Read State Resource (requires API token)
369
302
 
370
- ### `list_client_docs`
371
- Returns list of document keys associated with particular client. These documents are used by the server to sync data with the client.
372
- CD (:cd) - client document; represents the state of the client (set of all objects on the given client).
303
+ #### `POST /rc/v1/read_state/users/:user_id/sources/:source_id`
304
+ Sets source poll interval to "current time plus x seconds".
373
305
 
374
306
  :::ruby
375
307
  RestClient.post(
376
- "#{server}/api/list_client_docs",
308
+ #{server}/rc/v1/read_state/users/<user_id>/sources/<source_id>",
377
309
  {
378
- :api_token => token,
379
- :source_id => source_id,
380
- :client_id => client_id
310
+ :refresh_time => 100
381
311
  }.to_json,
382
- :content_type => :json
383
- ).body
312
+ {:content_type => :json,
313
+ 'X-RhoConnect-API-TOKEN' => @api_token}
314
+ )
384
315
 
385
- ### `list_sources`
386
- Return list of source adapters for this RhoConnect application.
316
+ This will set the refresh time to 100 seconds from the current time. Calling `set_refresh_time` with no `:refresh_time` will trigger a refresh on the sync request for the source.
317
+
318
+ ### Source Controller (requires API token)
319
+
320
+ #### `GET /rc/v1/sources/type/:partition_type`
321
+ Return list of source adapters for this RhoConnect application for the given partition type.
322
+ Partition type can be either `app` or `user`.
387
323
 
388
324
  :::ruby
389
- sources = RestClient.post("#{server}/api/list_sources",
325
+ sources = RestClient.get("#{server}/rc/v1/sources/type/<partition_type>",
390
326
  {
391
- :api_token => token,
392
- :partition_type => partition
393
- }.to_json,
394
- :content_type => :json
327
+ 'X-RhoConnect-API-TOKEN' => @api_token
328
+ }
395
329
  ).body
396
330
 
397
- ### `get_source_params`
331
+ #### `GET /rc/v1/sources/:source_id`
398
332
  Return attributes associated with a given source:
399
333
 
400
334
  * `name` - name of the data source
@@ -408,117 +342,206 @@ Return attributes associated with a given source:
408
342
  **NOTE: query or create/update/delete methods of the source adapter will be executed [asynchronously](/rhoconnect/async-jobs) if a queue name is defined.**
409
343
 
410
344
  :::ruby
411
- attributes = RestClient.post("#{server}/api/get_source_params",
345
+ attributes = RestClient.get("#{server}/rc/v1/sources/<source_id>",
412
346
  {
413
- :api_token => token,
414
- :source_id => source_id
415
- }.to_json,
416
- :content_type => :json
347
+ 'X-RhoConnect-API-TOKEN' => @api_token
348
+ }
417
349
  ).body
418
350
 
419
- ### `update_source_params`
351
+ #### `PUT /rc/v1/sources/:source_id`
420
352
  Updates attributes associated with a given source:
421
353
 
422
354
  `poll_interval` - query poll interval; defines how often RhoConnect will call source adapter to query for new data, set to -1 to disable polling, 0 to always poll.
423
355
 
424
356
  :::ruby
425
- attributes = RestClient.post("#{server}/api/update_source_params",
357
+ RestClient.put("#{server}/rc/v1/sources/<source_id>",
426
358
  {
427
- :api_token => token,
428
- :source_name => source_name,
429
359
  :user_name => user,
430
360
  :data => {:poll_interval => 25}
431
361
  }.to_json,
432
- :content_type => :json
362
+ {:content_type => :json,
363
+ 'X-RhoConnect-API-TOKEN' => @api_token}
433
364
  ).body
434
365
 
435
- ### `set_refresh_time`
436
- Sets source poll interval to "current time plus x seconds".
366
+ ### Client Resource (requires API token)
367
+
368
+ #### `GET /rc/v1/clients/:client_id`
369
+ Returns client (device) attributes, such as `device_type`, `device_pin`, `device_port`. These attributes used by [RhoConnect push](/rhoconnect/push).
370
+
371
+ :::ruby
372
+ client_attributes = RestClient.get(
373
+ "#{server}/rc/v1/clients/<client_id>",
374
+ {
375
+ 'X-RhoConnect-API-TOKEN' => @api_token
376
+ }
377
+ ).body
378
+
379
+ #### `GET /rc/v1/clients/:client_id/sources/:source_id/docnames`
380
+ Returns list of document keys associated with particular client for a given source. These documents are used by the server to sync data with the client.
381
+
382
+ :::ruby
383
+ docs = RestClient.get(
384
+ "#{server}/rc/v1/clients/:client_id/sources/:source_id/docnames",
385
+ {
386
+ 'X-RhoConnect-API-TOKEN' => @api_token
387
+ }
388
+ ).body
389
+
390
+ #### `GET /rc/v1/clients/:client_id/sources/:source_id/docs/:doc`
391
+ Return content of a given source document for the specified client.
392
+
393
+ :::ruby
394
+ res = RestClient.get(
395
+ "#{server}/rc/v1/clients/<client_id>/sources/<source_id>/docs/<docname>",
396
+ {
397
+ 'X-RhoConnect-API-TOKEN' => @api_token
398
+ }
399
+ ).body
400
+
401
+ #### `POST /rc/v1/clients/:client_id/sources/:source_id/docs/:doc`
402
+ Sets the content of the specified source document for the given client. Data should be either a string or hash of hashes.
403
+ If `append` flag is set to `true` , the data is appended to the current doc (if it exists) instead of replacing it.
437
404
 
438
405
  :::ruby
439
406
  RestClient.post(
440
- "/api/set_refresh_time",
407
+ "#{server}/rc/v1/clients/<client_id>/sources/<source_id>/docs/<docname>",
441
408
  {
442
- :api_token => @api_token,
443
- :source_name => source_name,
444
- :user_name => user,
445
- :refresh_time => 100
409
+ :data => data,
410
+ :append => false
446
411
  }.to_json,
447
- :content_type => :json
448
- )
412
+ {:content_type => :json,
413
+ 'X-RhoConnect-API-TOKEN' => @api_token}
414
+ )
449
415
 
450
- This will set the refresh time to 100 seconds from the current time. Calling `set_refresh_time` with no `:refresh_time` will trigger a refresh on the sync request for the source.
451
416
 
452
- ### `list_source_docs`
453
- Return list of document keys associated with given source and user.
417
+ ### Plugin methods (requires API token)
454
418
 
455
- If `:user_id` set to '*', this call will return list of keys for 'shared' documents.
419
+ #### `POST /app/v1/:source_name/push_objects`
420
+ Push new objects or object updates to RhoConnect. These changes will be sent to device next time it synchronizes.
456
421
 
457
- MD(:md) - master document; represents state of the backend (set of all objects for the given app/user/source on the backend service).
422
+ **NOTE: you may use [ping](/rhoconnect/push) to notify client and trigger sync.**
458
423
 
459
424
  :::ruby
460
- docs = RestClient.post(
461
- "#{server}/api/list_source_docs",
425
+ # list of objects in the canonical hash of hashes structure
426
+ data = {
427
+ '5' => {
428
+ 'name' => 'iPhone'
429
+ }
430
+ }
431
+ RestClient.post(
432
+ "#{server}/app/v1/<source_name>/push_objects",
462
433
  {
463
- :api_token => token,
464
- :source_id => source_id,
465
- :user_id => user_id
434
+ :user_id => user_id,
435
+ :objects => data
466
436
  }.to_json,
467
- :content_type => :json
468
- ).body
437
+ {:content_type => :json,
438
+ 'X-RhoConnect-API-TOKEN' => @api_token}
439
+ )
440
+
441
+ **NOTE: Normally, `push_objects` method will refresh the whole :md document in Redis. However, in case of large-size
442
+ documents, `push_objects` method can be optimized by invoking only the necessary updates. This can help reducing
443
+ the number of transactions with Redis. To force the optimization, user can use the `:rebuild_md => false` flag
444
+ in the `push_objects` parameters hash.**
469
445
 
470
- ### `get_db_doc`
471
- Return content of a given document (client or source).
446
+ #### `POST /app/v1/:source_name/push_deletes`
447
+ Delete objects from RhoConnect. These objects will be deleted from the device the next time it synchronizes.
448
+
449
+ **NOTE: You may use [ping](/rhoconnect/push) to notify client and trigger sync.**
472
450
 
473
451
  :::ruby
474
- res = RestClient.post(
475
- "#{server}/api/get_db_doc",
452
+ # object_ids is an array of objects to be deleted
453
+ RestClient.post(
454
+ "#{server}/app/v1/<source_name>/push_deletes",
476
455
  {
477
- :api_token => token,
478
- :doc => doc
479
- }.to_json,
480
- :content_type => :json
481
- ).body
456
+ :user_id => user_id,
457
+ :objects => object_ids
458
+ }.to_json,
459
+ {:content_type => :json,
460
+ 'X-RhoConnect-API-TOKEN' => @api_token}
461
+ )
482
462
 
483
- ### `set_db_doc`
484
- Sets the content of the specified server document. Data should be either a string or hash of hashes. Data type should be set accordingly.
485
- If `append` flag is set to `true` , the data is appended to the current doc (if it exists) instead of replacing it.
463
+ **NOTE: Normally, `push_deletes` method will refresh the whole :md document in Redis. However, in case of large-size
464
+ documents, `push_deletes` method can be optimized by invoking only the necessary updates. This can help reducing
465
+ the number of transactions with Redis. To force the optimization, user can use the `:rebuild_md => false` flag
466
+ in the `push_deletes` parameters hash.**
467
+
468
+ #### `POST /app/v1/:source_name/fast_insert`
469
+ Push new objects to RhoConnect. Changes are inserted into the Redis set without any checking for previous existence.
470
+ This way, the insert is very fast, but user must ensure that the object didn't exist before. No safeguards are implemented.
471
+ Use this method only when you can ensure the integrity of the data.
472
+
473
+ **NOTE: you may use [ping](/rhoconnect/push) to notify client after the insert and trigger sync.**
486
474
 
487
475
  :::ruby
476
+ # list of objects in the canonical hash of hashes structure
477
+ data = {
478
+ '5' => {
479
+ 'name' => 'iPhone'
480
+ }
481
+ }
488
482
  RestClient.post(
489
- "#{server}/api/set_db_doc",
483
+ "#{server}/app/v1/<source_name>/fast_insert",
490
484
  {
491
- :api_token => token,
492
- :doc => doc,
493
- :data => data,
494
- :append => false
485
+ :user_id => user_id,
486
+ :objects => data
495
487
  }.to_json,
496
- :content_type => :json
497
- )
488
+ {:content_type => :json,
489
+ 'X-RhoConnect-API-TOKEN' => @api_token}
490
+ )
491
+
492
+ #### `POST /app/v1/:source_name/fast_update`
493
+ Push object updates to RhoConnect. This method doesn't involve pulling the existing data out of Redis. Instead it required user to provide the previous state of the data. This way, this method allows for very fast updates (since it just removes the previous data from set and adds new ones). However, no data integrity checks are performed. Therefore, this method must be used only if user can ensure the integrity of the data (i.e. previous state must exist, otherwise it won't be properly deleted). Also, this method can be used to perform fast appends and deletes for any of the object's attributes (However, you shoudn't use this method to remove all of the attributes, `fast_delete` should be used instead.)
498
494
 
499
- ### `stats`
500
- Retrieves stats for a given metric key:
495
+ **NOTE: you may use [ping](/rhoconnect/push) to notify client after the update and trigger sync.**
501
496
 
502
497
  :::ruby
498
+ # list of objects in the canonical hash of hashes structure
499
+ # delete_data contains previous state of the object (to be deleted)
500
+ delete_data = {
501
+ '5' => {
502
+ 'name' => 'iPhone'
503
+ }
504
+ }
505
+ # data contains new state of the object
506
+ # to be inserted
507
+ data = {
508
+ '5' => {
509
+ 'name' => 'HTC'
510
+ }
511
+ }
503
512
  RestClient.post(
504
- "#{server}/api/stats",
513
+ "#{server}/app/v1/<source_name>/fast_update",
505
514
  {
506
- :api_token => @api_token,
507
- :metric => 'foo',
508
- :start => 0,
509
- :finish => -1
515
+ :user_id => user_id,
516
+ :delete_data => delete_data,
517
+ :data => data
510
518
  }.to_json,
511
- :content_type => :json
519
+ {:content_type => :json,
520
+ 'X-RhoConnect-API-TOKEN' => @api_token}
512
521
  )
513
522
 
514
- Retrieves a list of metric keys matching a given pattern. This supports 'glob' or '*' style pattern matching. For example, all metric keys associated with 'Product' source adapter methods:
523
+ #### `POST /app/v1/:source_name/fast_delete`
524
+ Push object deletes to RhoConnect. This method doesn't involve pulling the existing data out of Redis and removing all of its attributes. Instead it required user to provide all of the object's data in the hash to be removed. This way, this method allows for very fast deletes (since it just removes the object's data from set). However, no data integrity checks are performed. Therefore, this method must be used only if user can ensure the integrity of the data (i.e. supply all of the object's data to be removed, otherwise some object's data will remain in Redis).
525
+
526
+ **NOTE: you may use [ping](/rhoconnect/push) to notify client after the delete and trigger sync.**
515
527
 
516
528
  :::ruby
529
+ # list of objects in the canonical hash of hashes structure
530
+ # data contains all of the object's data (to be deleted)
531
+ data = {
532
+ '5' => {
533
+ 'name' => 'iPhone'
534
+ }
535
+ }
517
536
  RestClient.post(
518
- "#{server}/api/stats",
537
+ "#{server}/app/v1/<source_name>/fast_delete",
519
538
  {
520
- :api_token => @api_token,
521
- :names => 'sources:*:Product'
539
+ :user_id => user_id,
540
+ :data => data
522
541
  }.to_json,
523
- :content_type => :json
542
+ {:content_type => :json,
543
+ 'X-RhoConnect-API-TOKEN' => @api_token}
524
544
  )
545
+
546
+
547
+