class LC::Batch

Attributes

client[R]
requests[R]

Public Class Methods

new(client = LC.client) click to toggle source
# File lib/leancloud/batch.rb, line 6
def initialize(client = LC.client)
  @client = client
  @requests ||= []
end

Public Instance Methods

add_request(request) click to toggle source
# File lib/leancloud/batch.rb, line 11
def add_request(request)
  @requests << request
end
create_object(object) click to toggle source
# File lib/leancloud/batch.rb, line 15
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) click to toggle source
# File lib/leancloud/batch.rb, line 37
def delete_object(object)
  add_request({
    "method" => "DELETE",
    "path" => LC::Protocol.class_uri(object.class_name, object.id)
  })
end
run!() click to toggle source
# File lib/leancloud/batch.rb, line 44
def run!
  uri = LC::Protocol.batch_request_uri
  body = {:requests => @requests}.to_json
  @client.request(uri, :post, body)
end
update_object(object) click to toggle source
# File lib/leancloud/batch.rb, line 26
def update_object(object)
  method = "PUT"
  path = LC::Protocol.class_uri(object.class_name, object.id)
  body = object.safe_hash
  add_request({
    "method" => method,
    "path" => path,
    "body" => body
  })
end