Class: RakutenApi::ItemSearch::Response

Inherits:
Base::Response show all
Defined in:
lib/rakuten_api/item_search/response.rb

Instance Attribute Summary collapse

Attributes inherited from Base::Response

#body, #status

Instance Method Summary collapse

Methods inherited from Base::Response

#error?, #error_message, #success?

Constructor Details

#initialize(faraday_response = nil, params = nil) ⇒ Response

Returns a new instance of Response.



16
17
18
19
20
# File 'lib/rakuten_api/item_search/response.rb', line 16

def initialize(faraday_response = nil, params = nil)
  super(faraday_response)
  parse_body(@body)
  @request_params = params
end

Instance Attribute Details

#carrierObject (readonly)

Returns the value of attribute carrier.



12
13
14
# File 'lib/rakuten_api/item_search/response.rb', line 12

def carrier
  @carrier
end

#countObject (readonly)

Returns the value of attribute count.



9
10
11
# File 'lib/rakuten_api/item_search/response.rb', line 9

def count
  @count
end

#firstObject (readonly)

Returns the value of attribute first.



10
11
12
# File 'lib/rakuten_api/item_search/response.rb', line 10

def first
  @first
end

#hitsObject (readonly)

Returns the value of attribute hits.



8
9
10
# File 'lib/rakuten_api/item_search/response.rb', line 8

def hits
  @hits
end

#lastObject (readonly)

Returns the value of attribute last.



11
12
13
# File 'lib/rakuten_api/item_search/response.rb', line 11

def last
  @last
end

#pageObject (readonly)

Returns the value of attribute page.



14
15
16
# File 'lib/rakuten_api/item_search/response.rb', line 14

def page
  @page
end

#page_countObject (readonly)

Returns the value of attribute page_count.



13
14
15
# File 'lib/rakuten_api/item_search/response.rb', line 13

def page_count
  @page_count
end

Instance Method Details

#get_next_pageObject



30
31
32
33
34
# File 'lib/rakuten_api/item_search/response.rb', line 30

def get_next_page
  nil unless next?
  @request_params[:page] = @page + 1
  new_request
end

#get_prev_pageObject



36
37
38
39
40
# File 'lib/rakuten_api/item_search/response.rb', line 36

def get_prev_page
  nil unless prev?
  @request_params[:page] = @page - 1
  new_request
end

#new_requestObject



42
43
44
45
46
47
48
# File 'lib/rakuten_api/item_search/response.rb', line 42

def new_request
  Client.new do |params|
    @request_params.each_pair do |k, v|
      params.add_param k, v
    end
  end.request
end

#next?Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/rakuten_api/item_search/response.rb', line 22

def next?
  @page < @page_count
end

#parse_body(data) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'lib/rakuten_api/item_search/response.rb', line 50

def parse_body(data)
  @count = data['count']
  @page = data['page']
  @first = data['first']
  @last = data['last']
  @hits = data['hits']
  @carrier = data['carrier']
  @page_count = data['pageCount']
end

#prev?Boolean

Returns:

  • (Boolean)


26
27
28
# File 'lib/rakuten_api/item_search/response.rb', line 26

def prev?
  @page > 1
end

#simple_mappingObject



60
61
62
63
64
65
66
67
68
# File 'lib/rakuten_api/item_search/response.rb', line 60

def simple_mapping
  return [] unless @body.key? "Items"
  [].tap do |result|
    @body["Items"].each do |f|
      next unless f.include? 'Item'
      result << Model.from_hash(f['Item'])
    end
  end
end