google-seller-rating 1.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +55 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +7 -0
- data/google_seller_rating.gemspec +38 -0
- data/lib/google_seller_rating/version.rb +3 -0
- data/lib/google_seller_rating.rb +73 -0
- metadata +168 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 738d460a1d00901b57b47991ed1cbcb16a8da19e
|
4
|
+
data.tar.gz: 4dbc5a09c13ea0c489937ad228fe2fa6242f4203
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3aecd7f5848d3189efe6c19ff7ac1dbfd942d317e29c8448293baa22279851b1a671b1e47bb675899089c36ffbc18611c07a62b0016f0244affc752d12c81ac6
|
7
|
+
data.tar.gz: 3896004667bb8298deaedcf0a9cc51e062809e73cf8bdec422683c38c611b92edc9be7868d4a19aa07bb27a545038798773ee5b9917a8162e18186b58c30ec21
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2015 by Alexander Cremer
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
# Google Seller Rating
|
2
|
+
|
3
|
+
Fetching Google Seller Ratings.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'google-seller-rating'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install google-seller-rating
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
|
25
|
+
require 'google_seller_rating'
|
26
|
+
|
27
|
+
merchant = GoogleSellerRating::Api.new
|
28
|
+
|
29
|
+
merchant.domain = "http://www.amazon.com/" # Valid Domain
|
30
|
+
merchant.timeout = 2 # Set Timeout in seconds || Default: 5sec
|
31
|
+
merchant.format = "hash" # Format: hash || json
|
32
|
+
merchant.tld = "com" # e.g. google.com
|
33
|
+
|
34
|
+
merchant.rating # Show ratings
|
35
|
+
|
36
|
+
GoogleSellerRating::Api.new(format: "json", domain: "http://www.apple.de/", timeout: 5, tld: "de").rating
|
37
|
+
{"format":"json","status":"OK","google":"de","domain":"apple.de","rating":"2.3","reviews":31}
|
38
|
+
|
39
|
+
GoogleSellerRating::Api.new(format: "hash", domain: "http://www.apple.de/", timeout: 5, tld: "de").rating
|
40
|
+
{:format=>"hash", :status=>"OK", :google=>"de", :domain=>"apple.de", :rating=>"2.3", :reviews=>31}
|
41
|
+
```
|
42
|
+
|
43
|
+
## Development
|
44
|
+
|
45
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
|
46
|
+
|
47
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
48
|
+
|
49
|
+
## Contributing
|
50
|
+
|
51
|
+
1. Fork it ( https://github.com/axcr/google_seller_rating/fork )
|
52
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
53
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
54
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
55
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "google_seller_rating"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start
|
data/bin/setup
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
|
5
|
+
require 'google_seller_rating/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "google-seller-rating"
|
9
|
+
spec.version = GoogleSellerRating::VERSION
|
10
|
+
spec.authors = ["Alexander Cremer"]
|
11
|
+
spec.email = ["sayhello@alexander-cremer.com"]
|
12
|
+
spec.summary = %q{Fetch Google Seller Rating}
|
13
|
+
spec.description = %q{Fetch Google Seller Rating}
|
14
|
+
spec.homepage = "https://github.com/axcr/google-seller-rating"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "https://github.com/axcr/google_seller_rating"
|
21
|
+
# else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
# end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "exe"
|
27
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_runtime_dependency "bundler", "~> 1.9"
|
31
|
+
spec.add_runtime_dependency "rake", "~> 10.0"
|
32
|
+
spec.add_runtime_dependency "rspec", "~> 3.2.0"
|
33
|
+
spec.add_runtime_dependency "rspec-nc", "~> 0.2.0"
|
34
|
+
spec.add_runtime_dependency "nokogiri", "~> 1.6.6.2"
|
35
|
+
spec.add_runtime_dependency "open_uri_redirections", "~> 0.2.1"
|
36
|
+
spec.add_runtime_dependency "public_suffix", "~> 1.5.1"
|
37
|
+
spec.add_runtime_dependency "json", "~> 1.8.2"
|
38
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require "google_seller_rating/version"
|
2
|
+
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
5
|
+
require 'uri/http'
|
6
|
+
require 'open_uri_redirections'
|
7
|
+
require 'public_suffix'
|
8
|
+
require 'timeout'
|
9
|
+
require 'openssl'
|
10
|
+
require 'json'
|
11
|
+
|
12
|
+
module GoogleSellerRating
|
13
|
+
|
14
|
+
class Api
|
15
|
+
|
16
|
+
attr_accessor :domain, :tld, :timeout, :format
|
17
|
+
|
18
|
+
def initialize(options={})
|
19
|
+
@domain = options[:domain] ||= "http://www.amazon.com/"
|
20
|
+
@tld = options[:tld] ||= "com"
|
21
|
+
@timeout = options[:timeout] ||= 5
|
22
|
+
@format = options[:format] ||= "json"
|
23
|
+
end
|
24
|
+
|
25
|
+
def rating
|
26
|
+
begin
|
27
|
+
domain = parse_domain(@domain)
|
28
|
+
html_response = load_google(parse_domain(@domain))
|
29
|
+
html_body = Nokogiri::HTML(html_response[1])
|
30
|
+
rating = html_body.css("#rating").text
|
31
|
+
reviews = html_body.css("#review-count").text.force_encoding("iso-8859-1").gsub(/[^\d]/, "").strip.to_i
|
32
|
+
rating = if html_response[0] == "OK"
|
33
|
+
{ format: @format, status: "OK", google: @tld, domain: domain, rating: rating, reviews: reviews }
|
34
|
+
else
|
35
|
+
{ format: @format, status: html_response[0], google: @tld, domain: domain }
|
36
|
+
end
|
37
|
+
case @format
|
38
|
+
when "hash"
|
39
|
+
puts rating
|
40
|
+
else
|
41
|
+
puts rating.to_json
|
42
|
+
end
|
43
|
+
rescue Exception => e
|
44
|
+
puts "Error: #{e}"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def load_google(domain)
|
51
|
+
begin
|
52
|
+
Timeout.timeout(@timeout) do
|
53
|
+
html_body = open("https://www.google.#{@tld}/shopping/seller?q=#{domain}", { allow_redirections: :both, ssl_verify_mode: OpenSSL::SSL::VERIFY_NONE, read_timeout: @timeout })
|
54
|
+
[ html_body.status.last, html_body.read ]
|
55
|
+
end
|
56
|
+
rescue Exception => e
|
57
|
+
[ "Error: #{e}", nil ]
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def parse_domain(domain)
|
62
|
+
begin
|
63
|
+
domain = URI(domain).host
|
64
|
+
domain = PublicSuffix.parse(domain)
|
65
|
+
domain.domain
|
66
|
+
rescue Exception => e
|
67
|
+
puts "Error: #{e}"
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
metadata
ADDED
@@ -0,0 +1,168 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: google-seller-rating
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.4
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Cremer
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.9'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.9'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 3.2.0
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 3.2.0
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec-nc
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.2.0
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.2.0
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: nokogiri
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: 1.6.6.2
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: 1.6.6.2
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: open_uri_redirections
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.2.1
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 0.2.1
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: public_suffix
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 1.5.1
|
104
|
+
type: :runtime
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 1.5.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: json
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - "~>"
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.8.2
|
118
|
+
type: :runtime
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - "~>"
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.8.2
|
125
|
+
description: Fetch Google Seller Rating
|
126
|
+
email:
|
127
|
+
- sayhello@alexander-cremer.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- ".rspec"
|
134
|
+
- ".travis.yml"
|
135
|
+
- Gemfile
|
136
|
+
- LICENSE.txt
|
137
|
+
- README.md
|
138
|
+
- Rakefile
|
139
|
+
- bin/console
|
140
|
+
- bin/setup
|
141
|
+
- google_seller_rating.gemspec
|
142
|
+
- lib/google_seller_rating.rb
|
143
|
+
- lib/google_seller_rating/version.rb
|
144
|
+
homepage: https://github.com/axcr/google-seller-rating
|
145
|
+
licenses:
|
146
|
+
- MIT
|
147
|
+
metadata: {}
|
148
|
+
post_install_message:
|
149
|
+
rdoc_options: []
|
150
|
+
require_paths:
|
151
|
+
- lib
|
152
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
153
|
+
requirements:
|
154
|
+
- - ">="
|
155
|
+
- !ruby/object:Gem::Version
|
156
|
+
version: '0'
|
157
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
158
|
+
requirements:
|
159
|
+
- - ">="
|
160
|
+
- !ruby/object:Gem::Version
|
161
|
+
version: '0'
|
162
|
+
requirements: []
|
163
|
+
rubyforge_project:
|
164
|
+
rubygems_version: 2.4.5
|
165
|
+
signing_key:
|
166
|
+
specification_version: 4
|
167
|
+
summary: Fetch Google Seller Rating
|
168
|
+
test_files: []
|