class LsLinkdirectAPI::APIResponse
Attributes
data[R]
request[R]
Public Class Methods
new(response, response_name, params)
click to toggle source
# File lib/ls_linkdirect_api/api_response.rb, line 7 def initialize(response, response_name, params) @request = response.request @response_name = response_name @params = params result = response[ "get#{response_name}Response" ] @data = parse(result["return"]) end
Public Instance Methods
all()
click to toggle source
# File lib/ls_linkdirect_api/api_response.rb, line 15 def all get_next_page = true while get_next_page cls = Object.const_get('LsLinkdirectAPI').const_get(@response_name) @params[:page] += 1 next_page_response = cls.new.get(@params) @data += next_page_response.data get_next_page = false if next_page_response.data == [] end @data end
Private Instance Methods
parse(raw_data)
click to toggle source
# File lib/ls_linkdirect_api/api_response.rb, line 29 def parse(raw_data) data = [] data = [RecursiveOpenStruct.new(raw_data)] if raw_data.is_a?(Hash) # If we got exactly one result, put it in an array. raw_data.each { |i| data << RecursiveOpenStruct.new(i) } if raw_data.is_a?(Array) data end