rhosync_api 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. data/lib/rhosync_api.rb +126 -1
  2. metadata +3 -3
data/lib/rhosync_api.rb CHANGED
@@ -195,7 +195,7 @@ class RhosyncApi
195
195
  :client_id => client_id
196
196
  }.to_json,
197
197
  :content_type => :json
198
- )
198
+ )
199
199
  rescue=>e
200
200
  cant_connect_rhosync(e)
201
201
  end
@@ -250,6 +250,131 @@ class RhosyncApi
250
250
  end
251
251
  end
252
252
 
253
+
254
+ #Return attributes associated with a given source:
255
+
256
+ # name � name of the data source
257
+ # poll_interval � query poll interval; defines how often RhoSync will call source adapter to query for new data, set to -1 to disable polling, 0 to always poll
258
+ # partition_type � to share data across all users, set partition to :app; otherwise use :user partition (default)
259
+ # sync_type � set to :bulk_only to disable :incremental sync; regular sync is :incremental (default)
260
+ # queue � name of the queue for both query and create/update/delete (CUD) jobs (used if no specific queues not specified)
261
+ # query_queue � name of query queue
262
+ # cud_queue � name of CUD queue
263
+ def get_source_params(source_id)
264
+ unless $token.nil?
265
+ begin
266
+ attributes = RestClient.post("#{$server}/api/get_source_params",
267
+ {
268
+ :api_token => $token,
269
+ :source_id => source_id
270
+ }.to_json,
271
+ :content_type => :json
272
+ ).body
273
+ JSON.parse(attributes)
274
+ rescue=>e
275
+ cant_connect_rhosync(e)
276
+ end
277
+ else
278
+ access_denied
279
+ end
280
+ end
281
+
282
+ # Return list of document keys associated with given source and user.
283
+ # If :user_id set to �*�, this call will return list of keys for �shared� documents.
284
+ # MD(:md) � master document; represents state of the backend (set of all objects for the given app/user/source on the backend service).
285
+ def list_source_docs(user_id,source_id)
286
+ unless $token.nil?
287
+ begin
288
+ docs = RestClient.post(
289
+ "#{$server}/api/list_source_docs",
290
+ {
291
+ :api_token => $token,
292
+ :source_id => source_id,
293
+ :user_id => user_id
294
+ }.to_json,
295
+ :content_type => :json
296
+ ).body
297
+ JSON.parse(docs)
298
+ rescue=>e
299
+ cant_connect_rhosync(e)
300
+ end
301
+ else
302
+ access_denied
303
+ end
304
+ end
305
+
306
+ #Return content of a given document (client or source).
307
+ def get_db_doc(doc,data_type = nil)
308
+ unless $token.nil?
309
+ begin
310
+ res = RestClient.post(
311
+ "#{$server}/api/get_db_doc",
312
+ {
313
+ :api_token => $token,
314
+ :doc => doc,
315
+ :data_type => data_type
316
+ }.to_json,
317
+ :content_type => :json
318
+ ).body
319
+ JSON.parse(res)
320
+ rescue=>e
321
+ cant_connect_rhosync(e)
322
+ end
323
+ else
324
+ access_denied
325
+ end
326
+ end
327
+
328
+ #Returns list of document keys associated with particular client.
329
+ #These documents are used by the server to sync data with the client.
330
+ #CD (:cd) � client document; represents the state of the client (set of all objects on the given client).
331
+ def list_client_docs(client_id,source_id)
332
+ unless $token.nil?
333
+ begin
334
+ docs = RestClient.post(
335
+ "#{$server}/api/list_client_docs",
336
+ {
337
+ :api_token => $token,
338
+ :source_id => source_id,
339
+ :client_id => client_id
340
+ }.to_json,
341
+ :content_type => :json
342
+ ).body
343
+ JSON.parse(docs)
344
+ rescue=>e
345
+ cant_connect_rhosync(e)
346
+ end
347
+ else
348
+ access_denied
349
+ end
350
+ end
351
+
352
+
353
+
354
+ #NEW METHODS IN THE GEM
355
+ #Return content of a given document
356
+ def get_db_doc_key(user_id,source_id,type_doc)
357
+ unless $token.nil?
358
+ begin
359
+ docs = list_source_docs(user_id,source_id)
360
+ res = RestClient.post(
361
+ "#{$server}/api/get_db_doc",
362
+ {
363
+ :api_token => $token,
364
+ :doc => docs["#{type_doc}"],
365
+ :data_type => nil
366
+ }.to_json,
367
+ :content_type => :json
368
+ ).body
369
+ JSON.parse(res)
370
+ rescue=>e
371
+ cant_connect_rhosync(e)
372
+ end
373
+ else
374
+ access_denied
375
+ end
376
+ end
377
+
253
378
  def access_denied
254
379
  puts "you don't have access, please login in"
255
380
  nil
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhosync_api
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 1
10
- version: 0.0.1
9
+ - 2
10
+ version: 0.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Raul Mantilla