chrome_store_search 0.0.2
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 +7 -0
- data/lib/chrome_store_search/app.rb +7 -0
- data/lib/chrome_store_search/app_parser.rb +41 -0
- data/lib/chrome_store_search/search.rb +42 -0
- data/lib/chrome_store_search.rb +3 -0
- metadata +61 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e8ee950a58881adbd6a2fa062661b9c9aecdaeaf
|
4
|
+
data.tar.gz: a1d15ce90412a2b73b3fc12003a066b3974b5fb2
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: dedd9bc7288926c764029f2e356e62c9bed1cc77178db418be34816192f5e4adaae8491df852fdc4f5890d4f5a4ef639c9731ce17039027eff9805a86540f023
|
7
|
+
data.tar.gz: 780ed65e425986d9f03538a5b5f00c24906c017a4ceac4c746d0a77b65bafc617225b00da2a2e8f658fdfa4d3f05c5ee9fa6e802d07f30a99c23c60e779960a7
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'json'
|
2
|
+
require File.expand_path(File.dirname(__FILE__) + '/app')
|
3
|
+
|
4
|
+
module ChromeStoreSearch
|
5
|
+
class AppParser
|
6
|
+
def self.parse(apps_json_body)
|
7
|
+
apps_json_array = JSON.parse(gsub_continuation_commas(apps_json_body[4..-1]))[1][1]
|
8
|
+
apps = []
|
9
|
+
apps_json_array.each do |app_item|
|
10
|
+
apps << new_app_instance(app_item)
|
11
|
+
end
|
12
|
+
return apps
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def self.gsub_continuation_commas(json_str)
|
18
|
+
json_str.gsub(/,,,*/) do |commas_str|
|
19
|
+
replace_str = ""
|
20
|
+
(commas_str.size-1).times do |index|
|
21
|
+
replace_str += ",\"\""
|
22
|
+
end
|
23
|
+
commas_str = replace_str + ","
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.new_app_instance(app_item)
|
28
|
+
app = App.new
|
29
|
+
app.id = app_item[0]
|
30
|
+
app.name = app_item[1]
|
31
|
+
app.small_logo_url = app_item[3].encode("UTF-8")
|
32
|
+
app.description = app_item[6]
|
33
|
+
app.rating = app_item[12]
|
34
|
+
app.total_rating_count = app_item[22].to_i
|
35
|
+
app.total_users = app_item[23].gsub(",", "").to_i
|
36
|
+
app.big_logo_url = app_item[25].encode("UTF-8")
|
37
|
+
app.url = app_item[37]
|
38
|
+
return app
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'net/https'
|
3
|
+
require 'uri'
|
4
|
+
require 'cgi'
|
5
|
+
require File.expand_path(File.dirname(__FILE__) + '/app_parser')
|
6
|
+
|
7
|
+
module ChromeStoreSearch
|
8
|
+
class Search
|
9
|
+
|
10
|
+
CHROME_STORE_BASE_URL = "https://chrome.google.com/webstore/ajax/item?"
|
11
|
+
|
12
|
+
DEFAULT_SEARCH_CONDITION = {:hl =>"en-US",
|
13
|
+
:count => 20,
|
14
|
+
:pv => 1394218756,
|
15
|
+
:category => nil}
|
16
|
+
|
17
|
+
def initialize(search_condition = DEFAULT_SEARCH_CONDITION)
|
18
|
+
@search_condition = DEFAULT_SEARCH_CONDITION.merge(search_condition)
|
19
|
+
end
|
20
|
+
|
21
|
+
def search(keyword)
|
22
|
+
@keyword = keyword
|
23
|
+
uri = URI.parse(init_query_url)
|
24
|
+
res = Net::HTTP.post_form(uri,{})
|
25
|
+
AppParser.parse(res.body)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def init_query_url
|
31
|
+
query_url = ""
|
32
|
+
query_url << CHROME_STORE_BASE_URL
|
33
|
+
query_url << "hl=#{@search_condition[:hl]}"
|
34
|
+
query_url << "&count=#{@search_condition[:count]}"
|
35
|
+
query_url << "&pv=#{@search_condition[:pv]}"
|
36
|
+
query_url << "&container=CHROME&sortBy=0"
|
37
|
+
query_url << "&category=#{@search_condition[:category]}" if @search_condition[:category]
|
38
|
+
query_url << "&searchTerm=#{CGI.escape(@keyword)}"
|
39
|
+
end
|
40
|
+
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,61 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: chrome_store_search
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Grant Chen
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.8.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.8.1
|
27
|
+
description: chrome web store apps, extensions and themes search
|
28
|
+
email: kucss@hotmail.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- lib/chrome_store_search/search.rb
|
34
|
+
- lib/chrome_store_search/app.rb
|
35
|
+
- lib/chrome_store_search/app_parser.rb
|
36
|
+
- lib/chrome_store_search.rb
|
37
|
+
homepage: https://github.com/grantchen/chrome_store_search
|
38
|
+
licenses: []
|
39
|
+
metadata: {}
|
40
|
+
post_install_message:
|
41
|
+
rdoc_options: []
|
42
|
+
require_paths:
|
43
|
+
- lib
|
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'
|
54
|
+
requirements: []
|
55
|
+
rubyforge_project:
|
56
|
+
rubygems_version: 2.0.3
|
57
|
+
signing_key:
|
58
|
+
specification_version: 4
|
59
|
+
summary: chrome web store search
|
60
|
+
test_files: []
|
61
|
+
has_rdoc:
|