Class: Parse::Batch

Inherits:
Object
  • Object
show all
Defined in:
lib/parse/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBatch

Returns a new instance of Batch.



7
8
9
# File 'lib/parse/batch.rb', line 7

def initialize
  @requests ||= []
end

Instance Attribute Details

#requestsObject (readonly)

Returns the value of attribute requests.



5
6
7
# File 'lib/parse/batch.rb', line 5

def requests
  @requests
end

Instance Method Details

#add_request(request) ⇒ Object



11
12
13
# File 'lib/parse/batch.rb', line 11

def add_request(request)
  @requests << request
end

#create_object(object) ⇒ Object



15
16
17
18
19
20
21
22
23
24
# File 'lib/parse/batch.rb', line 15

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



37
38
39
40
41
42
# File 'lib/parse/batch.rb', line 37

def delete_object(object)
  add_request({
    "method" => "DELETE",
    "path" => Parse::Protocol.class_uri(object.class_name, object.id)
  })
end

#run!Object



44
45
46
47
48
# File 'lib/parse/batch.rb', line 44

def run!
  uri = Parse::Protocol.batch_request_uri
  body = {:requests => @requests}.to_json
  Parse.client.request(uri, :post, body)
end

#update_object(object) ⇒ Object



26
27
28
29
30
31
32
33
34
35
# File 'lib/parse/batch.rb', line 26

def update_object(object)
  method = "PUT"
  path = Parse::Protocol.class_uri(object.class_name, object.id)
  body = object.safe_hash
  add_request({
    "method" => method,
    "path" => path,
    "body" => body
  })
end