chrome_store_search 0.0.3 → 0.0.4

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.
@@ -1,7 +1,74 @@
1
+ require 'faraday'
2
+ require 'json'
3
+ require File.expand_path(File.dirname(__FILE__) + '/string_utility')
4
+
1
5
  module ChromeStoreSearch
2
6
  class App
3
- attr_accessor :id, :name, :url, :description, :small_logo_url,
7
+ include StringUtility
8
+ attr_accessor :id, :name, :url, :short_description, :small_logo_url,
4
9
  :big_logo_url, :rating, :total_rating_count,
5
- :total_users
10
+ :total_users, :description, :site, :version,
11
+ :updated_at, :support_url, :videos, :images
12
+
13
+ APP_DETAIL_BASE_URL = "https://chrome.google.com/webstore/ajax/detail?"
14
+
15
+ DEFAULT_PARAMETER = {:hl =>"en-US"}
16
+
17
+ def initialize(id=nil)
18
+ update_detail_info(id) if id
19
+ end
20
+
21
+ def update_detail_info(id, parmeter = DEFAULT_PARAMETER)
22
+ @parmeter = DEFAULT_PARAMETER.merge(parmeter)
23
+ conn = Faraday.new(:url => init_detail_url(id)) do |faraday|
24
+ faraday.request :url_encoded
25
+ faraday.adapter Faraday.default_adapter
26
+ end
27
+ res = conn.post '', {}
28
+ parse_detail(res.body)
29
+ end
30
+
31
+ def set_basic_info(app_item)
32
+ self.id = app_item[0]
33
+ self.name = app_item[1]
34
+ self.small_logo_url = app_item[3].encode("UTF-8")
35
+ self.short_description = app_item[6]
36
+ self.rating = app_item[12]
37
+ self.total_rating_count = app_item[22].to_i
38
+ self.total_users = app_item[23].gsub(",", "").to_i
39
+ self.big_logo_url = app_item[25].encode("UTF-8")
40
+ self.url = app_item[37]
41
+ end
42
+
43
+ private
44
+
45
+ def init_detail_url(id)
46
+ detail_url = APP_DETAIL_BASE_URL
47
+ detail_url << "hl=#{@parmeter[:hl]}"
48
+ detail_url << "&pv=1394218756"
49
+ detail_url << "&id=#{id}"
50
+ detail_url << "&container=CHROME"
51
+ end
52
+
53
+ def parse_detail(app_detail_body)
54
+ detail_info = JSON.parse(gsub_continuation_commas(app_detail_body[4..-1]))[1][1]
55
+ basic_info = detail_info[0]
56
+ set_basic_info(basic_info)
57
+ self.description = detail_info[1]
58
+ self.site = detail_info[3]
59
+ self.support_url = detail_info[5]
60
+ self.version = detail_info[6]
61
+ self.updated_at = detail_info[7]
62
+ videos_images = detail_info[11]
63
+ videos_images.each do |vi|
64
+ if vi[18].include?("https://i.ytimg.com")
65
+ self.videos = [] unless self.videos
66
+ self.videos << vi[19]
67
+ else
68
+ self.images = [] unless self.images
69
+ self.images << vi[17]
70
+ end
71
+ end
72
+ end
6
73
  end
7
74
  end
@@ -1,8 +1,11 @@
1
1
  require 'json'
2
2
  require File.expand_path(File.dirname(__FILE__) + '/app')
3
+ require File.expand_path(File.dirname(__FILE__) + '/string_utility')
3
4
 
4
5
  module ChromeStoreSearch
5
6
  class AppParser
7
+ include StringUtility
8
+
6
9
  def self.parse(apps_json_body)
7
10
  apps_json_array = JSON.parse(gsub_continuation_commas(apps_json_body[4..-1]))[1][1]
8
11
  apps = []
@@ -14,27 +17,9 @@ module ChromeStoreSearch
14
17
 
15
18
  private
16
19
 
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
20
  def self.new_app_instance(app_item)
28
21
  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]
22
+ app.set_basic_info(app_item)
38
23
  return app
39
24
  end
40
25
  end
@@ -0,0 +1,15 @@
1
+ module StringUtility
2
+ def gsub_continuation_commas(json_str)
3
+ json_str.gsub(/,,,*/) do |commas_str|
4
+ replace_str = ""
5
+ (commas_str.size-1).times do |index|
6
+ replace_str += ",\"\""
7
+ end
8
+ commas_str = replace_str + ","
9
+ end
10
+ end
11
+
12
+ def StringUtility.included cls
13
+ cls.extend StringUtility
14
+ end
15
+ end
metadata CHANGED
@@ -1,7 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chrome_store_search
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Grant Chen
@@ -13,29 +14,33 @@ dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: json
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - ">="
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 1.8.1
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - ">="
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 1.8.1
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: faraday
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - ">="
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: 0.8.8
34
38
  type: :runtime
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - ">="
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: 0.8.8
41
46
  description: chrome web store apps, extensions and themes search
@@ -45,31 +50,33 @@ extensions: []
45
50
  extra_rdoc_files: []
46
51
  files:
47
52
  - lib/chrome_store_search/search.rb
53
+ - lib/chrome_store_search/string_utility.rb
48
54
  - lib/chrome_store_search/app.rb
49
55
  - lib/chrome_store_search/app_parser.rb
50
56
  - lib/chrome_store_search.rb
51
57
  homepage: https://github.com/grantchen/chrome_store_search
52
58
  licenses: []
53
- metadata: {}
54
59
  post_install_message:
55
60
  rdoc_options: []
56
61
  require_paths:
57
62
  - lib
58
63
  required_ruby_version: !ruby/object:Gem::Requirement
64
+ none: false
59
65
  requirements:
60
- - - ">="
66
+ - - ! '>='
61
67
  - !ruby/object:Gem::Version
62
68
  version: '0'
63
69
  required_rubygems_version: !ruby/object:Gem::Requirement
70
+ none: false
64
71
  requirements:
65
- - - ">="
72
+ - - ! '>='
66
73
  - !ruby/object:Gem::Version
67
74
  version: '0'
68
75
  requirements: []
69
76
  rubyforge_project:
70
- rubygems_version: 2.0.3
77
+ rubygems_version: 1.8.25
71
78
  signing_key:
72
- specification_version: 4
79
+ specification_version: 3
73
80
  summary: chrome web store search
74
81
  test_files: []
75
82
  has_rdoc:
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 229cc06f1c0e76c5794332a75091fe2c5ae0c322
4
- data.tar.gz: ae6eb0e00b87a7b797eb7124ab27b22c9375ac72
5
- SHA512:
6
- metadata.gz: 30616310fa1fe042c6455f20100c4adcdc2c8596f5c35db7be46b4c1c03a9c64e9520f4e4c224ba0f393c022505be40c41fcfa09c1884ae9451399c3f9ee53cb
7
- data.tar.gz: a454d0f2d761ced6924439ae537146668657daa3eda663df42f3fcc4c80db790f74f4132c34d5b96029fbf28bd495b12119d8590b2bed020ee234a5765ea2762