Class: Ebay::Finding::Api::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/ebay/finding/api/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key_name, response) ⇒ Response

Returns a new instance of Response.



5
6
7
8
# File 'lib/ebay/finding/api/response.rb', line 5

def initialize(key_name, response)
  @key_name = key_name
  @response = response
end

Instance Attribute Details

#responseObject (readonly)

Returns the value of attribute response.



3
4
5
# File 'lib/ebay/finding/api/response.rb', line 3

def response
  @response
end

Instance Method Details

#itemsObject



10
11
12
13
14
15
16
17
18
# File 'lib/ebay/finding/api/response.rb', line 10

def items
  return [] unless success?

  result = JSON.parse(@response.body)["#{@key_name}Response"].first["searchResult"].first

  return [] if result["@count"] === "0"

  @items ||= result["item"]
end

#success?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/ebay/finding/api/response.rb', line 20

def success?
  @response.success?
end