Class: RakutenApi::ItemRanking::Response

Inherits:
Base::Response show all
Defined in:
lib/rakuten_api/item_ranking/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 = {}) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/rakuten_api/item_ranking/response.rb', line 10

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

Instance Attribute Details

#last_build_dateObject (readonly)

Returns the value of attribute last_build_date.



7
8
9
# File 'lib/rakuten_api/item_ranking/response.rb', line 7

def last_build_date
  @last_build_date
end

#pageObject (readonly)

Returns the value of attribute page.



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

def page
  @page
end

#titleObject (readonly)

Returns the value of attribute title.



6
7
8
# File 'lib/rakuten_api/item_ranking/response.rb', line 6

def title
  @title
end

Instance Method Details

#new_requestObject



31
32
33
34
35
36
37
# File 'lib/rakuten_api/item_ranking/response.rb', line 31

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

#next_rankingObject



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

def next_ranking
  @request_params['page'] = @page + 1
  new_request
end

#parse_bodyObject



39
40
41
42
43
44
# File 'lib/rakuten_api/item_ranking/response.rb', line 39

def parse_body
  @title = @body['title']
  @last_build_date = DateTime.rfc2822(@body['lastBuildDate']) rescue nil
  @page = @request_params['page'] if @request_params.is_a? Hash
  @page ||= 1
end

#prev?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/rakuten_api/item_ranking/response.rb', line 21

def prev?
  @page > 1
end

#prev_rankingObject



25
26
27
28
29
# File 'lib/rakuten_api/item_ranking/response.rb', line 25

def prev_ranking
  return nil unless prev?
  @request_params['page'] = @page - 1
  new_request
end

#simple_mappingObject



46
47
48
49
50
51
52
53
54
# File 'lib/rakuten_api/item_ranking/response.rb', line 46

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