Class: Parse::Batch
- Inherits:
-
Object
- Object
- Parse::Batch
- Defined in:
- lib/parse/batch.rb
Overview
Issue batch operations parseplatform.github.io/docs/rest/guide/#batch-operations
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#requests ⇒ Object
readonly
Returns the value of attribute requests.
Instance Method Summary collapse
- #add_request(request) ⇒ Object
- #class_uri(*args) ⇒ Object
- #create_object(object) ⇒ Object
- #delete_object(object) ⇒ Object
-
#initialize(client = nil) ⇒ Batch
constructor
A new instance of Batch.
- #run! ⇒ Object
- #update_object(object) ⇒ Object
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
7 8 9 |
# File 'lib/parse/batch.rb', line 7 def client @client end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
6 7 8 |
# File 'lib/parse/batch.rb', line 6 def requests @requests end |
Instance Method Details
#add_request(request) ⇒ Object
14 15 16 |
# File 'lib/parse/batch.rb', line 14 def add_request(request) @requests << request end |
#class_uri(*args) ⇒ Object
37 38 39 |
# File 'lib/parse/batch.rb', line 37 def class_uri(*args) ::File.join(client.path, Parse::Protocol.class_uri(*args)) end |
#create_object(object) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/parse/batch.rb', line 18 def create_object(object) method = 'POST' path = class_uri(object.class_name) body = object.safe_hash add_request('method' => method, 'path' => path, 'body' => body) end |
#delete_object(object) ⇒ Object
32 33 34 35 |
# File 'lib/parse/batch.rb', line 32 def delete_object(object) add_request( 'method' => 'DELETE', 'path' => class_uri(object.class_name, object.id)) end |
#run! ⇒ Object
41 42 43 44 45 |
# File 'lib/parse/batch.rb', line 41 def run! uri = Parse::Protocol.batch_request_uri body = { requests: @requests }.to_json @client.request(uri, :post, body) end |
#update_object(object) ⇒ Object
25 26 27 28 29 30 |
# File 'lib/parse/batch.rb', line 25 def update_object(object) method = 'PUT' path = class_uri(object.class_name, object.id) body = object.safe_hash add_request('method' => method, 'path' => path, 'body' => body) end |