Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

enable simpler and more comprehensive access to retrieve/query collec…

…tions, update examples, update version
  • Loading branch information...
commit fd39fe7d8411aa0297018470450be6adabc62210 1 parent 1db04b4
@theganyo authored
View
17 README.md
@@ -47,7 +47,7 @@ application = Usergrid::Application.new "#{usergrid_api}/#{organization}/#{appli
application.login username, password
# create and store a dog in the 'dogs' collection on the server
-response = application.create_entity 'dogs', { breed: 'Black Mouth Cur', name: 'Old Yeller' }
+response = application.create_dog breed: 'Black Mouth Cur', name: 'Old Yeller'
# let's get the dog from the response and grab its persistent id
dog = response.entity
@@ -89,7 +89,7 @@ you shouldn't need to do anything!)
new_application = organization.create_application app_name
# create an user for our application
- new_application.create_user 'username', 'password'
+ new_application.create_user username: 'username', password: 'password'
## now we can play with the puppies! ##
@@ -99,10 +99,11 @@ you shouldn't need to do anything!)
application.login 'username', 'password'
# we can start with our dog again
- application.create_entity 'dogs', { breed: 'Black Mouth Cur', name: 'Old Yeller' }
+ application.create_dog breed: 'Black Mouth Cur', name: 'Old Yeller'
# but this time let's create several more dogs at once
- application.create_entities 'dogs', [{ breed: 'Catalan sheepdog', name: 'Einstein' },
+ application.create_dogs [
+ { breed: 'Catalan sheepdog', name: 'Einstein' },
{ breed: 'Cocker Spaniel', name: 'Lady' },
{ breed: 'Mixed', name: 'Benji' }]
@@ -122,7 +123,7 @@ you shouldn't need to do anything!)
# query for the dogs that are home (should just be Benji)
dogs = application['dogs'].query("select * where location = 'home'").collection
- if dogs.size == 1 && dogs.first == 'home'
+ if dogs.size == 1 && dogs.first.location == 'home'
puts "Benji's home!"
end
@@ -154,6 +155,12 @@ usergrid_iron/spec/spec_settings.yaml to match.)
## Release notes
+### 0.0.5
+* New features
+ 1. added create_* method for application
+* Incompatible changes
+ 1. deprecated (Application::create_user username, password, ...) method
+
### 0.0.4
* New features
1. empty? check for collection
View
56 lib/usergrid/core/application.rb
@@ -7,15 +7,6 @@ def initialize(url, options={})
super url, api_url, options
end
- def create_user(username, password, email=nil, name=nil, invite=false)
- user_hash = { username: username,
- password: password,
- email: email,
- name: name,
- invite: invite }
- create_entity 'users', user_hash
- end
-
# note: collection_name s/b plural, but the server will change it if not
def create_entity(collection_name, entity_data)
self[collection_name].post entity_data
@@ -27,44 +18,15 @@ def method_missing(method, *args, &block)
method_s = method.to_s
if method_s.start_with? 'create_'
entity = method_s.split('_')[1]
+ return _create_user *args if entity == 'user' && args[0].is_a?(String) # backwards compatibility
create_entity entity, *args
+ elsif method_s.end_with? 's' # shortcut for retrieving collections
+ self[method].query(*args)
else
super method, args, block
end
end
- def users(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def groups(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def activities(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def devices(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def assets(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def folders(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def events(query=nil, options={})
- self[__method__].query(query, options)
- end
-
- def roles(query=nil, options={})
- self[__method__].query(query, options)
- end
-
def counter_names
self['counters'].get.data.data
end
@@ -75,5 +37,17 @@ def counter(name, other_params={})
self['counters'].get({params: options})
end
+ private
+
+ def _create_user(username, password, email=nil, name=nil, invite=false)
+ LOG.warn "create_user(username, password, ...) is deprecated"
+ user_hash = { username: username,
+ password: password,
+ email: email,
+ name: name,
+ invite: invite }
+ create_entity 'users', user_hash
+ end
+
end
end
View
7 lib/usergrid/core/resource.rb
@@ -59,10 +59,17 @@ def update_query(updates, query=nil, options={})
end
def entity
+ get unless response
response.entity
end
+ def entities
+ get unless response
+ response.entities
+ end
+
def collection
+ get unless response
Collection.new url, api_url, options, response
end
View
2  lib/usergrid/version.rb
@@ -1,3 +1,3 @@
module Usergrid
- VERSION = '0.0.4'
+ VERSION = '0.0.5'
end
View
39 spec/usergrid/core/application_spec.rb
@@ -10,10 +10,16 @@
delete_application @application
end
+ it "should be able to create a user using deprecated syntax" do
+ random = SecureRandom.hex
+ response = @application.create_user "username_#{random}", 'password'
+ response.entity.uuid.should_not be_nil
+ end
+
it "should be able to create, login, and delete a user" do
random = SecureRandom.hex
application = Usergrid::Application.new @application.url # create application resource that's not logged in
- response = application.create_user "username_#{random}", 'password'
+ response = application.create_user username: "username_#{random}", password: 'password'
entity = response.entity
application.login "username_#{random}", 'password'
begin
@@ -252,9 +258,7 @@
end
it "should be able to create a new collection and access it" do
- entities = (1..4).collect do |i|
- { name: "test_#{i}" }
- end
+ entities = (1..4).collect { |i| { name: "test_#{i}" } }
@application.create_entities 'tests', entities
response = @application['tests'].get
collection = response.collection
@@ -262,13 +266,32 @@
end
it "should be able to create a new collection via create_ method and access it" do
- entities = (1..4).collect do |i|
- { name: "test_#{i}" }
- end
+ entities = (1..4).collect { |i| { name: "test_#{i}" } }
@application.create_moretests entities
- response = @application['moretests'].get
+ response = @application['tests'].get
collection = response.collection
collection.size.should eq 4
end
+ it "should be able to access a collection without calling get" do
+ entities = (1..4).collect { |i| { name: "test_#{i}" } }
+ @application.create_entities 'tests', entities
+ collection = @application['tests'].collection
+ collection.size.should eq 4
+ end
+
+ it "should be able to access entities without calling get" do
+ entities = (1..4).collect { |i| { name: "test_#{i}" } }
+ @application.create_entities 'tests', entities
+ entities = @application['tests'].entities
+ entities.size.should eq 4
+ end
+
+ it "should be able to query using dot notation" do
+ entities = (1..4).collect { |i| { name: "test_#{i}" } }
+ @application.create_btests entities
+ entities = @application.btests("name = 'test_1'").entities
+ entities.size.should eq 1
+ end
+
end

0 comments on commit fd39fe7

Please sign in to comment.
Something went wrong with that request. Please try again.