Class: StoreApi::GooglePlay::Apps::Details

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

Overview

google play detail class

Constant Summary collapse

@@path =
'/store/apps/details'

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

initialize

Parameters:

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


22
23
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/store_api/google_play/apps/details.rb', line 22

def initialize(id,lang=nil,proxy=nil,header=nil)
  params = {'id' => id }
  if !lang.nil?
    params['hl'] = lang
  end
  begin
    html = get(StoreApi::GooglePlay::HOST,@@path,params,StoreApi::GooglePlay::HTTPS,proxy,header)
    doc = Nokogiri::HTML(html,nil,'utf-8')
    @id = id

    content_xpath = "id('body-content')"
    doc.xpath("#{content_xpath}//div[@class='details-info']").each do |node|
      # puts node.methods
      @title = node.css('.document-title').text.strip
      @cover_image = node.css('.cover-image').attribute('src').value
      @developer = node.css('.primary').text.strip
      @developer_url = node.css('.primary').attribute('href').value
      @category = node.css('.category').text.strip
      @category_url = node.css('.category').attribute('href').value
      @category_id = node.css('.category').attribute('href').value.split("/")[4]
      @badge_title = node.css('.badge-title').text.strip
      @price = node.xpath("//*[@class='price buy id-track-click']//*[@itemprop='price']/@content").text
    end

    thumbnails_xpath = "#{content_xpath}//div[@class='thumbnails']"
    @screenshot = doc.xpath("#{thumbnails_xpath}/img").map {|node| node.attribute('src').value }
    @video_url = doc.xpath("#{thumbnails_xpath}/span[@class='details-trailer']/span[@class='preview-overlay-container']/@data-video-url").text
    @description = doc.xpath("#{content_xpath}//div[@itemprop='description']").to_html
    @rating_score = doc.xpath("#{content_xpath}//div[@class='rating-box']//div[@class='score']").text
    rating_xpath = "#{content_xpath}//div[@class='rating-box']"
    @rating_value = doc.xpath("#{rating_xpath}//*[@itemprop='ratingValue']/@content").text
    @rating_count = doc.xpath("#{rating_xpath}//*[@itemprop='ratingCount']/@content").text

    @rating_map = {}
    doc.xpath("#{rating_xpath}//div[@class='rating-histogram']/div").each do |node|
      star_num = node.css(".bar-label").text.strip
      @rating_map[star_num.to_i] = node.css(".bar-number").text.gsub(',','')
    end

    @whatsnew = doc.xpath("#{content_xpath}//div[@class='details-section whatsnew']//div[@class='recent-change']").text
     = "#{content_xpath}//div[@class='details-section metadata']//div[@class='meta-info']"
    @date_published = doc.xpath("#{}//div[@itemprop='datePublished']").text
    @file_size = doc.xpath("#{}//div[@itemprop='fileSize']").text
    @file_size = !@file_size.nil? ? @file_size.strip : nil
    @downloads = doc.xpath("#{}//div[@itemprop='numDownloads']").text
    @downloads = !@downloads.nil? ? @downloads.strip : nil
    @software_version = doc.xpath("#{}//div[@itemprop='softwareVersion']").text
    @software_version = !@software_version.nil? ? @software_version.strip : nil
    @operating_system = doc.xpath("#{}//div[@itemprop='operatingSystems']").text
    @operating_system = !@operating_system.nil? ? @operating_system.strip : nil
    @content_rating = doc.xpath("#{}//div[@itemprop='contentRating']").text
    @content_rating = !@content_rating.nil? ? @content_rating.strip : nil
    @developer_address = doc.xpath("#{}//div[@class='content physical-address']").text
    @developer_address = !@developer_address.nil? ? @developer_address.strip : nil
    @developer_links = []
    doc.xpath("#{content_xpath}//div[@class='details-section metadata']//div[@class='content contains-text-link']/a[@class='dev-link']").each do |node|
      @developer_links.push({'text' => node.text,'link' => node.attribute('href').value})
    end
  rescue => e
    puts e
  end
end

Instance Attribute Details

#badge_titleObject

Returns the value of attribute badge_title.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def badge_title
  @badge_title
end

#categoryObject

Returns the value of attribute category.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def category
  @category
end

#category_idObject

Returns the value of attribute category_id.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def category_id
  @category_id
end

#category_urlObject

Returns the value of attribute category_url.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def category_url
  @category_url
end

#content_ratingObject

Returns the value of attribute content_rating.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def content_rating
  @content_rating
end

#cover_imageObject

Returns the value of attribute cover_image.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def cover_image
  @cover_image
end

#date_publishedObject

Returns the value of attribute date_published.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def date_published
  @date_published
end

#descriptionObject

Returns the value of attribute description.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def description
  @description
end

#developerObject

Returns the value of attribute developer.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def developer
  @developer
end

#developer_addressObject

Returns the value of attribute developer_address.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def developer_address
  @developer_address
end

Returns the value of attribute developer_links.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def developer_links
  @developer_links
end

#developer_urlObject

Returns the value of attribute developer_url.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def developer_url
  @developer_url
end

#downloadsObject

Returns the value of attribute downloads.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def downloads
  @downloads
end

#file_sizeObject

Returns the value of attribute file_size.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def file_size
  @file_size
end

#google_plusObject

Returns the value of attribute google_plus.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def google_plus
  @google_plus
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def id
  @id
end

#operating_systemObject

Returns the value of attribute operating_system.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def operating_system
  @operating_system
end

#priceObject

Returns the value of attribute price.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def price
  @price
end

#rating_countObject

Returns the value of attribute rating_count.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def rating_count
  @rating_count
end

#rating_mapObject

Returns the value of attribute rating_map.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def rating_map
  @rating_map
end

#rating_scoreObject

Returns the value of attribute rating_score.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def rating_score
  @rating_score
end

#rating_valueObject

Returns the value of attribute rating_value.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def rating_value
  @rating_value
end

#screenshotObject

Returns the value of attribute screenshot.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def screenshot
  @screenshot
end

#software_versionObject

Returns the value of attribute software_version.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def software_version
  @software_version
end

#titleObject

Returns the value of attribute title.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def title
  @title
end

#video_urlObject

Returns the value of attribute video_url.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def video_url
  @video_url
end

#whatsnewObject

Returns the value of attribute whatsnew.



11
12
13
# File 'lib/store_api/google_play/apps/details.rb', line 11

def whatsnew
  @whatsnew
end