Class: Parse::Batch
- Inherits:
-
Object
- Object
- Parse::Batch
- Defined in:
- lib/parse/batch.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
- #add_request(request) ⇒ Object
- #create_object(object) ⇒ Object
- #delete_object(object) ⇒ Object
-
#initialize(client = Parse.client) ⇒ Batch
constructor
A new instance of Batch.
- #run! ⇒ Object
- #update_object(object) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
5 6 7 |
# File 'lib/parse/batch.rb', line 5 def client @client end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
4 5 6 |
# File 'lib/parse/batch.rb', line 4 def requests @requests end |
Instance Method Details
#add_request(request) ⇒ Object
12 13 14 |
# File 'lib/parse/batch.rb', line 12 def add_request(request) @requests << request end |
#create_object(object) ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/parse/batch.rb', line 16 def create_object(object) method = "POST" path = Parse::Protocol.class_uri(object.class_name) body = object.safe_hash add_request({ "method" => method, "path" => path, "body" => body }) end |
#delete_object(object) ⇒ Object
38 39 40 41 42 43 |
# File 'lib/parse/batch.rb', line 38 def delete_object(object) add_request({ "method" => "DELETE", "path" => Parse::Protocol.class_uri(object.class_name, object.id) }) end |
#run! ⇒ Object
45 46 47 48 49 |
# File 'lib/parse/batch.rb', line 45 def run! uri = Parse::Protocol.batch_request_uri body = {:requests => @requests}.to_json @client.request(uri, :post, body) end |