usergrid_iron 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -6
- data/lib/usergrid/core/application.rb +25 -40
- data/lib/usergrid/core/entity.rb +6 -0
- data/lib/usergrid/core/resource.rb +11 -3
- data/lib/usergrid/extensions/hash.rb +12 -9
- data/lib/usergrid/version.rb +1 -1
- data/spec/usergrid/core/application_spec.rb +39 -5
- data/spec/usergrid/core/entity_spec.rb +6 -0
- data/usergrid_iron.gemspec +1 -1
- metadata +4 -4
data/README.md
CHANGED
@@ -47,7 +47,7 @@ application = Usergrid::Application.new "#{usergrid_api}/#{organization}/#{appli
|
|
47
47
|
application.login username, password
|
48
48
|
|
49
49
|
# create and store a dog in the 'dogs' collection on the server
|
50
|
-
response = application.
|
50
|
+
response = application.create_dog breed: 'Black Mouth Cur', name: 'Old Yeller'
|
51
51
|
|
52
52
|
# let's get the dog from the response and grab its persistent id
|
53
53
|
dog = response.entity
|
@@ -89,7 +89,7 @@ you shouldn't need to do anything!)
|
|
89
89
|
new_application = organization.create_application app_name
|
90
90
|
|
91
91
|
# create an user for our application
|
92
|
-
new_application.create_user 'username', 'password'
|
92
|
+
new_application.create_user username: 'username', password: 'password'
|
93
93
|
|
94
94
|
|
95
95
|
## now we can play with the puppies! ##
|
@@ -99,10 +99,11 @@ you shouldn't need to do anything!)
|
|
99
99
|
application.login 'username', 'password'
|
100
100
|
|
101
101
|
# we can start with our dog again
|
102
|
-
application.
|
102
|
+
application.create_dog breed: 'Black Mouth Cur', name: 'Old Yeller'
|
103
103
|
|
104
104
|
# but this time let's create several more dogs at once
|
105
|
-
application.
|
105
|
+
application.create_dogs [
|
106
|
+
{ breed: 'Catalan sheepdog', name: 'Einstein' },
|
106
107
|
{ breed: 'Cocker Spaniel', name: 'Lady' },
|
107
108
|
{ breed: 'Mixed', name: 'Benji' }]
|
108
109
|
|
@@ -122,7 +123,7 @@ you shouldn't need to do anything!)
|
|
122
123
|
|
123
124
|
# query for the dogs that are home (should just be Benji)
|
124
125
|
dogs = application['dogs'].query("select * where location = 'home'").collection
|
125
|
-
if dogs.size == 1 && dogs.first == 'home'
|
126
|
+
if dogs.size == 1 && dogs.first.location == 'home'
|
126
127
|
puts "Benji's home!"
|
127
128
|
end
|
128
129
|
|
@@ -154,7 +155,24 @@ usergrid_iron/spec/spec_settings.yaml to match.)
|
|
154
155
|
|
155
156
|
## Release notes
|
156
157
|
|
157
|
-
### 0.0.
|
158
|
+
### 0.0.5
|
159
|
+
* New features
|
160
|
+
1. added create_* method for application
|
161
|
+
* Backend changes
|
162
|
+
1. eliminated serialization of reserved attributes
|
163
|
+
* Incompatible changes
|
164
|
+
1. deprecated `Application::create_user username, password, ...`, use `create_user username: 'user', password: 'password'`
|
165
|
+
|
166
|
+
### 0.0.4
|
167
|
+
* New features
|
168
|
+
1. empty? check for collection
|
169
|
+
2. update queries (batch update)
|
170
|
+
* Backend changes
|
171
|
+
1. Additional data sanity checks
|
172
|
+
2. Additional flexibility in concat_urls
|
173
|
+
3. Cleanup
|
174
|
+
|
175
|
+
### 0.0.3
|
158
176
|
* New features
|
159
177
|
1. Support for lists returned when making parameterized queries:
|
160
178
|
<pre>select username, email where…</pre>
|
@@ -7,51 +7,24 @@ module Usergrid
|
|
7
7
|
super url, api_url, options
|
8
8
|
end
|
9
9
|
|
10
|
-
|
11
|
-
user_hash = { username: username,
|
12
|
-
password: password,
|
13
|
-
email: email,
|
14
|
-
name: name,
|
15
|
-
invite: invite }
|
16
|
-
create_entity 'users', user_hash
|
17
|
-
end
|
18
|
-
|
19
|
-
# note: collection_name s/b plural!
|
10
|
+
# note: collection_name s/b plural, but the server will change it if not
|
20
11
|
def create_entity(collection_name, entity_data)
|
21
12
|
self[collection_name].post entity_data
|
22
13
|
end
|
23
14
|
alias_method :create_entities, :create_entity
|
24
15
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
def devices(query=nil, options={})
|
38
|
-
self[__method__].query(query, options)
|
39
|
-
end
|
40
|
-
|
41
|
-
def assets(query=nil, options={})
|
42
|
-
self[__method__].query(query, options)
|
43
|
-
end
|
44
|
-
|
45
|
-
def folders(query=nil, options={})
|
46
|
-
self[__method__].query(query, options)
|
47
|
-
end
|
48
|
-
|
49
|
-
def events(query=nil, options={})
|
50
|
-
self[__method__].query(query, options)
|
51
|
-
end
|
52
|
-
|
53
|
-
def roles(query=nil, options={})
|
54
|
-
self[__method__].query(query, options)
|
16
|
+
# allow create_something(hash_or_array) method
|
17
|
+
def method_missing(method, *args, &block)
|
18
|
+
method_s = method.to_s
|
19
|
+
if method_s.start_with? 'create_'
|
20
|
+
entity = method_s.split('_')[1]
|
21
|
+
return _create_user *args if entity == 'user' && args[0].is_a?(String) # backwards compatibility
|
22
|
+
create_entity entity, *args
|
23
|
+
elsif method_s.end_with? 's' # shortcut for retrieving collections
|
24
|
+
self[method].query(*args)
|
25
|
+
else
|
26
|
+
super method, args, block
|
27
|
+
end
|
55
28
|
end
|
56
29
|
|
57
30
|
def counter_names
|
@@ -64,5 +37,17 @@ module Usergrid
|
|
64
37
|
self['counters'].get({params: options})
|
65
38
|
end
|
66
39
|
|
40
|
+
private
|
41
|
+
|
42
|
+
def _create_user(username, password, email=nil, name=nil, invite=false)
|
43
|
+
LOG.warn "create_user(username, password, ...) is deprecated"
|
44
|
+
user_hash = { username: username,
|
45
|
+
password: password,
|
46
|
+
email: email,
|
47
|
+
name: name,
|
48
|
+
invite: invite }
|
49
|
+
create_entity 'users', user_hash
|
50
|
+
end
|
51
|
+
|
67
52
|
end
|
68
53
|
end
|
data/lib/usergrid/core/entity.rb
CHANGED
@@ -3,8 +3,9 @@ require 'rest_client'
|
|
3
3
|
module Usergrid
|
4
4
|
class Resource < RestClient::Resource
|
5
5
|
|
6
|
+
RESERVED = %w( created modified metadata uri )
|
6
7
|
DEFAULT_API_URL = 'https://api.usergrid.com'
|
7
|
-
TYPE_HEADERS = { :
|
8
|
+
TYPE_HEADERS = { content_type: :json, accept: :json }
|
8
9
|
|
9
10
|
attr_reader :current_user, :api_url
|
10
11
|
|
@@ -59,10 +60,17 @@ module Usergrid
|
|
59
60
|
end
|
60
61
|
|
61
62
|
def entity
|
63
|
+
get unless response
|
62
64
|
response.entity
|
63
65
|
end
|
64
66
|
|
67
|
+
def entities
|
68
|
+
get unless response
|
69
|
+
response.entities
|
70
|
+
end
|
71
|
+
|
65
72
|
def collection
|
73
|
+
get unless response
|
66
74
|
Collection.new url, api_url, options, response
|
67
75
|
end
|
68
76
|
|
@@ -85,12 +93,12 @@ module Usergrid
|
|
85
93
|
end
|
86
94
|
|
87
95
|
def post(payload, additional_headers={}, &block)
|
88
|
-
payload = MultiJson.dump(payload)
|
96
|
+
payload = MultiJson.dump(payload) unless payload.is_a? String
|
89
97
|
self.response = super payload, additional_headers, &block
|
90
98
|
end
|
91
99
|
|
92
100
|
def put(payload, additional_headers={}, &block)
|
93
|
-
payload = MultiJson.dump(payload)
|
101
|
+
payload = MultiJson.dump(payload) unless payload.is_a? String
|
94
102
|
self.response = super payload, additional_headers, &block
|
95
103
|
end
|
96
104
|
|
@@ -1,10 +1,5 @@
|
|
1
1
|
class Hash
|
2
2
|
|
3
|
-
# recursive
|
4
|
-
def add_dot_notation!
|
5
|
-
add_dot_notation_recurse! self
|
6
|
-
end
|
7
|
-
|
8
3
|
# not recursive
|
9
4
|
def symbolize_keys
|
10
5
|
inject({}) do |options, (key, value)|
|
@@ -13,15 +8,23 @@ class Hash
|
|
13
8
|
end
|
14
9
|
end
|
15
10
|
|
16
|
-
|
11
|
+
def except(*keys)
|
12
|
+
dup.except! *keys
|
13
|
+
end
|
17
14
|
|
18
|
-
def
|
15
|
+
def except!(*keys)
|
16
|
+
keys.each { |key| key.is_a?(Array) ? except!(*key) : delete(key) }
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
# recursive
|
21
|
+
def add_dot_notation!(_hash=self)
|
19
22
|
_hash.each do |k,v|
|
20
23
|
getter = k.to_sym; setter = "#{k}=".to_sym
|
21
24
|
_hash.define_singleton_method getter, lambda { _hash[k] } unless _hash.respond_to? getter
|
22
25
|
_hash.define_singleton_method setter, lambda { |v| _hash[k] = v } unless _hash.respond_to? setter
|
23
|
-
|
24
|
-
v.each { |e|
|
26
|
+
add_dot_notation!(v) if v.is_a? Hash
|
27
|
+
v.each { |e| add_dot_notation!(e) if e.is_a? Hash } if v.is_a? Array
|
25
28
|
end
|
26
29
|
end
|
27
30
|
end
|
data/lib/usergrid/version.rb
CHANGED
@@ -10,10 +10,16 @@ describe Usergrid::Application do
|
|
10
10
|
delete_application @application
|
11
11
|
end
|
12
12
|
|
13
|
+
it "should be able to create a user using deprecated syntax" do
|
14
|
+
random = SecureRandom.hex
|
15
|
+
response = @application.create_user "username_#{random}", 'password'
|
16
|
+
response.entity.uuid.should_not be_nil
|
17
|
+
end
|
18
|
+
|
13
19
|
it "should be able to create, login, and delete a user" do
|
14
20
|
random = SecureRandom.hex
|
15
21
|
application = Usergrid::Application.new @application.url # create application resource that's not logged in
|
16
|
-
response = application.create_user "username_#{random}", 'password'
|
22
|
+
response = application.create_user username: "username_#{random}", password: 'password'
|
17
23
|
entity = response.entity
|
18
24
|
application.login "username_#{random}", 'password'
|
19
25
|
begin
|
@@ -201,7 +207,8 @@ describe Usergrid::Application do
|
|
201
207
|
response = @application.counter 'test'
|
202
208
|
counter = response.data.counters.first
|
203
209
|
counter.name.should eq 'test'
|
204
|
-
|
210
|
+
# can't reliably test this - counters are batched on server
|
211
|
+
#counter.values.last.first.value.should be > 0
|
205
212
|
end
|
206
213
|
|
207
214
|
it "should be able to create, retrieve, and delete roles" do
|
@@ -251,13 +258,40 @@ describe Usergrid::Application do
|
|
251
258
|
end
|
252
259
|
|
253
260
|
it "should be able to create a new collection and access it" do
|
254
|
-
entities = (1..4).collect
|
255
|
-
{ name: "test_#{i}" }
|
256
|
-
end
|
261
|
+
entities = (1..4).collect { |i| { name: "test_#{i}" } }
|
257
262
|
@application.create_entities 'tests', entities
|
258
263
|
response = @application['tests'].get
|
259
264
|
collection = response.collection
|
260
265
|
collection.size.should eq 4
|
261
266
|
end
|
262
267
|
|
268
|
+
it "should be able to create a new collection via create_ method and access it" do
|
269
|
+
entities = (1..4).collect { |i| { name: "test_#{i}" } }
|
270
|
+
@application.create_moretests entities
|
271
|
+
response = @application['tests'].get
|
272
|
+
collection = response.collection
|
273
|
+
collection.size.should eq 4
|
274
|
+
end
|
275
|
+
|
276
|
+
it "should be able to access a collection without calling get" do
|
277
|
+
entities = (1..4).collect { |i| { name: "test_#{i}" } }
|
278
|
+
@application.create_entities 'tests', entities
|
279
|
+
collection = @application['tests'].collection
|
280
|
+
collection.size.should eq 4
|
281
|
+
end
|
282
|
+
|
283
|
+
it "should be able to access entities without calling get" do
|
284
|
+
entities = (1..4).collect { |i| { name: "test_#{i}" } }
|
285
|
+
@application.create_entities 'tests', entities
|
286
|
+
entities = @application['tests'].entities
|
287
|
+
entities.size.should eq 4
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should be able to query using dot notation" do
|
291
|
+
entities = (1..4).collect { |i| { name: "test_#{i}" } }
|
292
|
+
@application.create_btests entities
|
293
|
+
entities = @application.btests("name = 'test_1'").entities
|
294
|
+
entities.size.should eq 1
|
295
|
+
end
|
296
|
+
|
263
297
|
end
|
@@ -46,4 +46,10 @@ describe Usergrid::Entity do
|
|
46
46
|
@application['foobars'].get.entity.should be_nil
|
47
47
|
end
|
48
48
|
|
49
|
+
it "should not serialize reserved attributes" do
|
50
|
+
dump = MultiJson.dump @user
|
51
|
+
hash = MultiJson.load dump
|
52
|
+
Usergrid::Resource::RESERVED.each { |a| hash.should_not have_key(a) }
|
53
|
+
end
|
54
|
+
|
49
55
|
end
|
data/usergrid_iron.gemspec
CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |gem|
|
|
9
9
|
(aka Usergrid) REST API with minimal dependencies.}
|
10
10
|
gem.homepage = "https://github.com/scottganyo/usergrid_iron"
|
11
11
|
|
12
|
-
gem.files =
|
12
|
+
gem.files = `git ls-files`.split($\)
|
13
13
|
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
14
14
|
gem.test_files = gem.files.grep(%r{^(spec|spec|features)/})
|
15
15
|
gem.name = "usergrid_iron"
|
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.5
|
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-
|
12
|
+
date: 2012-11-16 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rest-client
|
@@ -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: -2026056560338254280
|
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: -2026056560338254280
|
162
162
|
requirements: []
|
163
163
|
rubyforge_project:
|
164
164
|
rubygems_version: 1.8.24
|