rhoconnect-rb 0.3.2 → 1.0.0
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.
- data/.travis.yml +2 -0
- data/CHANGELOG.md +6 -0
- data/Gemfile +5 -1
- data/README.md +243 -38
- data/Rakefile +0 -7
- data/config/routes.rb +5 -5
- data/lib/rhoconnect-rb.rb +7 -6
- data/lib/rhoconnectrb/api/base.rb +50 -0
- data/lib/rhoconnectrb/api/clients.rb +43 -0
- data/lib/rhoconnectrb/api/read_state.rb +30 -0
- data/lib/rhoconnectrb/api/resource.rb +36 -0
- data/lib/rhoconnectrb/api/sources.rb +47 -0
- data/lib/rhoconnectrb/api/store.rb +37 -0
- data/lib/rhoconnectrb/api/system.rb +16 -0
- data/lib/rhoconnectrb/api/users.rb +43 -0
- data/lib/{rhoconnect → rhoconnectrb}/client.rb +5 -5
- data/lib/{rhoconnect → rhoconnectrb}/configuration.rb +7 -7
- data/lib/{rhoconnect → rhoconnectrb}/endpoints.rb +29 -29
- data/lib/{rhoconnect → rhoconnectrb}/railtie.rb +1 -1
- data/lib/{rhoconnect → rhoconnectrb}/resource.rb +5 -5
- data/lib/rhoconnectrb/version.rb +3 -0
- data/rhoconnect-rb.gemspec +2 -2
- data/spec/api_spec.rb +155 -0
- data/spec/client_spec.rb +11 -11
- data/spec/endpoints_spec.rb +20 -20
- data/spec/resource_spec.rb +18 -18
- data/spec/spec_helper.rb +40 -22
- data/templates/rhoconnect.rb +26 -18
- metadata +20 -9
- data/lib/rhoconnect/version.rb +0 -3
data/.travis.yml
CHANGED
data/CHANGELOG.md
ADDED
data/Gemfile
CHANGED
@@ -6,6 +6,10 @@ gem 'rails', '>= 3.0'
|
|
6
6
|
|
7
7
|
group :test do
|
8
8
|
gem 'rspec', '~>2.5.0', :require => 'spec'
|
9
|
-
gem '
|
9
|
+
gem 'simplecov', :platforms => [:ruby_19,:jruby]
|
10
10
|
gem 'webmock'
|
11
11
|
end
|
12
|
+
|
13
|
+
platforms :jruby do
|
14
|
+
gem 'jruby-openssl'
|
15
|
+
end
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
rhoconnect-rb 
|
1
|
+
rhoconnect-rb [](http://travis-ci.org/rhomobile/rhoconnect-rb)
|
2
2
|
===
|
3
3
|
|
4
4
|
A ruby library for the [RhoConnect](http://rhomobile.com/products/rhoconnect) App Integration Server.
|
@@ -12,23 +12,23 @@ Load the `rhoconnect-rb` library:
|
|
12
12
|
require 'rhoconnect-rb'
|
13
13
|
|
14
14
|
Note, if you are using datamapper, install the `dm-serializer` library and require it in your application. `rhoconnect-rb` depends on this utility to interact with Rhoconnect applications using JSON.
|
15
|
-
|
15
|
+
|
16
16
|
## Setup the Model
|
17
|
-
Now include
|
17
|
+
Now include Rhoconnectrb::Resource in a model that you want to synchronize with your mobile application:
|
18
18
|
|
19
19
|
class Product < ActiveRecord::Base
|
20
|
-
include
|
20
|
+
include Rhoconnectrb::Resource
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
Or, if you are using DataMapper:
|
24
24
|
|
25
25
|
class Product
|
26
26
|
include DataMapper::Resource
|
27
|
-
include
|
27
|
+
include Rhoconnectrb::Resource
|
28
28
|
end
|
29
29
|
|
30
30
|
## Partitioning Datasets
|
31
|
-
|
31
|
+
|
32
32
|
Next, your models will need to declare a partition key for `rhoconnect-rb`. This partition key is used by `rhoconnect-rb` to uniquely identify the model dataset when it is stored in a rhoconnect instance. It is typically an attribute on the model or related model. `rhoconnect-rb` supports two types of partitions:
|
33
33
|
|
34
34
|
* :app - No unique key will be used, a shared dataset is synchronized for all users.
|
@@ -37,21 +37,21 @@ Next, your models will need to declare a partition key for `rhoconnect-rb`. Thi
|
|
37
37
|
For example, the `Product` model above might have a `belongs_to :user` relationship. This provides us a simple way to organize the `Product` dataset for rhoconnect by reusing this relationship. The partition identifying a username would be declared as:
|
38
38
|
|
39
39
|
class Product < ActiveRecord::Base
|
40
|
-
include
|
41
|
-
|
40
|
+
include Rhoconnectrb::Resource
|
41
|
+
|
42
42
|
belongs_to :user
|
43
|
-
|
44
|
-
def partition
|
45
|
-
|
43
|
+
|
44
|
+
def partition
|
45
|
+
lambda { self.user.username }
|
46
46
|
end
|
47
47
|
end
|
48
|
-
|
48
|
+
|
49
49
|
Now all of the `Product` data synchronized by rhoconnect will organized by `self.user.username`. Note: You can also used a fixed key if the dataset doesn't require a dynamic value:
|
50
50
|
|
51
51
|
def partition
|
52
52
|
:app
|
53
53
|
end
|
54
|
-
|
54
|
+
|
55
55
|
For more information about Rhoconnect partitions, please refer to the [Rhoconnect docs](http://docs.rhomobile.com/rhoconnect/source-adapters#data-partitioning).
|
56
56
|
|
57
57
|
## Querying Datasets
|
@@ -59,20 +59,20 @@ For more information about Rhoconnect partitions, please refer to the [Rhoconnec
|
|
59
59
|
`rhoconnect-rb` installs a `/rhoconnect/query` route in your application which the Rhoconnect instance invokes to query the dataset for the dataset you want to synchronize. This route is mapped to a `rhoconnect_query` method in your model. This method should return a collection of objects:
|
60
60
|
|
61
61
|
class Product < ActiveRecord::Base
|
62
|
-
include
|
63
|
-
|
62
|
+
include Rhoconnectrb::Resource
|
63
|
+
|
64
64
|
belongs_to :user
|
65
|
-
|
66
|
-
def partition
|
67
|
-
|
65
|
+
|
66
|
+
def partition
|
67
|
+
lambda { self.user.username }
|
68
68
|
end
|
69
|
-
|
69
|
+
|
70
70
|
def self.rhoconnect_query(partition, attributes = nil)
|
71
71
|
Product.includes(:user).where("users.username = ?", partition)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
|
-
In this example, `self.rhoconnect_query` returns a list of products where the partition string (provided by the rhoconnect instance) matches the `user_id` field in the products table.
|
75
|
+
In this example, `self.rhoconnect_query` returns a list of products where the partition string (provided by the rhoconnect instance) matches the `user_id` field in the products table.
|
76
76
|
|
77
77
|
## Configuration and Authentication
|
78
78
|
|
@@ -83,41 +83,246 @@ Configure RhoConnect in an initializer like `config/initializers/rhoconnect.rb`
|
|
83
83
|
config.uri = "http://myrhoconnect.com"
|
84
84
|
config.token = "secrettoken"
|
85
85
|
config.app_endpoint = "http://myapp.heroku.com"
|
86
|
-
|
86
|
+
|
87
87
|
If `app_endpoint` is defined, your Rhoconnect instance will be configured to query data from the endpoint using the rhoconnect_query method in your model. For example, if your `app_endpoint` is defined as "http://myapp.heroku.com", RhoConnect will query data with:
|
88
88
|
|
89
89
|
POST http://myapp.heroku.com/rhoconnect/query
|
90
90
|
|
91
|
-
Example:
|
91
|
+
Example:
|
92
92
|
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
93
|
+
Rhoconnectrb.configure do |config|
|
94
|
+
config.uri = "http://localhost:8675"
|
95
|
+
config.token = "mydevtoken"
|
96
|
+
config.app_endpoint = "http://localhost:3000"
|
97
97
|
end
|
98
|
-
|
98
|
+
|
99
99
|
Example with authentication:
|
100
100
|
|
101
101
|
`rhoconnect-rb` installs a `/rhoconnect/authenticate` route into your application which will receive credentials from the client. Add block which handles the credentials:
|
102
102
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
103
|
+
Rhoconnectrb.configure do |config|
|
104
|
+
config.uri = "http://localhost:8675"
|
105
|
+
config.token = "mydevtoken"
|
106
|
+
config.app_endpoint = "http://localhost:3000"
|
107
|
+
config.authenticate = lambda { |credentials|
|
108
|
+
User.authenticate(credentials[:login], credentials[:password])
|
108
109
|
}
|
109
110
|
end
|
110
|
-
|
111
|
+
|
111
112
|
### Using the [RhoConnect Heroku Addon](http://docs.rhomobile.com/rhoconnect/heroku-addon)
|
112
113
|
|
113
114
|
If you're using the [RhoConnect Heroku Addon](http://docs.rhomobile.com/rhoconnect/heroku-addon), then you can omit the config.uri and config.token (they are managed for you):
|
114
115
|
|
115
|
-
|
116
|
-
|
117
|
-
|
116
|
+
Rhoconnectrb.configure do |config|
|
117
|
+
config.app_endpoint = "http://myapp.heroku.com"
|
118
|
+
config.authenticate = lambda { |credentials|
|
119
|
+
User.authenticate(credentials[:login], credentials[:password])
|
118
120
|
}
|
119
121
|
end
|
120
|
-
|
122
|
+
|
123
|
+
## Rhoconnect-rb API
|
124
|
+
|
125
|
+
### Overview of the API
|
126
|
+
|
127
|
+
The Rhoconnectrb::API module contains routes to all the resources available in <a href='http://docs.rhomobile.com/rhoconnect/rest-api'>Rhoconnect</a>. At a high level the API calls take on the following syntax:
|
128
|
+
|
129
|
+
Namespace::Resource.verb_action1_action2_...([resource_id,action1_id,action2_id],data)
|
130
|
+
|
131
|
+
Some of these values are not used for every API call such as resource_id and data.
|
132
|
+
|
133
|
+
### System Resource
|
134
|
+
|
135
|
+
#### `POST /rc/v1/system/login`
|
136
|
+
|
137
|
+
|
138
|
+
data = {:login=>'username',:password=>'password'}
|
139
|
+
Rhoconnectrb::API::System.post_login(data)
|
140
|
+
|
141
|
+
#### `GET /rc/v1/system/license`
|
142
|
+
|
143
|
+
|
144
|
+
Rhoconnectrb::API::System.get_license
|
145
|
+
|
146
|
+
#### `POST /rc/v1/system/reset`
|
147
|
+
|
148
|
+
|
149
|
+
Rhoconnectrb::API::System.post_reset({})
|
150
|
+
|
151
|
+
#### `GET /rc/v1/system/appserver`
|
152
|
+
|
153
|
+
|
154
|
+
Rhoconnectrb::API::System.get_appserver
|
155
|
+
|
156
|
+
#### `POST /rc/v1/system/appserver`
|
157
|
+
|
158
|
+
|
159
|
+
data = {:adapter_url=>'http://test.com'}
|
160
|
+
Rhoconnectrb::API::System.post_appserver(data)
|
161
|
+
|
162
|
+
#### `GET /rc/v1/system/stats`
|
163
|
+
|
164
|
+
|
165
|
+
data ={:names=>"*sources*"}
|
166
|
+
Rhoconnectrb::API::System.get_stats(data)
|
167
|
+
|
168
|
+
### Store Resource
|
169
|
+
|
170
|
+
#### `GET /rc/v1/store/:doc`
|
171
|
+
|
172
|
+
|
173
|
+
Rhoconnectrb::API::Store.get('docname')
|
174
|
+
|
175
|
+
#### `POST /rc/v1/store/:doc`
|
176
|
+
|
177
|
+
|
178
|
+
data = {:data=>{:id=3},:append=>false}
|
179
|
+
Rhoconnectrb::API::Store.post('docname',data)
|
180
|
+
|
181
|
+
### User Resource
|
182
|
+
|
183
|
+
#### `POST /rc/v1/users`
|
184
|
+
|
185
|
+
|
186
|
+
data = {:attributes=>{:login=>'login',:password=>'password'}}
|
187
|
+
Rhoconnectrb::API::Users.post(data)
|
188
|
+
|
189
|
+
#### `DELETE /rc/v1/users/:user_id`
|
190
|
+
|
191
|
+
|
192
|
+
Rhoconnectrb::API::Users.delete('user_id')
|
193
|
+
|
194
|
+
#### `PUT /rc/v1/users/:user_id`
|
195
|
+
|
196
|
+
|
197
|
+
data = {:attributes=>{:a_user_specific_attribute => a_user_specific_attribute_value}}
|
198
|
+
Rhoconnectrb::API::Users.put('user_id',data)
|
199
|
+
|
200
|
+
#### `GET /rc/v1/users`
|
201
|
+
|
202
|
+
|
203
|
+
Rhoconnectrb::API::Users.get
|
204
|
+
|
205
|
+
#### `Get /rc/v1/users/:user_id`
|
206
|
+
|
207
|
+
Rhoconnectrb::API::Users.get('user_id')
|
208
|
+
|
209
|
+
#### `Get /rc/v1/users/:user_id/clients`
|
210
|
+
|
211
|
+
|
212
|
+
Rhoconnectrb::API::Users.get_clients(['user_id','client_id'])
|
213
|
+
|
214
|
+
#### `DELETE /rc/v1/users/:user_id/clients/:client_id`
|
215
|
+
|
216
|
+
|
217
|
+
Rhoconnectrb::API::Users.delete_clients(['user_id','client_id'])
|
218
|
+
|
219
|
+
#### `GET /rc/v1/users/:user_id/sources/:source_id/docnames`
|
220
|
+
|
221
|
+
|
222
|
+
Rhoconnectrb::API::Users.get_sources_docnames(['user_id','source_id'])
|
223
|
+
|
224
|
+
#### `POST /rc/v1/users/ping`
|
225
|
+
|
226
|
+
|
227
|
+
data = {
|
228
|
+
:api_token => token,
|
229
|
+
:user_id => [array_of_users],
|
230
|
+
:sources => source_name,
|
231
|
+
:message => 'hello world',
|
232
|
+
:vibrate => 2000,
|
233
|
+
:sound => 'hello.mp3'
|
234
|
+
}
|
235
|
+
Rhoconnectrb::API::Users.post_ping(data)
|
236
|
+
|
237
|
+
#### `GET /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
|
238
|
+
|
239
|
+
|
240
|
+
Rhoconnectrb::API::Users.get_sources_docs(['user_id','source_id','docname'])
|
241
|
+
|
242
|
+
#### `POST /rc/v1/users/:user_id/sources/:source_id/docs/:doc`
|
243
|
+
|
244
|
+
|
245
|
+
data = {:data=>data,:append=>false}
|
246
|
+
Rhoconnectrb::API::Users.post_sources_docs(['user_id','source_id','docname'],data)
|
247
|
+
|
248
|
+
### Read State Resource
|
249
|
+
|
250
|
+
#### `POST /rc/v1/read_state/users/:user_id/sources/:source_id`
|
251
|
+
|
252
|
+
|
253
|
+
data = {:refresh_time => 100}
|
254
|
+
Rhconnectrb::API::ReadState.post_users_sources(['user_id','source_id'])
|
255
|
+
|
256
|
+
### Source Resource
|
257
|
+
|
258
|
+
#### `GET /rc/v1/sources/type/:partition_type`
|
259
|
+
|
260
|
+
|
261
|
+
Rhoconnectrb::API::Sources.get_type('parition_type')
|
262
|
+
|
263
|
+
#### `GET /rc/v1/sources/:source_id`
|
264
|
+
|
265
|
+
|
266
|
+
Rhoconnectrb::API::Sources.get('source_id')
|
267
|
+
|
268
|
+
#### `PUT /rc/v1/sources/:source_id`
|
269
|
+
|
270
|
+
|
271
|
+
data = {:user_name=>'username',:data=>{:poll_interval=>25}}
|
272
|
+
Rhoconnectrb::API::Sources.put('source_id',data)
|
273
|
+
|
274
|
+
### Client Resource
|
275
|
+
|
276
|
+
#### `GET /rc/v1/clients/:client_id`
|
277
|
+
|
278
|
+
|
279
|
+
Rhoconnectrb::API::Clients.get('client_id')
|
280
|
+
|
281
|
+
#### `GET /rc/v1/clients/:client_id/sources/:source_id/docnames`
|
282
|
+
|
283
|
+
|
284
|
+
Rhoconnectrb::API::Clients.get_sources_docnames(['client_id','source_id'])
|
285
|
+
|
286
|
+
#### `POST /rc/v1/clients/:client_id/sources/:source_id/docnames`
|
287
|
+
|
288
|
+
|
289
|
+
data = {:data=>data,:append=>false}
|
290
|
+
Rhoconnectrb::API::Clients.post_sources_docnames(['client_id','source_id'],data)
|
291
|
+
|
292
|
+
### Resource Resource
|
293
|
+
|
294
|
+
The Resource class is used for API calls to user defined dynamic or source adapters. The resource name is passed in as a parameter.
|
295
|
+
|
296
|
+
#### `POST /app/v1/:source_name/push_objects`
|
297
|
+
|
298
|
+
|
299
|
+
data = {:user_id=>'user_id',:objects=>data}
|
300
|
+
Rhoconnectrb::API::Resource.post_push_objects('source_name',data)
|
301
|
+
|
302
|
+
#### `POST /app/v1/:source_name/push_deletes`
|
303
|
+
|
304
|
+
|
305
|
+
data = {:user_id => 'user_id',:objects=>'object_ids'}
|
306
|
+
Rhoconnectrb::API::Resource.post_push_deletes('source_name',data)
|
307
|
+
|
308
|
+
#### `POST /app/v1/:source_name/fast_insert`
|
309
|
+
|
310
|
+
|
311
|
+
data = {:user_id=>'user_id',:objects=>data}
|
312
|
+
Rhoconnectrb::API::Resource.post_fast_insert('source_name',data)
|
313
|
+
|
314
|
+
#### `POST /app/v1/:source_name/fast_update`
|
315
|
+
|
316
|
+
|
317
|
+
data = {:user_id=>'user_id',:objects=>data}
|
318
|
+
Rhoconnectrb::API::Resource.post_fast_update('source_name',data)
|
319
|
+
|
320
|
+
#### `POST /app/v1/:source_name/fast_delete`
|
321
|
+
|
322
|
+
|
323
|
+
data = {:user_id=>'user_id',:objects=>data}
|
324
|
+
Rhoconnectrb::API::Resource.post_fast_delete('source_name',data)
|
325
|
+
|
121
326
|
|
122
327
|
## Meta
|
123
328
|
Created and maintained by Lucas Campbell-Rossen, Vladimir Tarasov and Lars Burgess.
|
data/Rakefile
CHANGED
@@ -11,11 +11,4 @@ RSpec::Core::RakeTask.new(:spec) do |t|
|
|
11
11
|
t.pattern = 'spec/**/*_spec.rb'
|
12
12
|
end
|
13
13
|
|
14
|
-
desc "Run all specs with rcov"
|
15
|
-
RSpec::Core::RakeTask.new(:rcov) do |t|
|
16
|
-
t.rcov = true
|
17
|
-
t.rcov_opts = ['--exclude', 'spec/*,gems/*']
|
18
|
-
t.rspec_opts = ["-b", "-c", "-fd"]
|
19
|
-
end
|
20
|
-
|
21
14
|
task :default => :spec
|
data/config/routes.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Rails.application.routes.draw do
|
2
|
-
match '/rhoconnect/authenticate' =>
|
3
|
-
match '/rhoconnect/query' =>
|
4
|
-
match '/rhoconnect/create' =>
|
5
|
-
match '/rhoconnect/update' =>
|
6
|
-
match '/rhoconnect/delete' =>
|
2
|
+
match '/rhoconnect/authenticate' => Rhoconnectrb::Authenticate
|
3
|
+
match '/rhoconnect/query' => Rhoconnectrb::Query
|
4
|
+
match '/rhoconnect/create' => Rhoconnectrb::Create
|
5
|
+
match '/rhoconnect/update' => Rhoconnectrb::Update
|
6
|
+
match '/rhoconnect/delete' => Rhoconnectrb::Delete
|
7
7
|
end
|
data/lib/rhoconnect-rb.rb
CHANGED
@@ -1,8 +1,9 @@
|
|
1
1
|
require 'json'
|
2
2
|
require 'rest_client'
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
6
|
-
require '
|
7
|
-
require '
|
8
|
-
require '
|
3
|
+
require 'rhoconnectrb/version'
|
4
|
+
require 'rhoconnectrb/configuration'
|
5
|
+
require 'rhoconnectrb/client'
|
6
|
+
require 'rhoconnectrb/resource'
|
7
|
+
require 'rhoconnectrb/endpoints'
|
8
|
+
require 'rhoconnectrb/railtie' if defined?(Rails)
|
9
|
+
Dir["/rhoconnectrb/api/*.rb"].each {|file| require file }
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
require 'uri'
|
3
|
+
|
4
|
+
module Rhoconnectrb
|
5
|
+
module API
|
6
|
+
|
7
|
+
class Base
|
8
|
+
def self.post(url,data)
|
9
|
+
resp = resource[url].post data.to_json
|
10
|
+
resp.body
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.get(url,params=nil)
|
14
|
+
if params
|
15
|
+
params = {:params=>params}
|
16
|
+
resp = resource[url].get(params)
|
17
|
+
else
|
18
|
+
resp = resource[url].get self.content
|
19
|
+
end
|
20
|
+
resp.body
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.put(url,data)
|
24
|
+
resp = resource[url].put data.to_json
|
25
|
+
resp.body
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.delete(url,nothing=nil)
|
29
|
+
resp = resource[url].delete
|
30
|
+
resp.body
|
31
|
+
end
|
32
|
+
|
33
|
+
def self.token
|
34
|
+
url = Rhoconnectrb.configuration.uri || ENV['RHOCONNECT_URL']
|
35
|
+
uri = URI.parse(url)
|
36
|
+
Rhoconnectrb.configuration.token || uri.user
|
37
|
+
end
|
38
|
+
|
39
|
+
def self.content
|
40
|
+
{'X-RhoConnect-API-TOKEN'=> self.token, :content_type => :json, :accept => :json}
|
41
|
+
end
|
42
|
+
|
43
|
+
def self.resource
|
44
|
+
uri = Rhoconnectrb.configuration.uri || ENV['RHOCONNECT_URL']
|
45
|
+
RestClient::Resource.new(uri + "/rc/v1",:headers=>self.content)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Rhoconnectrb
|
2
|
+
module API
|
3
|
+
class Clients
|
4
|
+
def self.klass
|
5
|
+
self.to_s.underscore.split('/')[2]
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.method_missing method_name, *args
|
9
|
+
action = method_name.to_s.split("_")
|
10
|
+
#handle CRUD operations
|
11
|
+
if action.size == 1
|
12
|
+
if action[0] =~ /put|delete/
|
13
|
+
Base.send(action[0],"/#{klass}/#{args[0]}",args[1])
|
14
|
+
else
|
15
|
+
url = args.size > 0 ? "/#{klass}/#{args[0]}" : "/#{klass}"
|
16
|
+
resp = Base.send(action[0],url,args[1])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if action.size > 1
|
21
|
+
verb = action.delete_at(0)
|
22
|
+
#if posting without parameters just post with data else contruct url
|
23
|
+
if verb == 'post' and !args[1]
|
24
|
+
Base.send(verb,"/#{klass}/#{action[0]}",args[0])
|
25
|
+
else
|
26
|
+
if args[0].class.to_s == 'String'
|
27
|
+
url = "/#{klass}/#{args[0]}/#{action[0]}"
|
28
|
+
else
|
29
|
+
url = klass
|
30
|
+
args[0].each_with_index do |value,index|
|
31
|
+
url += "/#{value}"
|
32
|
+
url += "/#{action[index]}" if action[index]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
resp = Base.send(verb,url,args[1])
|
36
|
+
end
|
37
|
+
end
|
38
|
+
resp
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
#READSTATE is special class that does not have resource id so logic changes to account for nil id inherint to every request
|
2
|
+
module Rhoconnectrb
|
3
|
+
module API
|
4
|
+
class ReadState
|
5
|
+
|
6
|
+
def self.klass
|
7
|
+
self.to_s.underscore.split('/')[2]
|
8
|
+
end
|
9
|
+
|
10
|
+
def self.method_missing method_name, *args
|
11
|
+
action = method_name.to_s.split("_")
|
12
|
+
|
13
|
+
if action.size > 1
|
14
|
+
verb = action.delete_at(0)
|
15
|
+
|
16
|
+
if args[0].class.to_s == 'String'
|
17
|
+
url = "/#{klass}/#{action[0]}/#{args[0]}"
|
18
|
+
else
|
19
|
+
url = klass
|
20
|
+
args[0].each_with_index do |value,index|
|
21
|
+
url += "/#{action[index]}" if action[index]
|
22
|
+
url += "/#{value}"
|
23
|
+
end
|
24
|
+
end
|
25
|
+
Base.send(verb,url,args[1])
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Rhoconnectrb
|
2
|
+
module API
|
3
|
+
class Resource
|
4
|
+
|
5
|
+
def self.method_missing method_name, *args
|
6
|
+
action = method_name.to_s.split("_")
|
7
|
+
method = "#{action[1]}_#{action[2]}"
|
8
|
+
url = "/#{args[0]}/#{method}"
|
9
|
+
self.send(action[0],url,args[1])
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def self.post(url,data)
|
15
|
+
resp = resource[url].post data.to_json, self.content
|
16
|
+
resp.body
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.token
|
20
|
+
url = Rhoconnectrb.configuration.uri || ENV['RHOCONNECT_URL']
|
21
|
+
uri = URI.parse(url)
|
22
|
+
Rhoconnectrb.configuration.token || uri.user
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.content
|
26
|
+
{'X-RhoConnect-API-TOKEN'=> self.token, :content_type => :json, :accept => :json}
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.resource
|
30
|
+
uri = Rhoconnectrb.configuration.uri || ENV['RHOCONNECT_URL']
|
31
|
+
RestClient::Resource.new(uri + "/app/v1")
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Rhoconnectrb
|
2
|
+
module API
|
3
|
+
class Sources
|
4
|
+
|
5
|
+
def self.klass
|
6
|
+
self.to_s.underscore.split('/')[2]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.method_missing method_name, *args
|
10
|
+
action = method_name.to_s.split("_")
|
11
|
+
#handle CRUD operations
|
12
|
+
if action.size == 1
|
13
|
+
if action[0] =~ /put|delete/
|
14
|
+
resp = Base.send(action[0],"/#{klass}/#{args[0]}",args[1])
|
15
|
+
else
|
16
|
+
url = args.size > 0 ? "/#{klass}/#{args[0]}" : klass
|
17
|
+
resp = Base.send(action[0],url,args[1])
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
if action.size > 1
|
22
|
+
verb = action.delete_at(0)
|
23
|
+
#if posting without parameters just post with data else contruct url
|
24
|
+
if verb == 'post' and !args[1]
|
25
|
+
resp = Base.send(verb,"/#{klass}/#{action[0]}",args[0])
|
26
|
+
elsif action[0] =~ /type/
|
27
|
+
#special case currently for this one call, refactor after rhoconnect is refactored. check for array or string passed
|
28
|
+
partition_type = args[0].is_a?(Array) ? args[0].first.to_sym : args[0].to_sym
|
29
|
+
resp = Base.send(verb,"/#{klass}/#{action[0]}/#{partition_type}")
|
30
|
+
else
|
31
|
+
if args[0].class.to_s == 'String'
|
32
|
+
url = "/#{klass}/#{args[0]}/#{action[0]}"
|
33
|
+
else
|
34
|
+
url = klass
|
35
|
+
args[0].each_with_index do |value,index|
|
36
|
+
url += "/#{value}"
|
37
|
+
url += "/#{action[index]}" if action[index]
|
38
|
+
end
|
39
|
+
end
|
40
|
+
resp = Base.send(verb,url,args[1])
|
41
|
+
end
|
42
|
+
end
|
43
|
+
resp
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Rhoconnectrb
|
2
|
+
module API
|
3
|
+
class Store
|
4
|
+
|
5
|
+
def self.klass
|
6
|
+
self.to_s.underscore.split('/')[2]
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.method_missing method_name, *args
|
10
|
+
action = method_name.to_s.split("_")
|
11
|
+
if action.size == 1
|
12
|
+
resp = Base.send(action[0],"/#{klass}/#{args[0]}",args[1])
|
13
|
+
else
|
14
|
+
|
15
|
+
verb = action.delete_at(0)
|
16
|
+
#if posting without parameters just post with data else contruct url
|
17
|
+
if verb == 'post' and !args[1]
|
18
|
+
resp = Base.send(verb,"/#{klass}/#{action[0]}",args[0])
|
19
|
+
else
|
20
|
+
if args[0].class.to_s == 'String'
|
21
|
+
url = "/#{klass}/#{args[0]}/#{action[0]}"
|
22
|
+
else
|
23
|
+
url = klass
|
24
|
+
args[0].each_with_index do |value,index|
|
25
|
+
url += "/#{value}"
|
26
|
+
url += "/#{action[index]}" if action[index]
|
27
|
+
end
|
28
|
+
end
|
29
|
+
resp = Base.send(verb,url,args[1])
|
30
|
+
end
|
31
|
+
end
|
32
|
+
resp
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|