Class: Parse::BatchHttpClient

Inherits:
HttpClient show all
Defined in:
lib/parse/batch_http_client.rb

Instance Attribute Summary collapse

Attributes inherited from HttpClient

#host

Instance Method Summary collapse

Constructor Details

#initialize(host) ⇒ BatchHttpClient

Returns a new instance of BatchHttpClient.



5
6
7
8
9
# File 'lib/parse/batch_http_client.rb', line 5

def initialize host
  @host = host
  @requests = []
  @after_blocks = []
end

Instance Attribute Details

#after_blocksObject

Returns the value of attribute after_blocks.



3
4
5
# File 'lib/parse/batch_http_client.rb', line 3

def after_blocks
  @after_blocks
end

#requestsObject

Returns the value of attribute requests.



3
4
5
# File 'lib/parse/batch_http_client.rb', line 3

def requests
  @requests
end

Instance Method Details

#request(method, endpoint, headers = {}, body = nil, &block) ⇒ Object



11
12
13
14
15
16
17
18
19
20
# File 'lib/parse/batch_http_client.rb', line 11

def request method, endpoint, headers={}, body=nil, &block
  raise 'find cannot be in a batch request.' if method.to_s.upcase == 'GET'

  @after_blocks << block
  @requests << {
    "method" => method.to_s.upcase,
    "path" => endpoint,
    "body" => JSON.parse(body) # TODO: ??
  }
end