google_play_search 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b4166b35ed26f6d6658a42b8de2e8b152788143f
4
+ data.tar.gz: ab3e879355c59c5c9247cea891af6899a0babb44
5
+ SHA512:
6
+ metadata.gz: 2c64bf7eaa2d536f714293213015e50a150f26204b79c46e1ded793eb6c00af6088b5b10f3ad2127e256575169972140d0970852cd1ae625a5384fffc9efcb48
7
+ data.tar.gz: 225884c444c6c50b64c33ec81bab2bfd1405527d441c1387c8a23eae565e3cb2e241f9d1ce8a8900152ce447a908b0f30dfee1389f88cbdd185d94f88d1f4f3c
@@ -1,5 +1,5 @@
1
1
  module GooglePlaySearch
2
- class App
3
- attr_accessor :id, :name, :url, :developer, :category, :logo_url, :short_description, :rating, :reviews
4
- end
2
+ class App
3
+ attr_accessor :id, :name, :url, :developer, :category, :logo_url, :short_description, :rating, :reviews, :price
4
+ end
5
5
  end
@@ -1,58 +1,71 @@
1
1
  require File.expand_path(File.dirname(__FILE__) + '/app')
2
2
 
3
3
  module GooglePlaySearch
4
- class AppParser
5
- SEARCH_APP_URL_END_SUFF = "&feature=search_result"
4
+ class AppParser
5
+ SEARCH_APP_URL_END_SUFF = "&feature=search_result"
6
6
 
7
- def initialize(content)
8
- @doc = Nokogiri::HTML(content)
9
- end
10
- def parse
11
- app_search_result_list = []
12
- @doc.css("li.search-results-item div.snippet").each do |app_content|
13
- app = App.new
14
- app.url = get_url app_content
15
- app.id = app.url[app.url.index("?id=")+4..-1]
16
- app.name = get_name app_content
17
- app.developer = get_developer app_content
18
- app.category = get_category app_content
19
- app.logo_url = get_logo_url app_content
20
- app.short_description = get_short_description app_content
21
- app.rating = get_app_rating app_content
22
- app.reviews = get_app_reviews app_content
23
- app_search_result_list << app
24
- end
25
- app_search_result_list
26
- end
7
+ def initialize(content)
8
+ @doc = Nokogiri::HTML(content)
9
+ end
10
+ def parse
11
+ app_search_result_list = []
12
+ if @doc.css("li.search-results-item div.snippet").size > 0
13
+ @doc.css("li.search-results-item div.snippet").each do |app_content|
14
+ app_search_result_list << create_app(app_content)
15
+ end
16
+ else
17
+ @doc.css("li.z-last-child div.snippet").each do |app_content|
18
+ app_search_result_list << create_app(app_content)
19
+ end
20
+ end
21
+ app_search_result_list
22
+ end
27
23
 
28
- private
29
- def get_url(app_content)
30
- url = $GOOGLE_PLAY_STORE_BASE_URL + app_content.css("div.thumbnail-wrapper a").first['href']
31
- if url.end_with?(SEARCH_APP_URL_END_SUFF)
32
- url = url[0..-1* (SEARCH_APP_URL_END_SUFF.size + 1)]
33
- end
34
- url
35
- end
24
+ private
25
+ def get_url(app_content)
26
+ url = $GOOGLE_PLAY_STORE_BASE_URL + app_content.css("div.thumbnail-wrapper a").first['href']
27
+ if url.end_with?(SEARCH_APP_URL_END_SUFF)
28
+ url = url[0..-1* (SEARCH_APP_URL_END_SUFF.size + 1)]
29
+ end
30
+ url
31
+ end
36
32
 
37
- def get_logo_url(app_content)
38
- app_content.css("div.thumbnail-wrapper a.thumbnail img").first['src']
39
- end
33
+ def get_logo_url(app_content)
34
+ app_content.css("div.thumbnail-wrapper a.thumbnail img").first['src']
35
+ end
40
36
 
41
- def get_name(app_content)
42
- app_content.css("div.details a.title").first.content
43
- end
37
+ def get_name(app_content)
38
+ app_content.css("div.details a.title").first.content
39
+ end
44
40
 
45
- def get_developer(app_content)
46
- app_content.css("div.details div.attribution-category span.attribution a").first.content
47
- end
41
+ def get_developer(app_content)
42
+ deleloper_contents_list = app_content.css("div.details div.attribution-category span.attribution a")
43
+ if deleloper_contents_list && deleloper_contents_list.size > 0
44
+ return deleloper_contents_list.first.content
45
+ else
46
+ deleloper_contents_single = app_content.css("div.details span.attribution a")
47
+ if deleloper_contents_single && deleloper_contents_single.size > 0
48
+ return deleloper_contents_single.first.content
49
+ end
50
+ end
51
+ return ""
52
+ end
48
53
 
