Class: LC::Batch
- Inherits:
-
Object
- Object
- LC::Batch
- Defined in:
- lib/leancloud/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 = LC.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/leancloud/batch.rb', line 5 def client @client end |
#requests ⇒ Object (readonly)
Returns the value of attribute requests.
4 5 6 |
# File 'lib/leancloud/batch.rb', line 4 def requests @requests end |
Instance Method Details
#add_request(request) ⇒ Object
12 13 14 |
# File 'lib/leancloud/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/leancloud/batch.rb', line 16 def create_object(object) method = "POST" path = LC::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/leancloud/batch.rb', line 38 def delete_object(object) add_request({ "method" => "DELETE", "path" => LC::Protocol.class_uri(object.class_name, object.id) }) end |
#run! ⇒ Object
45 46 47 48 49 |
# File 'lib/leancloud/batch.rb', line 45 def run! uri = LC::Protocol.batch_request_uri body = {:requests => @requests}.to_json @client.request(uri, :post, body) end |