class StoreApi::GooglePlay::Apps::Ranking
google play ranking class¶ ↑
@note specification
- top path : '/store/apps/collection/ranking_type' - category path : '/store/apps/category/category_id/collection/ranking_type' - post data start: min 0 max 480 num:60
Attributes
topchart[RW]
Public Class Methods
new(ranking_type=nil,category_id=nil,lang=nil,proxy=nil,header=nil)
click to toggle source
initialize @param [String] ranking_type @param [String] category_id @param [String] lang @param [Hash] proxy @param [Hash] header @see StoreApi::GooglePlay::RANKING_TYPE_LIST @see StoreApi::GooglePlay::CATEGORY_ID_LIST
# File lib/store_api/google_play/apps/ranking.rb, line 24 def initialize(ranking_type=nil,category_id=nil,lang=nil,proxy=nil,header=nil) params = {} if !lang.nil? params['hl'] = lang end if category_id.nil? @@path = "/store/apps/collection/#{ranking_type}" else @@path = "/store/apps/category/#{category_id}/collection/#{ranking_type}" end @topchart = [] num = 60 (0..8).each do |start| begin params['start'] = start*60 params['num'] = num html = post(StoreApi::GooglePlay::HOST,@@path,params,StoreApi::GooglePlay::HTTPS,proxy,header) doc = Nokogiri::HTML(html,nil,'utf-8') parse(doc) rescue => e puts e.backtrace puts e.message break end end end
Public Instance Methods
parse(doc)
click to toggle source
# File lib/store_api/google_play/apps/ranking.rb, line 51 def parse(doc) doc.css('.card-list > .card').each do |node| rank = node.css('.title').text.split('.')[0].strip if (/^[+-]?[0-9]+$/ =~ rank) rank = rank.to_i else rank = nil end @topchart.push( {:id => node.css('.preview-overlay-container')[0]['data-docid'], :title => node.css('.title')[0]['title'].strip, :cover_image => node.css('.cover-image').attribute('src').value, :details_url => node.css('.title').attribute('href').value, :developer => node.css('.subtitle').attribute('title').value.strip, :price => node.css('.display-price')[0].text, :rank => rank} ) end end