49
- def get_category(app_content)
50
- app_content.css("div.details div.attribution-category span.category a").first.content
51
- end
54
+ def get_category(app_content)
55
+ category_contents = app_content.css("div.details div.attribution-category span.category a")
56
+ if category_contents && category_contents.size>0
57
+ return category_contents.first.content
58
+ end
59
+ return ""
60
+ end
52
61
 
53
- def get_short_description(app_content)
54
- app_content.css("div.description").first.content
55
- end
62
+ def get_short_description(app_content)
63
+ description_contents = app_content.css("div.description")
64
+ if description_contents && description_contents.size > 0
65
+ return description_contents.first.content
66
+ end
67
+ return ""
68
+ end
56
69
 
57
70
  def get_app_rating(app_content)
58
71
  ratings = app_content.css("div.ratings")
@@ -71,5 +84,30 @@ module GooglePlaySearch
71
84
  reviews.first.content[1..-2].gsub(',','').to_i
72
85
  end
73
86
  end
74
- end
87
+
88
+ def get_app_price(app_content)
89
+ prices = app_content.css("span.buy-button-price")
90
+ if prices && prices.size > 0
91
+ if match = prices.first.content.match(/(.[0-9]*\.[0-9]+|[0-9]+) Buy/)
92
+ return match[1]
93
+ end
94
+ end
95
+ return "0"
96
+ end
97
+
98
+ def create_app(app_content)
99
+ app = App.new
100
+ app.url = get_url app_content
101
+ app.id = app.url[app.url.index("?id=")+4..-1]
102
+ app.name = get_name app_content
103
+ app.price = get_app_price app_content
104
+ app.developer = get_developer app_content
105
+ app.category = get_category app_content
106
+ app.logo_url = get_logo_url app_content
107
+ app.short_description = get_short_description app_content
108
+ app.rating = get_app_rating app_content
109
+ app.reviews = get_app_reviews app_content
110
+ return app
111
+ end
112
+ end
75
113
  end
@@ -5,51 +5,51 @@ require 'cgi'
5
5
  require File.expand_path(File.dirname(__FILE__) + '/app_parser')
6
6
 
7
7
  module GooglePlaySearch
8
- class Search
9
- attr_accessor :current_page, :keyword
10
-
11
- $GOOGLE_PLAY_STORE_BASE_URL = "https://play.google.com"
12
-
13
- GOOGLE_PLAY_BASE_SEARCH_URL = $GOOGLE_PLAY_STORE_BASE_URL + "/store/search?q="
14
-
15
- DEFAULT_SEARCH_CONDITION = {:language => "en",
16
- :category => "apps",
17
- :per_page_num => 24,
18
- :price => "0",
19
- :safe_search => "0",
20
- :sort_by => "1"}
21
-
22
- def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
23
- @search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
24
- @current_page = 1
25
- end
26
-
27
- def search(keyword, options={})
28
- @current_page = options[:page].nil? ? 1 : options[:page]
29
- @keyword = keyword
30
- stdin, stdout, stderr = Open3.popen3("curl '#{init_query_url}'")
31
- AppParser.new(stdout.read).parse
32
- end
33
-
34
- def next_page()
35
- @current_page = @current_page + 1
36
- search @keyword, { :page => @current_page }
37
- end
38
-
39
- private
40
- def init_query_url
41
- query_url = ""
42
- query_url << GOOGLE_PLAY_BASE_SEARCH_URL
43
- query_url << CGI.escape(@keyword) << "&"
44
- query_url << "c=" << @search_condition[:category] << "&"
45
- query_url << "hl=" << @search_condition[:language] << "&"
46
- query_url << "price=" << @search_condition[:price] << "&"
47
- query_url << "safe=" << @search_condition[:safe_search] << "&"
48
- query_url << "sort=" << @search_condition[:sort_by] << "&"
49
- start = (@current_page - 1) * @search_condition[:per_page_num]
50
- query_url << "start=#{start}&num=#{@search_condition[:per_page_num]}"
51
- end
52
- end
8
+ class Search
9
+ attr_accessor :current_page, :keyword
10
+
11
+ $GOOGLE_PLAY_STORE_BASE_URL = "https://play.google.com"
12
+
13
+ GOOGLE_PLAY_BASE_SEARCH_URL = $GOOGLE_PLAY_STORE_BASE_URL + "/store/search?q="
14
+
15
+ DEFAULT_SEARCH_CONDITION = {:language => "en",
16
+ :category => "apps",
17
+ :per_page_num => 24,
18
+ :price => "0",
19
+ :safe_search => "0",
20
+ :sort_by => "1"}
21
+
22
+ def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
23
+ @search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
24
+ @current_page = 1
25
+ end
26
+
27
+ def search(keyword, options={})
28
+ @current_page = options[:page].nil? ? 1 : options[:page]
29
+ @keyword = keyword
30
+ stdin, stdout, stderr = Open3.popen3("curl '#{init_query_url}'")
31
+ AppParser.new(stdout.read).parse
32
+ end
33
+
34
+ def next_page()
35
+ @current_page = @current_page + 1
36
+ search @keyword, { :page => @current_page }
37
+ end
38
+
39
+ private
40
+ def init_query_url
41
+ query_url = ""
42
+ query_url << GOOGLE_PLAY_BASE_SEARCH_URL
43
+ query_url << CGI.escape(@keyword) << "&"
44
+ query_url << "c=" << @search_condition[:category] << "&"
45
+ query_url << "hl=" << @search_condition[:language] << "&"
46
+ query_url << "price=" << @search_condition[:price] << "&"
47
+ query_url << "safe=" << @search_condition[:safe_search] << "&"
48
+ query_url << "sort=" << @search_condition[:sort_by] << "&"
49
+ start = (@current_page - 1) * @search_condition[:per_page_num]
50
+ query_url << "start=#{start}&num=#{@search_condition[:per_page_num]}"
51
+ end
52
+ end
53
53
  end
