google_play_search 0.0.24 → 0.0.25

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 2edbb46e631962a5e423c71f959f1e9e3fbb630c
4
- data.tar.gz: b833a2829055bca317ced1307878ba6e6aca8494
2
+ SHA256:
3
+ metadata.gz: c24b22dfdda221dc7ea339cf1ce3c48c67bbcdf9742de27e29d64a9d20312ed6
4
+ data.tar.gz: 3a55d8a6a4190c17b64b774501de9f6514a4f3f23f5c107b1e403f756b3226f6
5
5
  SHA512:
6
- metadata.gz: 1c2ff3beab4ecbbc17eca8f597da41c1ca7cc5292d5bff84f815f6de0579d465e8626864f2fb8cfad4cf466b4b70cad842e5c16362b71073ccea73e63cdfc103
7
- data.tar.gz: c25aa4bc08231e747adbbfa383364b023d7988603599658b42984bf53b4b51ebe20a21e9452f09b339095fd2a157a0801df58186e7779a200d1a7b4ca1630418
6
+ metadata.gz: e5cb795b237bf3b1ff34054ddf1add01becc579171b9f04604c0e19e5151fff113b6a33b65c506891cfa85287519c78b2eac1534a12da92a31567f797d2e839a
7
+ data.tar.gz: 70819cf4e15cff9bc2eda06c2b7e22ec86284cd98bf92ae0463b4627b2b4fbad0f6f57acb54a66cea07cd6630e6551fd05a40637ce4aaa4971f032ea6aa80e74
@@ -1,5 +1,6 @@
1
- require File.expand_path(File.dirname(__FILE__) + '/app')
2
- require File.expand_path(File.dirname(__FILE__) + '/utils')
1
+ require File.expand_path(File.dirname(__FILE__) + "/app")
2
+ require File.expand_path(File.dirname(__FILE__) + "/utils")
3
+ require "json"
3
4
 
4
5
  module GooglePlaySearch
5
6
  class AppParser
@@ -8,99 +9,33 @@ module GooglePlaySearch
8
9
  SEARCH_APP_URL_END_SUFF = "&feature=search_result"
9
10
 
10
11
  def initialize(content)
11
- @doc = Nokogiri::HTML(content)
12
+ @content = content
12
13
  end
14
+
13
15
  def parse
14
16
  app_search_result_list = []
15
- if @doc.css("div.card-list div.card").size > 0
16
- @doc.css("div.card-list div.card").each do |app_content|
17
- app_search_result_list << create_app(app_content)
18
- end
19
- else
20
- @doc.css("li.z-last-child div.snippet").each do |app_content|
21
- app_search_result_list << create_app(app_content)
22
- end
17
+ content = @content.match(
18
+ />AF_initDataCallback\({key: 'ds:3'.*{return(?<data>[\s\S]*?)}}\)\;<\/script/
19
+ )[:data]
20
+ data = JSON.parse(content)
21
+ data[0][1][0][0][0].each do |app|
22
+ app_search_result_list << create_app(app)
23
23
  end
24
24
  app_search_result_list
25
25
  end
26
26
 
27
27
  private
28
- def get_url(app_content)
29
- url = $GOOGLE_PLAY_STORE_BASE_URL + app_content.css("a.card-click-target").first['href']
30
- if url.end_with?(SEARCH_APP_URL_END_SUFF)
31
- url = url[0..-1* (SEARCH_APP_URL_END_SUFF.size + 1)]
32
- end
33
- url
34
- end
35
-
36
- def get_logo_url(app_content)
37
- add_http_prefix(app_content.css("img.cover-image").first['src'])
38
- end
39
-
40
- def get_name(app_content)
41
- app_content.css("a.title").first.content.strip
42
- end
43
-
44
- def get_developer(app_content)
45
- deleloper_contents_list = app_content.css("div.subtitle-container a.subtitle")
46
- if deleloper_contents_list && deleloper_contents_list.size > 0
47
- return deleloper_contents_list.first.content
48
- else
49
- deleloper_contents_single = app_content.css("div.details span.attribution a")
50
- if deleloper_contents_single && deleloper_contents_single.size > 0
51
- return deleloper_contents_single.first.content
52
- end
53
- end
54
- return ""
55
- end
56
-
57
- def get_category(app_content)
58
- category_contents = app_content.css("div.attribution-category span.category a")
59
- if category_contents && category_contents.size>0
60
- return category_contents.first.content
61
- end
62
- return ""
63
- end
64
-
65
- def get_short_description(app_content)
66
- description_contents = app_content.css("div.description")
67
- if description_contents && description_contents.size > 0
68
- return description_contents.first.content.strip
69
- end
70
- return ""
71
- end
72
-
73
- def get_app_rating(app_content)
74
- ratings = app_content.css("div.current-rating")
75
- if ratings && ratings.first
76
- rating_str = ratings.first['style']
77
- unless rating_str.empty?
78
- return rating_str[/\d+\.?\d?/].to_f / 100 * 5
79
- end
80
- return 0
81
- end
82
- end
83
-
84
- def get_app_price(app_content)
85
- prices = app_content.css("span.price-container button.price span")
86
- if prices and prices.first
87
- if match = prices.first.content.match(/(.[0-9]*\.[0-9]+|[0-9]+)/)
88
- return match[1]
89
- end
90
- end
91
- return "0"
92
- end
93
28
 
