class Singleplatform::Response
Attributes
body[RW]
code[RW]
next_page[RW]
origin[RW]
Public Class Methods
new(args)
click to toggle source
# 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
Public Instance Methods
next()
click to toggle source
An iterator for retrieving the next page of results from API response.
@note Will only work with Client#locations_updated_since
and photos_updated_since at this time.
@return [Hashie::Mash]
# 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
Private Instance Methods
parse_params(url)
click to toggle source
Take any given URL and parse its query params.
@param url [String] @return [Hash]
# File lib/singleplatform/response.rb, line 52 def parse_params(url) CGI::parse(url.split('?')[-1]) end
prepare_params(url)
click to toggle source
Include additional params required for accessing API
@return [Hash]
# File lib/singleplatform/response.rb, line 59 def prepare_params(url) params = parse_params(url) params['client'] = ENV['SINGLEPLATFORM_CLIENT_ID'] params end
refresh(response)
click to toggle source
Update Response
instance variables
@param [Singleplatform::Response] @return [Singleplatform::Response]
# File lib/singleplatform/response.rb, line 41 def refresh(response) @code = response.code @body = response.body @next_page = response.next_page response end