rhosync_api 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,6 +1,7 @@
1
1
 
2
- version 0.0.1 - 5 August 2011
3
- version 0.0.2 - 5 August 2011
4
- version 0.0.3 - 5 August 2011
5
- version 0.0.4 - 6 August 2011
6
- version 0.0.5 - 6 August 2011
2
+ version 0.0.1 - 5 August 2011 - firts test of the gem
3
+ version 0.0.2 - 5 August 2011 - fixing methods
4
+ version 0.0.3 - 5 August 2011 - added new api methods
5
+ version 0.0.4 - 6 August 2011 - error
6
+ version 0.0.5 - 6 August 2011 - firts stable release
7
+ varsion 0.0.6 - 7 August 2001 - added README file and changed class RhosyncApi to module RhosyncApi
@@ -1,10 +1,8 @@
1
1
  Created by Raul Mantilla Assia (2011)
2
-
3
2
 
4
-
5
3
  Based on the rhomobile documentation
6
-
7
- All the comments in this gem was copied from the Rhomobile web page, and don't belong to the author.
8
-
9
- http://docs.rhomobile.com/rhosync/rest-api
10
-
4
+
5
+ All the comments in this gem was copied from the Rhomobile web page, and doesn't belong to the author.
6
+
7
+ http://docs.rhomobile.com/rhosync/rest-api
8
+
data/README ADDED
@@ -0,0 +1,261 @@
1
+ = Rhosync_api
2
+
3
+ With this gem you can connect to the rhosync API very easy.
4
+
5
+ =INTALLATION
6
+
7
+ gem install rhosync_api
8
+
9
+ =HOW TO
10
+
11
+ require "rubygems"
12
+ require "rhosync_api"
13
+
14
+ RhosyncApi."method"
15
+
16
+ =METHODS
17
+
18
+ - login
19
+ - logout
20
+ - get_api_token
21
+ - get_license_info
22
+ - reset
23
+ - ping
24
+ - list_users
25
+ - create_user
26
+ - delete_user
27
+ - list_clients
28
+ - create_client
29
+ - delete_client
30
+ - get_client_params
31
+ - list_sources
32
+ - get_source_params
33
+ - list_source_docs
34
+ - get_db_doc
35
+ - set_db_doc
36
+ - list_client_docs
37
+ - get_db_doc_by_type
38
+ - set_db_doc_by_type
39
+
40
+
41
+ =LOGIN
42
+ this method is used to authenticate with rhosync server
43
+
44
+ RhosyncApi.login("http://localhost:3000","rhoadmin","")
45
+
46
+ params:
47
+ - RHOSYNC URL
48
+ - USERNAME
49
+ - PASSWORD
50
+ return:
51
+ this method will return a token is the authentication is correct
52
+ this method will return nil if the authentication is incorrect
53
+
54
+ =LOGOUT
55
+ This method set token variable to nil
56
+ RhosyncApi.logout
57
+
58
+
59
+ =GET_API_TOKEN
60
+
61
+ RhosyncApi.get_api_token
62
+
63
+ return:
64
+ this method returns the rhosync token, with this token you can authenticate to rhosync
65
+
66
+
67
+ =GET_LICENSE_INFO
68
+
69
+ RhosyncApi.get_license_info
70
+
71
+ return:
72
+ this method returns all the information about the rhosync license
73
+
74
+ =RESET
75
+
76
+ RhosyncApi.reset
77
+
78
+ this method will reset all the redis information in rhosync
79
+
80
+ =PING
81
+ this method is used to send alerts to devices using rhosync settings
82
+
83
+ RhosyncApi.ping(user_id,ping_params)
84
+
85
+ params
86
+ - USER_ID
87
+ the rhosync user id
88
+ - PING_PARAMS
89
+ ping_params => { :message => "this is a test", :sound=>"hello.mp3" }
90
+ # :message - message which will be used to display notification popup dialog on the device
91
+ # :badge - iphone specific badge
92
+ # :sound - name of the sound file to play upon receiving PUSH notification
93
+ # :vibrate - number of seconds to vibrate upon receiving PUSH notification
94
+ # :sources - list of data source names to be synced upon receiving PUSH notification
95
+
96
+
97
+ =LIST_USERS
98
+
99
+ RhosyncApi.list_users
100
+
101
+ return:
102
+ this method returns an ARRAY of users ID.
103
+
104
+ =CREATE_USER
105
+ with this method you can create a new user in rhosync
106
+
107
+ RhosyncApi.create_user("username","password")
108
+
109
+ params:
110
+ - USERNAME
111
+ - PASSWORD
112
+ return:
113
+ this method will return nil if it fails
114
+
115
+ =DELETE_USER
116
+ with this method you can delete an existing user in rhosync
117
+
118
+ RhosyncApi.delete_user("user_id")
119
+
120
+ params:
121
+ - USERID
122
+ return:
123
+ this method will return nil if it fails
124
+
125
+ =LIST_CLIENTS
126
+ this method returns a list of devices for a given user ID
127
+
128
+ RhosyncApi.list_clients("user_id")
129
+
130
+ params:
131
+ - USERID
132
+ return:
133
+ this method will return nil if it fails
134
+
135
+ =CREATE_CLIENT
136
+ this method create a device for a given user ID
137
+
138
+ RhosyncApi.create_client("user_id")
139
+
140
+ params:
141
+ - USERID
142
+ return:
143
+ this method will return nil if it fails
144
+
145
+ =DELETE_CLIENT
146
+ this method deletes a device for a given user ID and device ID
147
+
148
+ RhosyncApi.delete_client("user_id","device_id")
149
+
150
+ params:
151
+ - USERID
152
+ - DEVICE_ID
153
+ return:
154
+ this method will return nil if it fails
155
+
156
+ =GET_CLIENT_PARAMS
157
+ this method returns the attributes of a given device ID, such as device_type, device_pin, device_port.
158
+
159
+ RhosyncApi.get_client_params("device_id")
160
+
161
+ params:
162
+ - DEVICE_ID
163
+ return:
164
+ this method will return nil if it fails
165
+
166
+
167
+ =LIST_SOURCES
168
+ this method returns a list rhosync source adapters for a given partition
169
+
170
+ RhosyncApi.list_sources("partition")
171
+ RhosyncApi.list_sources
172
+
173
+ params:
174
+ - PARTITION : this could be "user" or "app" by default if use "user" partition
175
+ return:
176
+ this method will return nil if it fails
177
+
178
+ =GET_SOURCE_PARAMS
179
+ this method returns the attributes of a given source adapter
180
+ such as name, poll_interval, partition_type, sync_type, queue, query_queue, cud_queue
181
+
182
+ RhosyncApi.get_source_params("source name")
183
+
184
+ params:
185
+ - SOURCE NAME
186
+ return:
187
+ this method will return nil if it fails
188
+
189
+ =LIST_SOURCE_DOCS
190
+ this method returns a list of document keys associated with given source and user.
191
+ such as md, md_size, md_copy, errors
192
+
193
+ RhosyncApi.list_source_docs("user_id","source_name")
194
+
195
+ params:
196
+ - USER ID
197
+ - SOURCE NAME
198
+ return:
199
+ this method will return nil if it fails
200
+
201
+ =GET_DB_DOC
202
+ this method returns the content of a given document key.
203
+
204
+ RhosyncApi.get_db_doc("document key","data_type")
205
+ RhosyncApi.get_db_doc("document key")
206
+
207
+ params:
208
+ - DOCUMENT KEY : this is the document key listed in the LIST_SOURCE_DOCS method
209
+ - DATA TYPE: could be "string" or nil
210
+ return:
211
+ this method will return nil if it fails
212
+
213
+ =SET_DB_DOC
214
+ this method set content of a given document key
215
+
216
+ RhosyncApi.set_db_doc("document key","data","data_type")
217
+ RhosyncApi.set_db_doc("document key","data")
218
+
219
+ params:
220
+ - DOCUMENT KEY : this is the document key listed in the LIST_SOURCE_DOCS method
221
+ - DATA : Data should be either a string or hash of hashes.
222
+ - DATA TYPE: could be type "string" or nil
223
+ return:
224
+ this method will return nil if it fails
225
+
226
+ =LIST_CLIENT_DOC
227
+ this method returns a list of document keys associated with particular device.
228
+
229
+ RhosyncApi.list_client_docs("device_id","source_name")
230
+
231
+ params:
232
+ - DEVICE_ID :
233
+ - SOURCE NAME:
234
+ return:
235
+ this method will return nil if it fails
236
+
237
+ =GET_DB_DOC_BY_TYPE
238
+ this method returns the content of a given document user and source name.
239
+
240
+ RhosyncApi.get_db_doc("user_id","source_name","type_doc")
241
+
242
+ params:
243
+ - USER ID :
244
+ - SOURCE NAME:
245
+ - TYPE DOC : such as md, md_size, md_copy, errors
246
+ return:
247
+ this method will return nil if it fails
248
+
249
+ =SET_DB_DOC_BY_TYPE
250
+ this method set content of a given user id and source name
251
+
252
+ RhosyncApi.set_db_doc_by_type("user_id","source_name","data","type_doc")
253
+
254
+ params:
255
+ - USER ID :
256
+ - SOURCE NAME:
257
+ - DATA : Data should be a hash of hashes.
258
+ - TYPE DOC : such as md, md_size, md_copy, errors
259
+ return:
260
+ this method will return nil if it fails
261
+ - set_db_doc_by_type
data/lib/rhosync_api.rb CHANGED
@@ -4,25 +4,27 @@
4
4
  require 'rest_client'
