google_play_search 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.unshift "#{File.dirname(__FILE__)}/google_play_search"
2
+ require 'rubygems'
3
+ require 'search'
@@ -0,0 +1,5 @@
1
+ module GooglePlaySearch
2
+ class App
3
+ attr_accessor :id, :name, :url, :developer, :category, :logo_url, :short_description
4
+ end
5
+ end
@@ -0,0 +1,55 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/app')
2
+
3
+ module GooglePlaySearch
4
+ class AppParser
5
+ SEARCH_APP_URL_END_SUFF = "&feature=search_result"
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_search_result_list << app
22
+ end
23
+ app_search_result_list
24
+ end
25
+
26
+ private
27
+ def get_url(app_content)
28
+ url = $GOOGLE_PLAY_STORE_BASE_URL + app_content.css("div.thumbnail-wrapper a").first['href']
29
+ if url.end_with?(SEARCH_APP_URL_END_SUFF)
30
+ url = url[0..-1* (SEARCH_APP_URL_END_SUFF.size + 1)]
31
+ end
32
+ url
33
+ end
34
+
35
+ def get_logo_url(app_content)
36
+ app_content.css("div.thumbnail-wrapper a.thumbnail img").first['src']
37
+ end
38
+
39
+ def get_name(app_content)
40
+ app_content.css("div.details a.title").first.content
41
+ end
42
+
43
+ def get_developer(app_content)
44
+ app_content.css("div.details div.attribution-category span.attribution a").first.content
45
+ end
46
+
47
+ def get_category(app_content)
48
+ app_content.css("div.details div.attribution-category span.category a").first.content
49
+ end
50
+
51
+ def get_short_description(app_content)
52
+ app_content.css("div.description").first.content
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,45 @@
1
+ require 'rubygems'
2
+ require 'nokogiri'
3
+ require 'open3'
4
+ require File.expand_path(File.dirname(__FILE__) + '/app_parser')
5
+
6
+ module GooglePlaySearch
7
+ class Search
8
+ attr_accessor :current_page, :keyword
9
+
10
+ $GOOGLE_PLAY_STORE_BASE_URL = "https://play.google.com"
11
+
12
+ GOOGLE_PLAY_BASE_SEARCH_URL = $GOOGLE_PLAY_STORE_BASE_URL + "/store/search?q="
13
+
14
+ DEFAULT_SEARCH_CONDITION = {:language => "en", :category => "apps", :per_page_num => 24}
15
+
16
+ def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
17
+ @search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
18
+ @current_page = 1
19
+ end
20
+
21
+ def search(keyword, options={})
22
+ @current_page = options[:page].nil? ? 1 : options[:page]
23
+ @keyword = keyword
24
+ stdin, stdout, stderr = Open3.popen3("curl '#{init_query_url}'")
25
+ AppParser.new(stdout.read).parse
26
+ end
27
+
28
+ def next_page()
29
+ @current_page = @current_page + 1
30
+ search @keyword, { :page => @current_page }
31
+ end
32
+
33
+ private
34
+ def init_query_url
35
+ query_url = ""
36
+ query_url << GOOGLE_PLAY_BASE_SEARCH_URL
37
+ query_url << @keyword << "&"
38
+ query_url << "c=" << @search_condition[:category] << "&"
39
+ query_url << "hl=" << @search_condition[:language] << "&"
40
+ start = (@current_page - 1) * @search_condition[:per_page_num]
41
+ query_url << "start=#{start}&num=#{@search_condition[:per_page_num]}"
42
+ end
43
+
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_play_search
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Grant Chen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nokogiri
16
+ requirement: &74992780 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 1.5.3
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *74992780
25
+ description: google play market search gem
26
+ email: kucss@hotmail.com
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files: []
30
+ files:
31
+ - lib/google_play_search/app_parser.rb
32
+ - lib/google_play_search/search.rb
33
+ - lib/google_play_search/app.rb
34
+ - lib/google_play_search.rb
35
+ homepage: http://rubygems.org/gems/google_play_app_search
36
+ licenses: []
37
+ post_install_message:
38
+ rdoc_options: []
39
+ require_paths:
40
+ - lib
41
+ required_ruby_version: !ruby/object:Gem::Requirement
42
+ none: false
43
+ requirements:
44
+ - - ! '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ required_rubygems_version: !ruby/object:Gem::Requirement
48
+ none: false
49
+ requirements:
50
+ - - ! '>='
51
+ - !ruby/object:Gem::Version
52
+ version: '0'
53
+ requirements: []
54
+ rubyforge_project:
55
+ rubygems_version: 1.8.10
56
+ signing_key:
57
+ specification_version: 3
58
+ summary: google play market search
59
+ test_files: []