54
54
 
55
55
 
metadata CHANGED
@@ -1,84 +1,60 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: google_play_search
3
- version: !ruby/object:Gem::Version
4
- hash: 21
5
- prerelease:
6
- segments:
7
- - 0
8
- - 0
9
- - 5
10
- version: 0.0.5
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.6
11
5
  platform: ruby
12
- authors:
6
+ authors:
13
7
  - Grant Chen
14
8
  autorequire:
15
9
  bindir: bin
16
10
  cert_chain: []
17
-
18
- date: 2012-06-03 00:00:00 Z
19
- dependencies:
20
- - !ruby/object:Gem::Dependency
11
+ date: 2012-06-03 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
21
14
  name: nokogiri
22
- prerelease: false
23
- requirement: &id001 !ruby/object:Gem::Requirement
24
- none: false
25
- requirements:
26
- - - ">="
27
- - !ruby/object:Gem::Version
28
- hash: 5
29
- segments:
30
- - 1
31
- - 5
32
- - 3
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
33
19
  version: 1.5.3
34
20
  type: :runtime
35
- version_requirements: *id001
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.5.3
36
27
  description: google play market search gem
37
28
  email: kucss@hotmail.com
38
29
  executables: []
39
-
40
30
  extensions: []
41
-
42
31
  extra_rdoc_files: []
43
-
44
- files:
45
- - lib/google_play_search/app_parser.rb
32
+ files:
33
+ - lib/google_play_search.rb
46
34
  - lib/google_play_search/search.rb
35
+ - lib/google_play_search/app_parser.rb
47
36
  - lib/google_play_search/app.rb
48
- - lib/google_play_search.rb
49
- homepage: https://github.com/kucss/google_play_search
37
+ homepage: https://github.com/grantchen/google_play_search
50
38
  licenses: []
51
-
39
+ metadata: {}
52
40
  post_install_message:
53
41
  rdoc_options: []
54
-
55
- require_paths:
42
+ require_paths:
56
43
  - lib
57
- required_ruby_version: !ruby/object:Gem::Requirement
58
- none: false
59
- requirements:
60
- - - ">="
61
- - !ruby/object:Gem::Version
62
- hash: 3
63
- segments:
64
- - 0
65
- version: "0"
66
- required_rubygems_version: !ruby/object:Gem::Requirement
67
- none: false
68
- requirements:
69
- - - ">="
70
- - !ruby/object:Gem::Version
71
- hash: 3
72
- segments:
73
- - 0
74
- version: "0"
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - '>='
47
+ - !ruby/object:Gem::Version
48
+ version: '0'
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
75
54
  requirements: []
76
-
77
55
  rubyforge_project:
78
- rubygems_version: 1.8.24
56
+ rubygems_version: 2.0.0.rc.2
79
57
  signing_key:
80
- specification_version: 3
58
+ specification_version: 4
81
59
  summary: google play market search
82
60
  test_files: []
83
-
84
- has_rdoc: