Class: StoreApi::AppStore::Apps::Ranking

Inherits:
Object
  • Object
show all
Includes:
Request
Defined in:
lib/store_api/app_store/apps/ranking.rb

Constant Summary

Constants included from Request

Request::TIME_OUT

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Request

#get, #post, #request

Constructor Details

#initialize(ranking_type = nil, category_id = nil, country = nil, limit = 10, proxy = nil, header = nil) ⇒ Ranking

initialize

Parameters:

  • ranking_type (String) (defaults to: nil)
  • category_id (String) (defaults to: nil)
  • country (String) (defaults to: nil)
  • limit (Integer) (defaults to: 10)
  • proxy (Hash) (defaults to: nil)
  • header (Hash) (defaults to: nil)


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/store_api/app_store/apps/ranking.rb', line 19

def initialize(ranking_type=nil, category_id=nil, country=nil, limit=10, proxy=nil, header=nil)
  if category_id.nil?
    @@path = "/#{country}/rss/#{ranking_type}/limit=#{limit}/json"
  else
    @@path = "/#{country}/rss/#{ranking_type}/limit=#{limit}/genre=#{category_id}/json"
  end

  @topchart = []
  feed_data = JSON.load(get(StoreApi::AppStore::HOST, @@path,
    nil, StoreApi::AppStore::HTTPS, proxy, header))['feed']['entry']

  feed_data.each.with_index(1) do |entry, rank|
    @topchart.push({
      :id => entry['id']['attributes']['im:id'],
      :title => entry['im:name']['label'],
      :bundle_id => entry['id']['attributes']['im:bundleId'],
      :category_id => entry['category']['attributes']['im:id'],
      :category => entry['category']['attributes']['label'],
      :cover_image => entry['im:image'][0]['label'],
      :price => entry['im:price']['attributes']['amount'],
      :developer => entry['im:artist']['label'],
      :release_date => entry['im:releaseDate']['label'],
      :rank => rank
    })
  end
end

Instance Attribute Details

#topchartObject

Returns the value of attribute topchart.



9
10
11
# File 'lib/store_api/app_store/apps/ranking.rb', line 9

def topchart
  @topchart
end