94
- def create_app(app_content)
29
+ def create_app(app_json)
95
30
  app = App.new
96
- app.url = get_url app_content
97
- app.id = app.url[app.url.index("?id=")+4..-1]
98
- app.name = get_name app_content
99
- app.price = get_app_price app_content
100
- app.developer = get_developer app_content
101
- app.logo_url = get_logo_url app_content
102
- app.short_description = get_short_description app_content
103
- app.rating = get_app_rating app_content
31
+ app.url = "https://play.google.com" + app_json[9][4][2]
32
+ app.id = app_json[12][0]
33
+ app.name = app_json[2]
34
+ app.price = app_json[7][0][3][2][1][0][2] if app_json[7].size > 0 && app_json[7][0][3]
35
+ app.developer = app_json[4][0][0][0]
36
+ app.logo_url = app_json[1][1][0][3][2]
37
+ app.short_description = app_json[4][1][1][1][1]
38
+ app.rating = app_json[6][0][2][1][0] if app_json[6].size > 0
104
39
  return app
105
40
  end
106
41
  end
@@ -1,7 +1,8 @@
1
- require 'rubygems'
2
- require 'nokogiri'
3
- require 'cgi'
4
- require File.expand_path(File.dirname(__FILE__) + '/app_parser')
1
+ require "rubygems"
2
+ require "nokogiri"
3
+ require "cgi"
4
+ require "httpclient"
5
+ require File.expand_path(File.dirname(__FILE__) + "/app_parser")
5
6
 
6
7
  module GooglePlaySearch
7
8
  class Search
@@ -11,10 +12,10 @@ module GooglePlaySearch
11
12
 
12
13
  GOOGLE_PLAY_BASE_SEARCH_URL = $GOOGLE_PLAY_STORE_BASE_URL + "/store/search"
13
14
 
14
- DEFAULT_SEARCH_CONDITION = {:language => "en",
15
- :category => "apps",
16
- :price => "0",
17
- :rating => "0"}
15
+ DEFAULT_SEARCH_CONDITION = { :language => "en",
16
+ :category => "apps",
17
+ :price => "0",
18
+ :rating => "0" }
18
19
 
19
20
  def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
20
21
  @search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
@@ -22,10 +23,9 @@ module GooglePlaySearch
22
23
  @current_page = 1
23
24
  end
24
25
 
25
- def search(keyword, options={})
26
+ def search(keyword, options = {})
26
27
  @keyword = keyword
27
28
  page = HTTPClient.new.get(GOOGLE_PLAY_BASE_SEARCH_URL, query_params).body
28
- get_next_page_token(page)
29
29
  AppParser.new(page).parse
30
30
  end
31
31
 
@@ -35,18 +35,19 @@ module GooglePlaySearch
35
35
  end
36
36
 
37
37
  private
38
+
38
39
  def query_params
39
40
  params = {
40
- 'q' => @keyword,
41
- 'c' => @search_condition[:category],
42
- 'hl' => @search_condition[:language],
43
- 'price' => @search_condition[:price],
44
- 'rating' => @search_condition[:rating],
45
- 'start' => 0,
46
- 'num' => 0
41
+ "q" => @keyword,
42
+ "c" => @search_condition[:category],
43
+ "hl" => @search_condition[:language],
44
+ "price" => @search_condition[:price],
45
+ "rating" => @search_condition[:rating],
46
+ "start" => 0,
47
+ "num" => 0,
47
48
  }
48
49
  if @next_page_token
49
- params['pagTok'] = @next_page_token
50
+ params["pagTok"] = @next_page_token
50
51
  end
51
52
  params
52
53
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: google_play_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.24
4
+ version: 0.0.25
5
5
  platform: ruby
6
6
  authors:
7
7
  - Grant Chen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-07-06 00:00:00.000000000 Z
11
+ date: 2020-01-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -125,8 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
125
125
  - !ruby/object:Gem::Version
126
126
  version: '0'
127
127
  requirements: []
128
- rubyforge_project:
129
- rubygems_version: 2.5.1
128
+ rubygems_version: 3.0.3
130
129
  signing_key:
131
130
  specification_version: 4
132
131
  summary: google play market search