rhosync_api 0.0.3 → 0.0.4

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 (4) hide show
  1. data/History.txt +4 -1
  2. metadata +40 -69
  3. data/LICENSE.txt +0 -4
  4. data/lib/rhosync_api.rb +0 -389
data/History.txt CHANGED
@@ -1,2 +1,5 @@
1
1
 
2
- version 0.0.1 - 5 August 2011
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
metadata CHANGED
@@ -1,100 +1,71 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rhosync_api
3
- version: !ruby/object:Gem::Version
4
- hash: 25
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.4
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 3
10
- version: 0.0.3
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Raul Mantilla
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2011-08-05 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
21
- name: rest_client
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
12
+ date: 2011-08-06 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rest-client
16
+ requirement: &21681648 !ruby/object:Gem::Requirement
24
17
  none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 13
29
- segments:
30
- - 1
31
- - 6
32
- - 1
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
33
21
  version: 1.6.1
34
- type: :development
35
- version_requirements: *id001
36
- - !ruby/object:Gem::Dependency
37
- name: json
22
+ type: :runtime
38
23
  prerelease: false
39
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: *21681648
25
+ - !ruby/object:Gem::Dependency
26
+ name: json
27
+ requirement: &21681360 !ruby/object:Gem::Requirement
40
28
  none: false
41
- requirements:
42
- - - ">="
43
- - !ruby/object:Gem::Version
44
- hash: 3
45
- segments:
46
- - 1
47
- - 4
48
- - 2
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
49
32
  version: 1.4.2
50
- type: :development
51
- version_requirements: *id002
52
- description: ""
53
- email:
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: *21681360
36
+ description: ''
37
+ email:
54
38
  - rmantilla26@hotmail.com
55
39
  executables: []
56
-
57
40
  extensions: []
58
-
59
- extra_rdoc_files:
41
+ extra_rdoc_files:
60
42
  - History.txt
61
- files:
43
+ files:
62
44
  - History.txt
63
- - LICENSE.txt
64
- - lib/rhosync_api.rb
65
45
  homepage:
66
46
  licenses: []
67
-
68
47
  post_install_message:
69
- rdoc_options:
48
+ rdoc_options:
70
49
  - --main
71
50
  - README.txt
72
- require_paths:
51
+ require_paths:
73
52
  - lib
74
- required_ruby_version: !ruby/object:Gem::Requirement
53
+ required_ruby_version: !ruby/object:Gem::Requirement
75
54
  none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- hash: 3
80
- segments:
81
- - 0
82
- version: "0"
83
- required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ! '>='
57
+ - !ruby/object:Gem::Version
58
+ version: '0'
59
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
60
  none: false
85
- requirements:
86
- - - ">="
87
- - !ruby/object:Gem::Version
88
- hash: 3
89
- segments:
90
- - 0
91
- version: "0"
61
+ requirements:
62
+ - - ! '>='
63
+ - !ruby/object:Gem::Version
64
+ version: '0'
92
65
  requirements: []
93
-
94
66
  rubyforge_project: rhosync_api
95
- rubygems_version: 1.8.6
67
+ rubygems_version: 1.7.2
96
68
  signing_key:
97
69
  specification_version: 3
98
70
  summary: RhosyncApi
99
71
  test_files: []
