Class: StoreApi::GooglePlay::Apps::Ranking

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

Overview

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

google play ranking class

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, lang = nil, proxy = nil, header = nil) ⇒ Ranking

initialize

Parameters:

  • ranking_type (String) (defaults to: nil)
  • category_id (String) (defaults to: nil)
  • lang (String) (defaults to: nil)
  • proxy (Hash) (defaults to: nil)
  • header (Hash) (defaults to: nil)

See Also:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# 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

Instance Attribute Details

#topchartObject

Returns the value of attribute topchart.



14
15
16
# File 'lib/store_api/google_play/apps/ranking.rb', line 14

def topchart
  @topchart
end

Instance Method Details

#parse(doc) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# 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