Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added delete_query to collection and resource

  • Loading branch information...
commit dca9f945eeafc5dd3567c69626faf117aadc8a7c 1 parent 62de652
@theganyo authored
View
4 README.md
@@ -181,6 +181,10 @@ usergrid_iron/spec/spec_settings.yaml to match.)
## Release notes
+### 0.9.2
+* New features
+ 1. delete_query (batch delete by query)
+
### 0.9.1
* New features
1. may now login using credentials: application.login_credentials() or organization.login_credentials()
View
8 lib/usergrid/core/collection.rb
@@ -60,6 +60,14 @@ def update_query(updates, query=nil, options={})
end
# options: 'reversed', 'start', 'cursor', 'limit', 'permission'
+ def delete_query(query=nil, options={})
+ options = options.symbolize_keys
+ query_params = query ? options.merge({ql: query}) : options
+ self.delete({params: query_params })
+ self
+ end
+
+ # options: 'reversed', 'start', 'cursor', 'limit', 'permission'
def query(query=nil, options={})
options = options.symbolize_keys
query_params = query ? options.merge({ql: query}) : options
View
6 lib/usergrid/core/resource.rb
@@ -58,6 +58,12 @@ def update_query(updates, query=nil, options={})
put(updates, {params: options})
end
+ # options: 'reversed', 'start', 'cursor', 'limit', 'permission'
+ def delete_query(query=nil, options={})
+ options = options.merge({ql: query}) if query
+ delete({params: options})
+ end
+
def entity
get unless response
response.entity
View
2  lib/usergrid/version.rb
@@ -1,3 +1,3 @@
module Usergrid
- VERSION = '0.9.1'
+ VERSION = '0.9.2'
end
View
8 spec/usergrid/core/collection_spec.rb
@@ -78,6 +78,14 @@
entity.name.should eq @entity_data[4][:name]
end
+ it "should be able to delete based on a query" do
+ @collection.delete_query "select * where name = \'#{@entity_data[5][:name]}\'"
+ @collection.query
+ entity = @collection.detect { |e| e['name'] == "#{@entity_data[5][:name]}" }
+ entity.should be_nil
+ @entity_data.delete @entity_data[5]
+ end
+
it "should be able to iterate within the page" do
@collection.query
@collection.cursor.should_not be_nil
View
21 spec/usergrid/core/entity_spec.rb
@@ -52,4 +52,25 @@
Usergrid::Resource::RESERVED.each { |a| hash.should_not have_key(a) }
end
+ it "should be able to delete itself" do
+ user = create_random_user @application
+ name = user.name
+ user.delete
+ u = @application['users'].entities.detect {|e| e.name == "#{name}"}
+ u.should be_nil
+ end
+
+ it "should be able to update and delete by query" do
+ dog = (@application.create_dog name: 'Vex').entity
+
+ @application['dogs'].update_query({foo: 'bar'}, "select * where name = \'#{dog.name}\'")
+ dog.get
+ dog.foo.should eq('bar')
+
+ @application['dogs'].delete_query "select * where name = \'#{dog.name}\'"
+
+ dog = @application['dogs'].entities.detect {|e| e.name == "#{dog.name}"}
+ dog.should be_nil
+ end
+
end
View
2  usergrid_iron.gemspec
@@ -3,7 +3,7 @@ require File.expand_path('../lib/usergrid/version', __FILE__)
Gem::Specification.new do |gem|
gem.authors = ["Scott Ganyo"]
- gem.email = ["sganyo@apigee.com"]
+ gem.email = ["scott@ganyo.com"]
gem.description = %q{Low-level gem to access Usergrid / Apigee App Services}
gem.summary = %q{Usergrid_iron enables simple, low-level Ruby access to Apigee's App Services
(aka Usergrid) REST API with minimal dependencies.}

0 comments on commit dca9f94

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