Module: Postmates::Response

Extended by:
Utils
Defined in:
lib/postmates/response.rb

Class Method Summary collapse

Methods included from Utils

timeify, urlify

Class Method Details

.build(body) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/postmates/response.rb', line 10

def build(body)
  kind = body['object'] || body['kind']
  case kind
  when 'list'
    body['data'].map { |del| Delivery.new(del) }.tap do |list|
      list.instance_variable_set(:@total_count, body['total_count'])
      list.instance_variable_set(:@next_href, urlify(body['next_href']))
      list.class.module_eval { attr_reader :total_count, :next_href }
    end
  when 'delivery'
    Delivery.new(body)
  when 'delivery_quote'
    Quote.new(body)
  end
end