rhoconnect-rb 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +10 -0
- data/Gemfile +1 -1
- data/README.md +23 -14
- data/Rakefile +1 -1
- data/lib/rhoconnect/client.rb +3 -4
- data/lib/rhoconnect/configuration.rb +3 -3
- data/lib/rhoconnect/endpoints.rb +1 -1
- data/lib/rhoconnect/resource.rb +1 -1
- data/lib/rhoconnect/version.rb +1 -1
- data/spec/client_spec.rb +3 -3
- data/spec/endpoints_spec.rb +1 -1
- metadata +47 -61
data/.travis.yml
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,9 @@
|
|
1
|
-
rhoconnect-rb
|
1
|
+
rhoconnect-rb ![Build Status](https://secure.travis-ci.org/rhomobile/rhoconnect-rb.png)
|
2
2
|
===
|
3
3
|
|
4
|
-
A ruby library for the [
|
4
|
+
A ruby library for the [RhoConnect](http://rhomobile.com/products/rhoconnect) App Integration Server.
|
5
5
|
|
6
|
-
Using rhoconnect-rb, your application's model data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [
|
6
|
+
Using rhoconnect-rb, your application's model data will transparently synchronize with a mobile application built on the [Rhodes framework](http://rhomobile.com/products/rhodes), or any of the available [RhoConnect clients](http://rhomobile.com/products/rhoconnect/). This client includes built-in support for [ActiveRecord](http://ar.rubyonrails.org/) and [DataMapper](http://datamapper.org/) models.
|
7
7
|
|
8
8
|
## Getting started
|
9
9
|
|
@@ -13,7 +13,7 @@ Load the `rhoconnect-rb` library:
|
|
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
17
|
Now include Rhoconnect::Resource in a model that you want to synchronize with your mobile application:
|
18
18
|
|
19
19
|
class Product < ActiveRecord::Base
|
@@ -27,7 +27,7 @@ Or, if you are using DataMapper:
|
|
27
27
|
include Rhoconnect::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
|
|
@@ -52,9 +52,9 @@ Now all of the `Product` data synchronized by rhoconnect will organized by `self
|
|
52
52
|
:app
|
53
53
|
end
|
54
54
|
|
55
|
-
For more information about Rhoconnect partitions, please refer to the [Rhoconnect docs](http://docs.rhomobile.com/
|
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
|
58
58
|
|
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
|
|
@@ -67,25 +67,24 @@ For more information about Rhoconnect partitions, please refer to the [Rhoconnec
|
|
67
67
|
lambda { self.user.username }
|
68
68
|
end
|
69
69
|
|
70
|
-
def self.rhoconnect_query(partition)
|
71
|
-
Product.includes(:user).where("users.username = ?",partition)
|
70
|
+
def self.rhoconnect_query(partition, attributes = nil)
|
71
|
+
Product.includes(:user).where("users.username = ?", partition)
|
72
72
|
end
|
73
73
|
end
|
74
74
|
|
75
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
|
|
79
|
-
|
79
|
+
### Running RhoConnect Manually
|
80
80
|
|
81
|
+
Configure RhoConnect in an initializer like `config/initializers/rhoconnect.rb` (for Rails), or directly in your application (i.e. Sinatra). Here you will setup the rhoconnect uri (the location of your RhoConnect instance), the api\_token (see [rhoconnect:get_token](http://docs.rhomobile.com/rhoconnect/command-line#rake-tasks) rake task), and app\_endpoint (the location of your ruby app):
|
81
82
|
|
82
|
-
# Use rhoconnect:get_token to get the token value.
|
83
|
-
|
84
83
|
config.uri = "http://myrhoconnect.com"
|
85
84
|
config.token = "secrettoken"
|
86
85
|
config.app_endpoint = "http://myapp.heroku.com"
|
87
86
|
|
88
|
-
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",
|
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:
|
89
88
|
|
90
89
|
POST http://myapp.heroku.com/rhoconnect/query
|
91
90
|
|
@@ -109,6 +108,16 @@ Example with authentication:
|
|
109
108
|
}
|
110
109
|
end
|
111
110
|
|
111
|
+
### Using the [RhoConnect Heroku Addon](http://docs.rhomobile.com/rhoconnect/heroku-addon)
|
112
|
+
|
113
|
+
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
|
+
Rhoconnect.configure do |config|
|
116
|
+
config.authenticate = lambda { |credentials|
|
117
|
+
User.authenticate(credentials[:login], credentials[:password])
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
112
121
|
|
113
122
|
## Meta
|
114
123
|
Created and maintained by Lucas Campbell-Rossen, Vladimir Tarasov and Lars Burgess.
|
data/Rakefile
CHANGED
@@ -14,8 +14,8 @@ end
|
|
14
14
|
desc "Run all specs with rcov"
|
15
15
|
RSpec::Core::RakeTask.new(:rcov) do |t|
|
16
16
|
t.rcov = true
|
17
|
-
t.rspec_opts = ["-b", "-c", "-fd"]
|
18
17
|
t.rcov_opts = ['--exclude', 'spec/*,gems/*']
|
18
|
+
t.rspec_opts = ["-b", "-c", "-fd"]
|
19
19
|
end
|
20
20
|
|
21
21
|
task :default => :spec
|
data/lib/rhoconnect/client.rb
CHANGED
@@ -61,9 +61,8 @@ module Rhoconnect
|
|
61
61
|
def send_objects(action, source_name, partition, obj = {}) # :nodoc:
|
62
62
|
validate_args(source_name, partition, obj)
|
63
63
|
|
64
|
-
process(:post, "/
|
64
|
+
process(:post, "/app/v1/#{source_name}/#{action}",
|
65
65
|
{
|
66
|
-
:source_id => source_name,
|
67
66
|
:user_id => partition,
|
68
67
|
:objects => action == :push_deletes ? [obj['id'].to_s] : { obj['id'] => obj }
|
69
68
|
}
|
@@ -77,8 +76,8 @@ module Rhoconnect
|
|
77
76
|
def process(method, path, payload = nil) # :nodoc:
|
78
77
|
headers = api_headers
|
79
78
|
unless method == :get
|
80
|
-
payload = payload.
|
81
|
-
headers = api_headers.merge(:content_type => 'application/json')
|
79
|
+
payload = payload.to_json
|
80
|
+
headers = api_headers.merge(:content_type => 'application/json', 'X-RhoConnect-API-TOKEN' => @token)
|
82
81
|
end
|
83
82
|
args = [method, payload, headers].compact
|
84
83
|
response = resource(path).send(*args)
|
@@ -42,9 +42,9 @@ module Rhoconnect
|
|
42
42
|
uri = uri.to_s
|
43
43
|
end
|
44
44
|
token ||= ENV['token'] || self.configuration.token
|
45
|
-
Rhoconnect::Client.set_app_endpoint(:url => uri + "/
|
46
|
-
:payload => {:
|
47
|
-
:headers => {:content_type => 'application/json'}
|
45
|
+
Rhoconnect::Client.set_app_endpoint(:url => uri + "/rc/v1/system/appserver",
|
46
|
+
:payload => {:adapter_url => endpoint_url}.to_json,
|
47
|
+
:headers => {:content_type => 'application/json', 'X-RhoConnect-API-TOKEN' => token}
|
48
48
|
) if endpoint_url && uri && token
|
49
49
|
end
|
50
50
|
end
|
data/lib/rhoconnect/endpoints.rb
CHANGED
@@ -15,7 +15,7 @@ module Rhoconnect
|
|
15
15
|
action, c_type, result, records = :rhoconnect_query, 'application/json', {}, []
|
16
16
|
# Call resource rhoconnect_query class method
|
17
17
|
code, error = get_rhoconnect_resource(params['resource'], action) do |klass|
|
18
|
-
records = klass.send(action, params['partition'])
|
18
|
+
records = klass.send(action, params['partition'], params['attributes'])
|
19
19
|
end
|
20
20
|
if code == 200
|
21
21
|
# Serialize records into hash of hashes
|
data/lib/rhoconnect/resource.rb
CHANGED
data/lib/rhoconnect/version.rb
CHANGED
data/spec/client_spec.rb
CHANGED
@@ -58,7 +58,7 @@ describe Rhoconnect::Client do
|
|
58
58
|
end
|
59
59
|
|
60
60
|
it "should create an object" do
|
61
|
-
stub_request(:post, "http://test.rhoconnect.com/
|
61
|
+
stub_request(:post, "http://test.rhoconnect.com/app/v1/Person/push_objects").with(
|
62
62
|
:headers => {"Content-Type" => "application/json"}
|
63
63
|
).to_return(:status => 200, :body => "done")
|
64
64
|
resp = @client.create("Person", "user1",
|
@@ -72,7 +72,7 @@ describe Rhoconnect::Client do
|
|
72
72
|
end
|
73
73
|
|
74
74
|
it "should update an object" do
|
75
|
-
stub_request(:post, "http://test.rhoconnect.com/
|
75
|
+
stub_request(:post, "http://test.rhoconnect.com/app/v1/Person/push_objects").with(
|
76
76
|
:headers => {"Content-Type" => "application/json"}
|
77
77
|
).to_return(:status => 200, :body => "done")
|
78
78
|
resp = @client.update("Person", "user1",
|
@@ -86,7 +86,7 @@ describe Rhoconnect::Client do
|
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should destroy an object" do
|
89
|
-
stub_request(:post, "http://test.rhoconnect.com/
|
89
|
+
stub_request(:post, "http://test.rhoconnect.com/app/v1/Person/push_deletes").with(
|
90
90
|
:headers => {"Content-Type" => "application/json"}
|
91
91
|
).to_return(:status => 200, :body => "done")
|
92
92
|
resp = @client.destroy("Person", "user1",
|
data/spec/endpoints_spec.rb
CHANGED
metadata
CHANGED
@@ -1,67 +1,59 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: rhoconnect-rb
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 3
|
9
|
-
- 1
|
10
|
-
version: 0.3.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Rhomobile
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rest-client
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
22
17
|
none: false
|
23
|
-
requirements:
|
18
|
+
requirements:
|
24
19
|
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
hash: 13
|
27
|
-
segments:
|
28
|
-
- 1
|
29
|
-
- 6
|
30
|
-
- 1
|
20
|
+
- !ruby/object:Gem::Version
|
31
21
|
version: 1.6.1
|
32
|
-
requirement: *id001
|
33
22
|
type: :runtime
|
34
23
|
prerelease: false
|
35
|
-
|
36
|
-
|
37
|
-
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ~>
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 1.6.1
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: json
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
38
33
|
none: false
|
39
|
-
requirements:
|
40
|
-
- -
|
41
|
-
- !ruby/object:Gem::Version
|
42
|
-
hash: 11
|
43
|
-
segments:
|
44
|
-
- 1
|
45
|
-
- 4
|
46
|
-
- 6
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
47
37
|
version: 1.4.6
|
48
|
-
requirement: *id002
|
49
38
|
type: :runtime
|
50
39
|
prerelease: false
|
51
|
-
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 1.4.6
|
52
46
|
description: Rhoconnect rails plugin
|
53
|
-
email:
|
47
|
+
email:
|
54
48
|
- support@rhomobile.com
|
55
49
|
executables: []
|
56
|
-
|
57
50
|
extensions: []
|
58
|
-
|
59
51
|
extra_rdoc_files: []
|
60
|
-
|
61
|
-
files:
|
52
|
+
files:
|
62
53
|
- .autotest
|
63
54
|
- .gitignore
|
64
55
|
- .rspec
|
56
|
+
- .travis.yml
|
65
57
|
- Gemfile
|
66
58
|
- README.md
|
67
59
|
- Rakefile
|
@@ -83,38 +75,32 @@ files:
|
|
83
75
|
- templates/rhoconnect.rb
|
84
76
|
homepage: http://rhomobile.com
|
85
77
|
licenses: []
|
86
|
-
|
87
78
|
post_install_message:
|
88
79
|
rdoc_options: []
|
89
|
-
|
90
|
-
require_paths:
|
80
|
+
require_paths:
|
91
81
|
- lib
|
92
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
82
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
83
|
none: false
|
94
|
-
requirements:
|
95
|
-
- -
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
|
98
|
-
segments:
|
84
|
+
requirements:
|
85
|
+
- - ! '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
segments:
|
99
89
|
- 0
|
100
|
-
|
101
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
hash: 2309536265588466998
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
92
|
none: false
|
103
|
-
requirements:
|
104
|
-
- -
|
105
|
-
- !ruby/object:Gem::Version
|
106
|
-
|
107
|
-
segments:
|
108
|
-
- 0
|
109
|
-
version: "0"
|
93
|
+
requirements:
|
94
|
+
- - ! '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
110
97
|
requirements: []
|
111
|
-
|
112
98
|
rubyforge_project:
|
113
|
-
rubygems_version: 1.8.
|
99
|
+
rubygems_version: 1.8.24
|
114
100
|
signing_key:
|
115
101
|
specification_version: 3
|
116
102
|
summary: Rhoconnect rails plugin
|
117
|
-
test_files:
|
103
|
+
test_files:
|
118
104
|
- spec/client_spec.rb
|
119
105
|
- spec/endpoints_spec.rb
|
120
106
|
- spec/resource_spec.rb
|