usergrid_iron 0.0.2 → 0.0.3
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/.rvmrc +1 -1
- data/README.md +55 -33
- data/lib/usergrid/core/application.rb +7 -7
- data/lib/usergrid/core/resource.rb +2 -2
- data/lib/usergrid/extensions/response.rb +8 -4
- data/lib/usergrid/version.rb +1 -1
- data/lib/usergrid_iron.rb +2 -1
- data/spec/spec_helper.rb +3 -3
- data/spec/usergrid/core/application_spec.rb +8 -3
- data/spec/usergrid/core/collection_spec.rb +20 -2
- data/usergrid_iron.gemspec +1 -1
- metadata +5 -5
data/.rvmrc
CHANGED
@@ -1,2 +1,2 @@
|
|
1
1
|
rvm_gemset_create_on_use_flag=1
|
2
|
-
rvm gemset use '
|
2
|
+
rvm gemset use 'usergrid_iron'
|
data/README.md
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
# Usergrid_iron
|
2
2
|
|
3
|
-
Usergrid_iron enables simple, low-level Ruby access to Apigee's App Services (aka Usergrid)
|
4
|
-
dependencies.
|
5
|
-
|
3
|
+
Usergrid_iron enables simple, low-level Ruby access to Apigee's App Services (aka Usergrid)
|
4
|
+
REST API with minimal dependencies.
|
6
5
|
|
7
6
|
## Installation
|
8
7
|
|
@@ -21,16 +20,20 @@ Or install it yourself as:
|
|
21
20
|
|
22
21
|
## Usage
|
23
22
|
|
24
|
-
|
23
|
+
### Not familiar with Usergrid / Apigee's App Services?
|
24
|
+
|
25
|
+
#### It's great stuff! Check it out, here:
|
26
|
+
|
27
|
+
Docs: <http://apigee.com/docs/usergrid/>
|
28
|
+
Open source: <https://github.com/apigee/usergrid-stack>
|
25
29
|
|
26
|
-
|
27
|
-
Open source: https://github.com/apigee/usergrid-stack
|
30
|
+
### Getting started with the Usergrid_iron SDK is simple!
|
28
31
|
|
29
|
-
|
30
|
-
|
31
|
-
own values in the code below.
|
32
|
+
#### Let's start with the basics.
|
33
|
+
For this example, we'll assume you've already set up an organization, application, and user -
|
34
|
+
just fill in your own values in the code below.
|
32
35
|
|
33
|
-
|
36
|
+
```
|
34
37
|
require 'usergrid_iron'
|
35
38
|
|
36
39
|
# fill in your values here!
|
@@ -55,15 +58,18 @@ same_dog = application['dogs'][uuid].entity
|
|
55
58
|
|
56
59
|
# is it our dog? well, he knows his name!
|
57
60
|
puts "My dog's name is: #{same_dog.name}"
|
58
|
-
|
61
|
+
```
|
59
62
|
|
60
|
-
|
61
|
-
Let's say we've registered for an organization, but we don't have an application yet (or
|
62
|
-
want to create a new one to work on). No worries, just fill in your organization and
|
63
|
-
superuser credentials below, and follow along! (Better yet: If you used the Usergrid launcher
|
64
|
-
and let it initialize your database, you shouldn't need to do anything!)
|
63
|
+
Well that was really easy.
|
65
64
|
|
66
|
-
|
65
|
+
#### Let's try something slightly more complex.
|
66
|
+
Let's say you've registered for an organization, but you don't have an application yet
|
67
|
+
(or want to create a new one to work on). No worries, just fill in your organization and
|
68
|
+
superuser credentials below, and follow along!
|
69
|
+
(Better yet: If you used the Usergrid launcher and let it initialize your database,
|
70
|
+
you shouldn't need to do anything!)
|
71
|
+
|
72
|
+
```
|
67
73
|
require 'usergrid_iron'
|
68
74
|
|
69
75
|
usergrid_api = 'http://localhost:8080'
|
@@ -83,7 +89,7 @@ and let it initialize your database, you shouldn't need to do anything!)
|
|
83
89
|
new_application = organization.create_application app_name
|
84
90
|
|
85
91
|
# create an user for our application
|
86
|
-
new_application.create_user 'username', '
|
92
|
+
new_application.create_user 'username', 'password'
|
87
93
|
|
88
94
|
|
89
95
|
## now we can play with the puppies! ##
|
@@ -107,7 +113,7 @@ and let it initialize your database, you shouldn't need to do anything!)
|
|
107
113
|
end
|
108
114
|
|
109
115
|
# "Benji, come!"
|
110
|
-
benji = dogs.query("select * where name = 'Benji'").entity # shortcut: entity
|
116
|
+
benji = dogs.query("select * where name = 'Benji'").entity # shortcut: entity() returns the first
|
111
117
|
|
112
118
|
# modify Benji's attributes & save
|
113
119
|
benji.location = 'home' # use attribute access
|
@@ -120,7 +126,7 @@ and let it initialize your database, you shouldn't need to do anything!)
|
|
120
126
|
puts "Benji's home!"
|
121
127
|
end
|
122
128
|
|
123
|
-
|
129
|
+
```
|
124
130
|
|
125
131
|
Whew. That's enough for now. But looking for a specific feature? Check out the rspecs,
|
126
132
|
there are examples of nearly everything!
|
@@ -146,6 +152,23 @@ In order to run the tests, check out the Usergrid open source project
|
|
146
152
|
usergrid_iron/spec/spec_settings.yaml to match.)
|
147
153
|
|
148
154
|
|
155
|
+
## Release notes
|
156
|
+
|
157
|
+
### 0.0.3
|
158
|
+
* New features
|
159
|
+
1. Support for lists returned when making parameterized queries:
|
160
|
+
<pre>select username, email where…</pre>
|
161
|
+
or replacement queries:
|
162
|
+
<pre>select { user:username, email:email } where…
|
163
|
+
* Incompatible changes
|
164
|
+
1. Application.create_user parameter change from:
|
165
|
+
<pre>create_user(username, name, email, password, invite=false)</pre>
|
166
|
+
to:
|
167
|
+
<pre>create_user(username, password, email=nil, name=nil, invite=false)</pre>
|
168
|
+
* Backend changes
|
169
|
+
1. Replaced json_pure dependency with multi_json
|
170
|
+
|
171
|
+
|
149
172
|
## Notes
|
150
173
|
|
151
174
|
The following features are not currently implemented on the server:
|
@@ -156,17 +179,16 @@ The following features are not currently implemented on the server:
|
|
156
179
|
|
157
180
|
|
158
181
|
## Copyright
|
182
|
+
Copyright (c) 2012 Scott Ganyo
|
183
|
+
|
184
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
185
|
+
you may not use the included files except in compliance with the License.
|
186
|
+
|
187
|
+
You may obtain a copy of the License at
|
159
188
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
167
|
-
*
|
168
|
-
* Unless required by applicable law or agreed to in writing, software
|
169
|
-
* distributed under the License is distributed on an "AS IS" BASIS,
|
170
|
-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
171
|
-
* See the License for the specific language governing permissions and
|
172
|
-
* limitations under the License.
|
189
|
+
<http://www.apache.org/licenses/LICENSE-2.0>
|
190
|
+
|
191
|
+
Unless required by applicable law or agreed to in writing, software distributed under
|
192
|
+
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
|
193
|
+
either express or implied. See the License for the specific language governing permissions and
|
194
|
+
limitations under the License.
|
@@ -7,13 +7,13 @@ module Usergrid
|
|
7
7
|
super url, api_url, options
|
8
8
|
end
|
9
9
|
|
10
|
-
def create_user(username,
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
create_entity 'users',
|
10
|
+
def create_user(username, password, email=nil, name=nil, invite=false)
|
11
|
+
user_hash = { username: username,
|
12
|
+
password: password,
|
13
|
+
email: email,
|
14
|
+
name: name,
|
15
|
+
invite: invite }
|
16
|
+
create_entity 'users', user_hash
|
17
17
|
end
|
18
18
|
|
19
19
|
# note: collection_name s/b plural!
|
@@ -78,12 +78,12 @@ module Usergrid
|
|
78
78
|
end
|
79
79
|
|
80
80
|
def post(payload, additional_headers={}, &block)
|
81
|
-
payload = payload
|
81
|
+
payload = MultiJson.dump(payload) if payload.is_a?(Hash) || payload.is_a?(Array)
|
82
82
|
self.response = super payload, additional_headers, &block
|
83
83
|
end
|
84
84
|
|
85
85
|
def put(payload, additional_headers={}, &block)
|
86
|
-
payload = payload
|
86
|
+
payload = MultiJson.dump(payload) if payload.is_a?(Hash) || payload.is_a?(Array)
|
87
87
|
self.response = super payload, additional_headers, &block
|
88
88
|
end
|
89
89
|
|
@@ -10,7 +10,7 @@ module RestClient
|
|
10
10
|
end
|
11
11
|
|
12
12
|
def data
|
13
|
-
@data =
|
13
|
+
@data = MultiJson.load(self).add_dot_notation! unless @data
|
14
14
|
@data
|
15
15
|
end
|
16
16
|
|
@@ -25,10 +25,10 @@ module RestClient
|
|
25
25
|
|
26
26
|
def entities_data
|
27
27
|
return @entities_data if @entities_data
|
28
|
-
entities_data = data['entities'] || data['data'] || data['messages']
|
28
|
+
entities_data = data['entities'] || data['data'] || data['messages'] || data['list']
|
29
29
|
raise "unable to determine entities from: #{data}" unless entities_data.is_a?(Array)
|
30
30
|
entities_data.each do |e|
|
31
|
-
e['uri'] = resource.concat_urls(data['uri'], e['uuid']) if e['uuid']
|
31
|
+
e['uri'] = resource.concat_urls(data['uri'], e['uuid']) if e.is_a?(Hash) && e['uuid']
|
32
32
|
end
|
33
33
|
@entities_data = entities_data
|
34
34
|
end
|
@@ -37,7 +37,11 @@ module RestClient
|
|
37
37
|
return @entities if @entities
|
38
38
|
index = -1
|
39
39
|
@entities = entities_data.collect do |e|
|
40
|
-
|
40
|
+
if e.is_a? Array
|
41
|
+
e
|
42
|
+
else
|
43
|
+
Usergrid::Entity.new e['uri'], resource.api_url, resource.options, self, index+=1
|
44
|
+
end
|
41
45
|
end
|
42
46
|
end
|
43
47
|
|
data/lib/usergrid/version.rb
CHANGED
data/lib/usergrid_iron.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -29,7 +29,7 @@ begin
|
|
29
29
|
SPEC_SETTINGS[:organization][:password])
|
30
30
|
LOG.info "created organization with user #{SPEC_SETTINGS[:organization][:username]}@email.com"
|
31
31
|
rescue
|
32
|
-
if
|
32
|
+
if MultiJson.load($!.response)['error'] == "duplicate_unique_property_exists"
|
33
33
|
LOG.debug "test organization exists"
|
34
34
|
else
|
35
35
|
raise $!
|
@@ -62,9 +62,9 @@ end
|
|
62
62
|
def create_random_user(application, login=false)
|
63
63
|
random = SecureRandom.hex
|
64
64
|
user_hash = {username: "username_#{random}",
|
65
|
-
|
65
|
+
password: random,
|
66
66
|
email: "#{random}@email.com",
|
67
|
-
|
67
|
+
name: "#{random} name" }
|
68
68
|
entity = application['users'].post(user_hash).entity
|
69
69
|
application.login user_hash[:username], user_hash[:password] if login
|
70
70
|
entity
|
@@ -10,18 +10,23 @@ describe Usergrid::Application do
|
|
10
10
|
delete_application @application
|
11
11
|
end
|
12
12
|
|
13
|
-
it "should be able to create and delete a user" do
|
13
|
+
it "should be able to create, login, and delete a user" do
|
14
14
|
random = SecureRandom.hex
|
15
|
-
|
15
|
+
application = Usergrid::Application.new @application.url # create application resource that's not logged in
|
16
|
+
response = application.create_user "username_#{random}", 'password'
|
16
17
|
entity = response.entity
|
18
|
+
application.login "username_#{random}", 'password'
|
17
19
|
begin
|
18
20
|
response.code.should eq 200
|
19
21
|
response.entities.size.should eq 1
|
20
22
|
entity.uuid.should_not be_nil
|
21
|
-
response =
|
23
|
+
response = application["users/#{entity.uuid}"].get
|
22
24
|
response.code.should eq 200
|
23
25
|
ensure
|
24
26
|
entity.delete
|
27
|
+
# deleted user shouldn't be able to access anything now
|
28
|
+
expect { application["users/#{entity.uuid}"].get }.to raise_error(RestClient::Unauthorized)
|
29
|
+
# use original application - logged in under existing user
|
25
30
|
expect { @application["users/#{entity.uuid}"].get }.to raise_error(RestClient::ResourceNotFound)
|
26
31
|
end
|
27
32
|
end
|
@@ -7,7 +7,7 @@ describe Usergrid::Collection do
|
|
7
7
|
@collection = @application['tests'].collection
|
8
8
|
@entity_data = []
|
9
9
|
(1..10).each do |i|
|
10
|
-
test = { name: "
|
10
|
+
test = { name: "name_#{i}", value: "value_#{i+1}" }
|
11
11
|
@entity_data << test
|
12
12
|
end
|
13
13
|
@collection.create_entities @entity_data
|
@@ -18,11 +18,29 @@ describe Usergrid::Collection do
|
|
18
18
|
delete_application @application
|
19
19
|
end
|
20
20
|
|
21
|
-
it "should be able to
|
21
|
+
it "should be able to do a simple query" do
|
22
22
|
@collection.query "select * where name = \'#{@entity_data[0][:name]}\'"
|
23
23
|
@collection.size.should eq 1
|
24
24
|
end
|
25
25
|
|
26
|
+
it "should be able to select data elements" do
|
27
|
+
@collection.query "select name, value where name = \'#{@entity_data[0][:name]}\'"
|
28
|
+
@collection.size.should eq 1
|
29
|
+
# note: not Usergrid::Entity objects: it is an Array for this kind of query
|
30
|
+
values = @collection.entities.first
|
31
|
+
values[0].should eq @entity_data[0][:name]
|
32
|
+
values[1].should eq @entity_data[0][:value]
|
33
|
+
end
|
34
|
+
|
35
|
+
it "should be able to select redefined data elements" do
|
36
|
+
@collection.query "select { test1: name, test2 : value } where name = \'#{@entity_data[0][:name]}\'"
|
37
|
+
@collection.size.should eq 1
|
38
|
+
# note: not Usergrid::Entity objects: it is a Hash for this kind of query
|
39
|
+
values = @collection.entities.first
|
40
|
+
values.test1.should eq @entity_data[0][:name]
|
41
|
+
values.test2.should eq @entity_data[0][:value]
|
42
|
+
end
|
43
|
+
|
26
44
|
it "should be able to find an entity" do
|
27
45
|
@collection.query
|
28
46
|
entity = @collection.detect { |e| e.name == @entity_data[5][:name] }
|
data/usergrid_iron.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.version = Usergrid::VERSION
|
18
18
|
|
19
19
|
gem.add_dependency 'rest-client'
|
20
|
-
gem.add_dependency '
|
20
|
+
gem.add_dependency 'multi_json'
|
21
21
|
|
22
22
|
gem.add_development_dependency 'rake'
|
23
23
|
gem.add_development_dependency 'rspec'
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: usergrid_iron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-09-
|
12
|
+
date: 2012-09-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -28,7 +28,7 @@ dependencies:
|
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '0'
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: multi_json
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
none: false
|
34
34
|
requirements:
|
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
version: '0'
|
150
150
|
segments:
|
151
151
|
- 0
|
152
|
-
hash: -
|
152
|
+
hash: -270819572663973399
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
none: false
|
155
155
|
requirements:
|
@@ -158,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
158
158
|
version: '0'
|
159
159
|
segments:
|
160
160
|
- 0
|
161
|
-
hash: -
|
161
|
+
hash: -270819572663973399
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
164
|
rubygems_version: 1.8.24
|