reviews_catcher 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +9 -0
- data/.rspec +3 -0
- data/.travis.yml +15 -0
- data/Gemfile +4 -0
- data/MIT-LICENSE.txt +21 -0
- data/README.md +38 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/changes.txt +5 -0
- data/lib/reviews_catcher/account.rb +22 -0
- data/lib/reviews_catcher/base_service.rb +55 -0
- data/lib/reviews_catcher/client.rb +34 -0
- data/lib/reviews_catcher/reviews.rb +28 -0
- data/lib/reviews_catcher/version.rb +3 -0
- data/lib/reviews_catcher.rb +10 -0
- data/reviews_catcher.gemspec +29 -0
- metadata +160 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 6f4b47ea90bf150d41c52e9386000037ec554fd5
|
4
|
+
data.tar.gz: 5c1d642799381206437218a8b9925401cb39e74f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 5b64ca263172e1afdd5503b4cd1dead8057d3a5db19ff605a8aa5e44bb85702e6ad3c69992cdfefedcec08c854e440c7ca5cba5894147d0d29ec55530ff29264
|
7
|
+
data.tar.gz: 51fd80eefc31ebfb5b431b69a8fee16dbd64ba81eb6dfda795881fe384564da9a8b523d89ee3f8aafb1c7c16e32c933213aca511a36df0188dda513e236195a4
|
data/.coveralls.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
service_name: travis-ci
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/MIT-LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Reviews Catcher (http://www.reviewscatcher.io)
|
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,38 @@
|
|
1
|
+
# reviewscatcher-ruby
|
2
|
+
|
3
|
+
Ruby bindings for the Reviews Catcher API.
|
4
|
+
|
5
|
+
## Instalation
|
6
|
+
|
7
|
+
```ruby
|
8
|
+
gem install reviews_catcher
|
9
|
+
```
|
10
|
+
|
11
|
+
Using bundler:
|
12
|
+
|
13
|
+
```ruby
|
14
|
+
gem 'reviews_catcher'
|
15
|
+
```
|
16
|
+
|
17
|
+
## Configure your client
|
18
|
+
|
19
|
+
```
|
20
|
+
reviews_catcher = ReviewsCatcher::Client.new(app_id: 'my_app_id', api_key: 'my_api_key')
|
21
|
+
```
|
22
|
+
|
23
|
+
You can get your `app_id` and `api_key` from your account in Reviews Catcher, in the integration settings page.
|
24
|
+
|
25
|
+
## Usage
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
# Find your account's aggregate rating
|
29
|
+
aggregate_rating = reviews_catcher.account.aggregate_rating
|
30
|
+
|
31
|
+
# Find your account's reviews
|
32
|
+
reviews = reviews_catcher.reviews.all
|
33
|
+
```
|
34
|
+
|
35
|
+
## License
|
36
|
+
|
37
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
38
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "reviews_catcher"
|
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
data/changes.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
module ReviewsCatcher
|
2
|
+
class Account < BaseService
|
3
|
+
|
4
|
+
def name
|
5
|
+
response = JSON.parse(get_api_rating.body)
|
6
|
+
|
7
|
+
response['account_name']
|
8
|
+
end
|
9
|
+
|
10
|
+
def aggregate_rating
|
11
|
+
response = JSON.parse(get_api_rating.body)
|
12
|
+
|
13
|
+
response['aggregate_rating']
|
14
|
+
end
|
15
|
+
|
16
|
+
def rating_count
|
17
|
+
response = JSON.parse(get_api_rating.body)
|
18
|
+
|
19
|
+
response['rating_count']
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'net/http'
|
2
|
+
require 'uri'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module ReviewsCatcher
|
6
|
+
class InvalidApiRequestError < StandardError; end
|
7
|
+
class BaseService
|
8
|
+
attr_reader :client
|
9
|
+
|
10
|
+
def initialize(client)
|
11
|
+
@client = client
|
12
|
+
end
|
13
|
+
|
14
|
+
def uri(action)
|
15
|
+
URI.parse(@client.base_url + action)
|
16
|
+
end
|
17
|
+
|
18
|
+
def authorization_header_value
|
19
|
+
"api_key=#{@client.api_key}"
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(action)
|
23
|
+
uri = self.uri(action)
|
24
|
+
|
25
|
+
http = Net::HTTP.new(uri.host, uri.port)
|
26
|
+
http.open_timeout = 3 # in seconds
|
27
|
+
http.read_timeout = 3 # in seconds
|
28
|
+
|
29
|
+
request = Net::HTTP::Get.new(uri.request_uri)
|
30
|
+
request['Authorization'] = authorization_header_value
|
31
|
+
|
32
|
+
http.request(request)
|
33
|
+
end
|
34
|
+
|
35
|
+
def get_api_rating
|
36
|
+
response = get('/api/v1/rating')
|
37
|
+
|
38
|
+
if response.code == '200'
|
39
|
+
response
|
40
|
+
else
|
41
|
+
fail InvalidApiRequestError.new("invalid response from API (CODE: #{response.code})")
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def get_api_reviews
|
46
|
+
response = get('/api/v1/reviews')
|
47
|
+
|
48
|
+
if response.code == '200'
|
49
|
+
response
|
50
|
+
else
|
51
|
+
fail InvalidApiRequestError.new("invalid response from API (CODE: #{response.code})")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module ReviewsCatcher
|
2
|
+
class MisconfiguredClientError < StandardError; end
|
3
|
+
class Client
|
4
|
+
attr_reader :base_url, :app_id, :api_key
|
5
|
+
|
6
|
+
def initialize(app_id: 'my_app_id', api_key: 'my_api_key')
|
7
|
+
@app_id = app_id
|
8
|
+
@api_key = api_key
|
9
|
+
|
10
|
+
validate_credentials!
|
11
|
+
|
12
|
+
@base_url = build_base_url
|
13
|
+
end
|
14
|
+
|
15
|
+
def account
|
16
|
+
@account ||= ReviewsCatcher::Account.new(self)
|
17
|
+
end
|
18
|
+
|
19
|
+
def reviews
|
20
|
+
@reviews ||= ReviewsCatcher::Reviews.new(self)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def validate_credentials!
|
26
|
+
error = MisconfiguredClientError.new('app_id and api_key must not be nil')
|
27
|
+
fail error if @app_id.nil? || @api_key.nil?
|
28
|
+
end
|
29
|
+
|
30
|
+
def build_base_url
|
31
|
+
"http://#{@app_id}.reviewscatcher.io"
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module ReviewsCatcher
|
2
|
+
class Reviews < BaseService
|
3
|
+
|
4
|
+
def name
|
5
|
+
response = JSON.parse(get_api_reviews.body)
|
6
|
+
|
7
|
+
response['account_name']
|
8
|
+
end
|
9
|
+
|
10
|
+
def aggregate_rating
|
11
|
+
response = JSON.parse(get_api_reviews.body)
|
12
|
+
|
13
|
+
response['aggregate_rating']
|
14
|
+
end
|
15
|
+
|
16
|
+
def rating_count
|
17
|
+
response = JSON.parse(get_api_reviews.body)
|
18
|
+
|
19
|
+
response['rating_count']
|
20
|
+
end
|
21
|
+
|
22
|
+
def all
|
23
|
+
response = JSON.parse(get_api_reviews.body)
|
24
|
+
|
25
|
+
response['reviews']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'reviews_catcher/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'reviews_catcher'
|
8
|
+
spec.version = ReviewsCatcher::VERSION
|
9
|
+
spec.authors = ['Bruno Valentino']
|
10
|
+
spec.email = ['brunovalentino@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Ruby bindings for the ReviewsCatcher API (http://wwww.reviewscatcher.io)}
|
13
|
+
spec.description = %q{Ruby bindings for the ReviewsCatcher API (http://wwww.reviewscatcher.io)}
|
14
|
+
spec.homepage = 'https://github.com/reviewscatcher/reviewscatcher-ruby'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'rspec', '~> 3.0'
|
25
|
+
spec.add_development_dependency 'pry'
|
26
|
+
spec.add_development_dependency 'webmock'
|
27
|
+
spec.add_development_dependency 'forgery'
|
28
|
+
spec.add_development_dependency 'coveralls'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: reviews_catcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Bruno Valentino
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-04-03 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: :development
|
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.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '3.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: pry
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: webmock
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: forgery
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
description: Ruby bindings for the ReviewsCatcher API (http://wwww.reviewscatcher.io)
|
112
|
+
email:
|
113
|
+
- brunovalentino@gmail.com
|
114
|
+
executables: []
|
115
|
+
extensions: []
|
116
|
+
extra_rdoc_files: []
|
117
|
+
files:
|
118
|
+
- ".coveralls.yml"
|
119
|
+
- ".gitignore"
|
120
|
+
- ".rspec"
|
121
|
+
- ".travis.yml"
|
122
|
+
- Gemfile
|
123
|
+
- MIT-LICENSE.txt
|
124
|
+
- README.md
|
125
|
+
- Rakefile
|
126
|
+
- bin/console
|
127
|
+
- bin/setup
|
128
|
+
- changes.txt
|
129
|
+
- lib/reviews_catcher.rb
|
130
|
+
- lib/reviews_catcher/account.rb
|
131
|
+
- lib/reviews_catcher/base_service.rb
|
132
|
+
- lib/reviews_catcher/client.rb
|
133
|
+
- lib/reviews_catcher/reviews.rb
|
134
|
+
- lib/reviews_catcher/version.rb
|
135
|
+
- reviews_catcher.gemspec
|
136
|
+
homepage: https://github.com/reviewscatcher/reviewscatcher-ruby
|
137
|
+
licenses:
|
138
|
+
- MIT
|
139
|
+
metadata: {}
|
140
|
+
post_install_message:
|
141
|
+
rdoc_options: []
|
142
|
+
require_paths:
|
143
|
+
- lib
|
144
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
version: '0'
|
149
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
version: '0'
|
154
|
+
requirements: []
|
155
|
+
rubyforge_project:
|
156
|
+
rubygems_version: 2.5.1
|
157
|
+
signing_key:
|
158
|
+
specification_version: 4
|
159
|
+
summary: Ruby bindings for the ReviewsCatcher API (http://wwww.reviewscatcher.io)
|
160
|
+
test_files: []
|