100
-
data/LICENSE.txt DELETED
@@ -1,4 +0,0 @@
1
- Copyright (c) 2011 Raul Mantilla Assia
2
-
3
- This gem is free, every one can use it.
4
-
data/lib/rhosync_api.rb DELETED
@@ -1,389 +0,0 @@
1
- require 'rest_client'
2
- require 'json'
3
-
4
- class RhosyncApi
5
-
6
- def initialize
7
- $server = ""
8
- $username = ""
9
- $password = ""
10
- $token = ""
11
- end
12
-
13
- #login -- rhosync
14
- def login(server,admin,password)
15
- $server = server
16
- $username = admin
17
- $password = password
18
- $token = get_api_token
19
- end
20
-
21
- #Before you can use RhoSync API you should get API token:
22
- def get_api_token
23
- uri = URI.parse($server)
24
- http = Net::HTTP.new(uri.host,uri.port)
25
- begin
26
- res,data = http.post( '/login',
27
- {:login => $username, :password => $password}.to_json,
28
- {'Content-Type' => 'application/json'} )
29
- cookie = res.response['set-cookie'].split('; ')[0].split('=')
30
- cookie = {cookie[0] => URI.escape(cookie[1])}
31
- token = RestClient.post("#{$server}/api/get_api_token",'',{:cookies => cookie})
32
- rescue=>e
33
- cant_connect_rhosync(e)
34
- end
35
- end
36
-
37
- #Returns license information of the currently used license
38
- def get_license_info
39
- unless $token.nil?
40
- begin
41
- license_info = RestClient.post(
42
- "#{$server}/api/get_license_info",
43
- {:api_token => $token}.to_json, :content_type => :json
44
- ).body
45
- JSON.parse(license_info)
46
- rescue=>e
47
- cant_connect_rhosync(e)
48
- end
49
- else
50
- access_denied
51
- end
52
- end
53
-
54
- #Reset the server: flush db and re-bootstrap server
55
- def reset
56
- unless $token.nil?
57
- begin
58
- RestClient.post("#{$server}/api/reset",
59
- { :api_token => $token }.to_json,
60
- :content_type => :json
61
- )
62
- rescue=>e
63
- cant_connect_rhosync(e)
64
- end
65
- else
66
- access_denied
67
- end
68
- end
69
-
70
- #List users registered with this RhoSync application.
71
- def list_users
72
- unless $token.nil?
73
- begin
74
- users = RestClient.post(
75
- "#{$server}/api/list_users",
76
- { :api_token => $token }.to_json,
77
- :content_type => :json
78
- ).body
79
- JSON.parse(users)
80
- rescue=>e
81
- cant_connect_rhosync(e)
82
- end
83
- else
84
- access_denied
85
- end
86
- end
87
-
88
- #Create a user in this RhoSync application.
89
- def create_user(login,password)
90
- unless $token.nil?
91
- unless login.nil?
92
- begin
93
- RestClient.post("#{$server}/api/create_user",
94
- {
95
- :api_token => $token,
96
- :attributes => {
97
- :login => login,
98
- :password => password
99
- }
100
- }.to_json,
101
- :content_type => :json
102
- )
103
- rescue=>e
104
- cant_connect_rhosync(e)
105
- end
106
- else
107
- puts "the user's ID can't be null "
108
- nil
109
- end
110
- else
111
- access_denied
112
- end
113
- end
114
-
115
- #Delete User and all associated devices from the RhoSync application.
116
- def delete_user(user_id)
117
- unless $token.nil?
118
- unless user_id.nil?
119
- begin
120
- RestClient.post(
121
- "#{$server}/api/delete_user",
122
- {
123
- :api_token => $token,
124
- :user_id => user_id
125
- }.to_json,
126
- :content_type => :json
127
- )
128
- rescue=>e
129
- cant_connect_rhosync(e)
130
- end
131
- else
132
- puts "the user's ID can't be null "
133
- nil
134
- end
135
- else
136
- access_denied
137
- end
138
- end
139
-
140
- #List clients (devices) associated with given user.
141
- def list_clients(user_id)
142
- unless $token.nil?
143
- begin
144
- clients = RestClient.post("#{$server}/api/list_clients",
145
- {
146
- :api_token => $token,
147
- :user_id => user_id
148
- }.to_json,
149
- :content_type => :json
150
- ).body
151
- JSON.parse(clients)
152
- rescue=>e
153
- cant_connect_rhosync(e)
154
- end
155
- else
156
- access_denied
157
- end
158
- end
159
-
160
- #Creates a client (device) for a given user.
161
- def create_client(user_id)
162
- unless $token.nil?
163
- unless user_id.nil?
164
- begin
165
- RestClient.post(
166
- "#{$server}/api/create_client",
167
- {
168
- :api_token => $token,
169
- :user_id => user_id
170
- }.to_json,
171
- :content_type => :json
172
- ).body
173
- rescue=>e
174
- cant_connect_rhosync(e)
175
- end
176
- else
177
- puts "the user's ID can't be null "
178
- nil
179
- end
180
- else
181
- access_denied
182
- end
183
- end
184
-
185
- #Deletes the specified client (device).
186
- def delete_client(user_id,client_id)
187
- unless $token.nil?
188
- unless user_id.nil? and client_id.nil?
189
- begin
190
- RestClient.post(
191
- "#{$server}/api/delete_client",
192
- {
193
- :api_token => $token,
194
- :user_id => user_id,
195
- :client_id => client_id
196
- }.to_json,
197
- :content_type => :json
198
- )
199
- rescue=>e
200
- cant_connect_rhosync(e)
201
- end
202
- else
203
- puts "the user's ID and client's ID can't be null "
204
- nil
205
- end
206
- else
207
- access_denied
208
- end
209
- end
210
-
211
- #Returns client (device) attributes, such as device_type, device_pin, device_port. These attributes used by RhoSync push.
212
- def get_client_params(client_id)
213
- unless $token.nil?
214
- begin
215
- client_params = RestClient.post(
216
- "#{$server}/api/get_client_params",
217
- {
218
- :api_token => $token,
219
- :client_id => client_id
220
- }.to_json,
221
- :content_type => :json
222
- ).body
223
- JSON.parse(client_params)
224
- rescue=>e
225
- cant_connect_rhosync(e)
226
- end
227
- else
228
- access_denied
229
- end
230
- end
231
-
232
- #Return list of source adapters for this RhoSync application.
233
- def list_sources(partition = nil)
234
- unless $token.nil?
235
- partition = "user" if partition.nil?
236
- begin
237
- sources = RestClient.post("#{$server}/api/list_sources",
238
- {
239
- :api_token => $token,
240
- :partition_type => partition
241
- }.to_json,
242
- :content_type => :json
243
- ).body
244
- JSON.parse(sources)
245
- rescue=>e
246
- cant_connect_rhosync(e)
247
- end
248
- else
249
- access_denied
250
- end
251
- end
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
-
378
- def access_denied
379
- puts "you don't have access, please login in"
380
- nil
381
- end
382
-
383
- def cant_connect_rhosync(e)
384
- puts "rhosync error : #{e.inspect}"
385
- nil
386
- end
387
-
388
-
389
- end