Class: Singleplatform::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/singleplatform/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
# File 'lib/singleplatform/response.rb', line 7

def initialize(args)
  @code      = args[:code]
  @body      = args[:body]
  @next_page = args[:body].respond_to?(:next) ? args[:body].next : nil
  @origin    = args[:origin].to_s
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



5
6
7
# File 'lib/singleplatform/response.rb', line 5

def body
  @body
end

#codeObject

Returns the value of attribute code.



5
6
7
# File 'lib/singleplatform/response.rb', line 5

def code
  @code
end

#next_pageObject

Returns the value of attribute next_page.



5
6
7
# File 'lib/singleplatform/response.rb', line 5

def next_page
  @next_page
end

#originObject

Returns the value of attribute origin.



5
6
7
# File 'lib/singleplatform/response.rb', line 5

def origin
  @origin
end

Instance Method Details

#nextHashie::Mash

Note:

Will only work with Client#locations_updated_since and

An iterator for retrieving the next page of results from API response.

#photos_updated_since at this time.

Returns:

  • (Hashie::Mash)


21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/singleplatform/response.rb', line 21

def next
  return nil if next_page.nil? || next_page.empty?
  params = prepare_params(next_page)
  client = Singleplatform.new(
    client_id:     ENV['SINGLEPLATFORM_CLIENT_ID'],
    client_secret: ENV['SINGLEPLATFORM_CLIENT_SECRET']
  )
  new_page = client.public_send(
               origin.to_sym,
               params.delete('date').first, params
             )
  refresh(new_page)
end