Class: EBayEnterpriseAffiliateNetwork::APIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/ebay_enterprise_affiliate_network/api_response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ APIResponse

Returns a new instance of APIResponse.



5
6
7
8
9
10
# File 'lib/ebay_enterprise_affiliate_network/api_response.rb', line 5

def initialize(response)
  @request = response.request
  body = JSON.parse(response.body)
  @meta = RecursiveOpenStruct.new(body["meta"])
  @data = parse(body["data"])
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



3
4
5
# File 'lib/ebay_enterprise_affiliate_network/api_response.rb', line 3

def data
  @data
end

#metaObject (readonly)

Returns the value of attribute meta.



3
4
5
# File 'lib/ebay_enterprise_affiliate_network/api_response.rb', line 3

def meta
  @meta
end

#requestObject (readonly)

Returns the value of attribute request.



3
4
5
# File 'lib/ebay_enterprise_affiliate_network/api_response.rb', line 3

def request
  @request
end

Instance Method Details

#allObject



12
13
14
15
16
17
18
19
20
# File 'lib/ebay_enterprise_affiliate_network/api_response.rb', line 12

def all
  while meta.pagination.next
    uri = Addressable::URI.parse(meta.pagination.next.href)
    next_page_response = EBayEnterpriseAffiliateNetwork::Publisher.new.request(uri.origin + uri.path, uri.query_values)
    @meta = next_page_response.meta
    @data += next_page_response.data
  end
  @data
end