5
5
  require 'json'
6
6
 
7
- class RhosyncApi
8
-
9
- def initialize
10
- $server = ""
11
- $username = ""
12
- $password = ""
13
- $token = ""
14
- end
7
+ module RhosyncApi
15
8
 
16
9
  #login -- rhosync
17
- def login(server,admin,password)
10
+ def self.login(server,admin,password)
18
11
  $server = server
19
12
  $username = admin
20
13
  $password = password
21
14
  $token = get_api_token
22
15
  end
16
+
17
+ #logout -- rhosync
18
+ def self.logout
19
+ $server = nil
20
+ $username = nil
21
+ $password = nil
22
+ $token = nil
23
+ true
24
+ end
23
25
 
24
26
  #Before you can use RhoSync API you should get API token:
25
- def get_api_token
27
+ def self.get_api_token
26
28
  uri = URI.parse($server)
27
29
  http = Net::HTTP.new(uri.host,uri.port)
28
30
  begin
@@ -38,7 +40,7 @@ class RhosyncApi
38
40
  end
39
41
 
40
42
  #Returns license information of the currently used license
41
- def get_license_info
43
+ def self.get_license_info
42
44
  unless $token.nil?
43
45
  begin
44
46
  license_info = RestClient.post(
@@ -55,7 +57,7 @@ class RhosyncApi
55
57
  end
56
58
 
57
59
  #Reset the server: flush db and re-bootstrap server
58
- def reset
60
+ def self.reset
59
61
  unless $token.nil?
60
62
  begin
61
63
  RestClient.post("#{$server}/api/reset",
@@ -75,7 +77,7 @@ class RhosyncApi
75
77
  # :sound - name of the sound file to play upon receiving PUSH notification
76
78
  # :vibrate - number of seconds to vibrate upon receiving PUSH notification
77
79
  # :sources - list of data source names to be synced upon receiving PUSH notification
78
- def ping(user_id,ping_params)
80
+ def self.ping(user_id,ping_params)
79
81
  unless $token.nil?
80
82
  unless user_id.nil?
81
83
  begin
@@ -96,7 +98,7 @@ class RhosyncApi
96
98
  end
97
99
 
98
100
  #List users registered with this RhoSync application.
99
- def list_users
101
+ def self.list_users
100
102
  unless $token.nil?
101
103
  begin
102
104
  users = RestClient.post(
@@ -114,7 +116,7 @@ class RhosyncApi
114
116
  end
115
117
 
116
118
  #Create a user in this RhoSync application.
117
- def create_user(login,password)
119
+ def self.create_user(login,password)
118
120
  unless $token.nil?
119
121
  unless login.nil?
120
122
  begin
@@ -141,7 +143,7 @@ class RhosyncApi
141
143
  end
142
144
 
143
145
  #Delete User and all associated devices from the RhoSync application.
144
- def delete_user(user_id)
146
+ def self.delete_user(user_id)
145
147
  unless $token.nil?
146
148
  unless user_id.nil?
147
149
  begin
@@ -166,7 +168,7 @@ class RhosyncApi
166
168
  end
167
169
 
168
170
  #List clients (devices) associated with given user.
169
- def list_clients(user_id)
171
+ def self.list_clients(user_id)
170
172
  unless $token.nil?
171
173
  begin
172
174
  clients = RestClient.post("#{$server}/api/list_clients",
@@ -186,7 +188,7 @@ class RhosyncApi
186
188
  end
187
189
 
188
190
  #Creates a client (device) for a given user.
189
- def create_client(user_id)
191
+ def self.create_client(user_id)
190
192
  unless $token.nil?
191
193
  unless user_id.nil?
192
194
  begin
@@ -211,7 +213,7 @@ class RhosyncApi
211
213
  end
212
214
 
213
215
  #Deletes the specified client (device).
214
- def delete_client(user_id,client_id)
216
+ def self.delete_client(user_id,client_id)
215
217
  unless $token.nil?
216
218
  unless user_id.nil? and client_id.nil?
217
219
  begin
@@ -237,7 +239,7 @@ class RhosyncApi
237
239
  end
238
240
 
239
241
  #Returns client (device) attributes, such as device_type, device_pin, device_port. These attributes used by RhoSync push.
240
- def get_client_params(client_id)
242
+ def self.get_client_params(client_id)
241
243
  unless $token.nil?
242
244
  begin
243
245
  client_params = RestClient.post(
@@ -258,7 +260,7 @@ class RhosyncApi
258
260
  end
259
261
 
260
262
  #Return list of source adapters for this RhoSync application.
261
- def list_sources(partition = nil)
263
+ def self.list_sources(partition = nil)
262
264
  unless $token.nil?
263
265
  partition = "user" if partition.nil?
264
266
  begin
@@ -288,7 +290,7 @@ class RhosyncApi
288
290
  # queue � name of the queue for both query and create/update/delete (CUD) jobs (used if no specific queues not specified)
289
291
  # query_queue � name of query queue
290
292
  # cud_queue � name of CUD queue
291
- def get_source_params(source_id)
293
+ def self.get_source_params(source_id)
292
294
  unless $token.nil?
293
295
  begin
294
296
  attributes = RestClient.post("#{$server}/api/get_source_params",
@@ -310,7 +312,7 @@ class RhosyncApi
310
312
  # Return list of document keys associated with given source and user.
311
313
  # If :user_id set to �*�, this call will return list of keys for �shared� documents.
312
314
  # MD(:md) � master document; represents state of the backend (set of all objects for the given app/user/source on the backend service).
313
- def list_source_docs(user_id,source_id)
315
+ def self.list_source_docs(user_id,source_id)
314
316
  unless $token.nil?
315
317
  begin
316
318
  docs = RestClient.post(
@@ -332,7 +334,7 @@ class RhosyncApi
332
334
  end
333
335
 
334
336
  #Return content of a given document (client or source).
335
- def get_db_doc(doc,data_type = nil)
337
+ def self.get_db_doc(doc,data_type = nil)
336
338
  unless $token.nil?
337
339
  begin
338
340
  res = RestClient.post(
@@ -355,8 +357,13 @@ class RhosyncApi
355
357
 
356
358
  #Sets the content of the specified server document.
357
359
  #Data should be either a string or hash of hashes. Data type should be set accordingly.
358
- def set_db_doc(doc,data,data_type = nil)
360
+ def self.set_db_doc(doc,data)
359
361
  unless $token.nil?
362
+ if data.class == "String"
363
+ data_type = "string"
364
+ else
365
+ data_type = nil
366
+ end
360
367
  begin
361
368
  RestClient.post(
362
369
  "#{$server}/api/set_db_doc",
@@ -379,7 +386,7 @@ class RhosyncApi
379
386
  #Returns list of document keys associated with particular client.
380
387
  #These documents are used by the server to sync data with the client.
381
388
  #CD (:cd) � client document; represents the state of the client (set of all objects on the given client).
382
- def list_client_docs(client_id,source_id)
389
+ def self.list_client_docs(client_id,source_id)
383
390
  unless $token.nil?
384
391
  begin
385
392
  docs = RestClient.post(
@@ -402,7 +409,7 @@ class RhosyncApi
402
409
 
403
410
  #NEW METHODS IN THE GEM
404
411
  #Return content of a given document
405
- def get_db_doc_by_type(user_id,source_id,type_doc)
412
+ def self.get_db_doc_by_type(user_id,source_id,type_doc)
406
413
  unless $token.nil?
407
414
  begin
408
415
  docs = list_source_docs(user_id,source_id)
@@ -425,7 +432,7 @@ class RhosyncApi
425
432
  end
426
433
 
427
434
  #set content of a given document
428
- def set_db_doc_by_type(user_id,source_id,data,type_doc)
435
+ def self.set_db_doc_by_type(user_id,source_id,data,type_doc)
429
436
  unless $token.nil?
430
437
  begin
431
438
  docs = list_source_docs(user_id,source_id)
@@ -438,12 +445,12 @@ class RhosyncApi
438
445
  end
439
446
  end
440
447
 
441
- def access_denied
448
+ def self.access_denied
442
449
  puts "you don't have access, please login in"
443
450
  nil
444
451
  end
445
452
 
446
- def cant_connect_rhosync(e)
453
+ def self.cant_connect_rhosync(e)
447
454
  puts "rhosync error : #{e.inspect}"
448
455
  nil
449
456
  end
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rhosync_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Raul Mantilla
8
+ - Raul Mantilla Assia
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-08-06 00:00:00.000000000Z
12
+ date: 2011-08-07 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rest-client
16
- requirement: &22531452 !ruby/object:Gem::Requirement
16
+ requirement: &21336504 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 1.6.1
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *22531452
24
+ version_requirements: *21336504
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &22531164 !ruby/object:Gem::Requirement
27
+ requirement: &21336216 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.4.2
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *22531164
35
+ version_requirements: *21336216
36
36
  description: ''
37
37
  email:
38
38
  - rmantilla26@hotmail.com
@@ -41,15 +41,16 @@ extensions: []
41
41
  extra_rdoc_files:
42
42
  - History.txt
43
43
  files:
44
+ - README
44
45
  - History.txt
45
- - LICENSE.txt
46
+ - LICENSE
46
47
  - lib/rhosync_api.rb
47
48
  homepage:
48
49
  licenses: []
49
50
  post_install_message:
50
51
  rdoc_options:
51
52
  - --main
52
- - README.txt
53
+ - README
53
54
  require_paths:
54
55
  - lib
55
56
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -69,5 +70,5 @@ rubyforge_project: rhosync_api
69
70
  rubygems_version: 1.7.2
70
71
  signing_key:
71
72
  specification_version: 3
72
- summary: RhosyncApi
73
+ summary: Rhosync Api helps you connect to Rhosync Server
73
74
  test_files: []