luchadeer 0.3.1 → 0.4.0
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 +5 -5
- data/.gitignore +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +4 -4
- data/lib/luchadeer/client.rb +11 -28
- data/lib/luchadeer/middleware/follow_redirects.rb +1 -1
- data/lib/luchadeer/version.rb +1 -1
- data/luchadeer.gemspec +1 -1
- data/spec/luchadeer/client_spec.rb +24 -25
- data/spec/luchadeer/middleware/follow_redirects_spec.rb +37 -0
- data/spec/luchadeer/resource_spec.rb +1 -1
- data/spec/luchadeer/search_spec.rb +9 -9
- metadata +8 -7
- data/Gemfile.lock +0 -60
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f24bbcc0abbc0e797271da9f9cd00f0d1f6aa3b6119f1e663c59d1240885031f
|
4
|
+
data.tar.gz: c1a173ec9966a10fcff77ec484e9173323047c68fcd39986c3e45b3b9c8f0aab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1586bd13f33b1bd9888c4130fec1f32d3cceef388909855ac2f0ba8c51560c58e36aca96b925264824f40f1135cd96bb3ac97dadf48440700258c8a58ab19209
|
7
|
+
data.tar.gz: 810e8eecb979e6d1741c4c9e3b1e59fb47cd0ff0010108159a6aa8395e02181ca43d23317232cf3fb5a3625e3aaaa38d0149554e21a4657168d7dd222ac29274
|
data/.gitignore
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.1
|
data/.travis.yml
CHANGED
data/lib/luchadeer/client.rb
CHANGED
@@ -9,24 +9,17 @@ require 'luchadeer/middleware/parse_api_error'
|
|
9
9
|
|
10
10
|
module Luchadeer
|
11
11
|
class Client
|
12
|
+
GIANT_BOMB = 'http://www.giantbomb.com/api'
|
13
|
+
|
12
14
|
include Luchadeer::API
|
13
15
|
|
14
16
|
attr_accessor :api_key
|
15
|
-
GIANT_BOMB = 'http://www.giantbomb.com/api'
|
16
17
|
|
17
18
|
def initialize(opts = {})
|
18
19
|
@api_key = opts[:api_key] if opts[:api_key]
|
19
20
|
yield self if block_given?
|
20
21
|
end
|
21
22
|
|
22
|
-
def user_agent
|
23
|
-
"Luchadeer #{Luchadeer::VERSION}"
|
24
|
-
end
|
25
|
-
|
26
|
-
def api_key?
|
27
|
-
not (api_key.nil? || api_key == '')
|
28
|
-
end
|
29
|
-
|
30
23
|
def get(path, params = {})
|
31
24
|
request(:get, path, params)
|
32
25
|
end
|
@@ -34,28 +27,18 @@ module Luchadeer
|
|
34
27
|
private
|
35
28
|
|
36
29
|
def connection
|
37
|
-
@_connection ||= Faraday.new(GIANT_BOMB,
|
38
|
-
|
30
|
+
@_connection ||= Faraday.new(GIANT_BOMB, headers: headers) do |f|
|
31
|
+
f.response :parse_api_error
|
32
|
+
f.response :parse_json
|
33
|
+
f.response :parse_http_error
|
34
|
+
f.response :follow_redirects
|
39
35
|
|
40
|
-
|
41
|
-
|
42
|
-
builder: middleware,
|
43
|
-
headers: {
|
44
|
-
accept: 'application/json',
|
45
|
-
user_agent: user_agent,
|
46
|
-
}
|
47
|
-
}
|
36
|
+
f.adapter :net_http
|
37
|
+
end
|
48
38
|
end
|
49
39
|
|
50
|
-
def
|
51
|
-
|
52
|
-
builder.response :parse_api_error
|
53
|
-
builder.response :parse_json
|
54
|
-
builder.response :parse_http_error
|
55
|
-
builder.response :follow_redirects
|
56
|
-
|
57
|
-
builder.adapter :net_http
|
58
|
-
end
|
40
|
+
def headers
|
41
|
+
{ accept: 'application/json', user_agent: "Luchadeer v#{Luchadeer::VERSION}" }
|
59
42
|
end
|
60
43
|
|
61
44
|
def request(method, path, params = {})
|
@@ -21,7 +21,7 @@ module Luchadeer
|
|
21
21
|
if follow_redirect?(env, response)
|
22
22
|
raise Luchadeer::Error::RedirectLimitReached, response if follows.zero?
|
23
23
|
|
24
|
-
env
|
24
|
+
env = update_env(env, request_body, response)
|
25
25
|
response = follow_redirect(env, follows - 1)
|
26
26
|
end
|
27
27
|
end
|
data/lib/luchadeer/version.rb
CHANGED
data/luchadeer.gemspec
CHANGED
@@ -17,7 +17,7 @@ Gem::Specification.new do |spec|
|
|
17
17
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
18
|
spec.require_paths = ['lib']
|
19
19
|
|
20
|
-
spec.add_dependency 'faraday', '~> 0.
|
20
|
+
spec.add_dependency 'faraday', '~> 0.10'
|
21
21
|
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
23
|
spec.add_development_dependency 'rake'
|
@@ -10,41 +10,21 @@ describe Luchadeer::Client do
|
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
-
describe '#user_agent' do
|
14
|
-
it 'identifies the library' do
|
15
|
-
expect(client.user_agent).to eq "Luchadeer #{Luchadeer::VERSION}"
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
describe '#api_key?' do
|
20
|
-
context 'when API key is present' do
|
21
|
-
it 'returns true' do
|
22
|
-
client.api_key = 'key'
|
23
|
-
expect(client.api_key?).to be_true
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
context 'when API key is not present' do
|
28
|
-
it 'returns false' do
|
29
|
-
client.api_key = ''
|
30
|
-
expect(client.api_key?).to be_false
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
13
|
describe '#get' do
|
36
14
|
let(:url) { %r(http://laika.io) }
|
15
|
+
let(:empty_body) { '{ }' }
|
37
16
|
|
38
17
|
it 'makes a GET request' do
|
39
|
-
stub = stub_request(:get, url).to_return(body:
|
18
|
+
stub = stub_request(:get, url).to_return(body: empty_body)
|
40
19
|
client.get("http://laika.io")
|
41
20
|
|
42
21
|
expect(stub).to have_been_requested
|
43
22
|
end
|
44
23
|
|
45
24
|
it 'adds default parameters' do
|
46
|
-
stub = stub_request(:get, url)
|
47
|
-
.
|
25
|
+
stub = stub_request(:get, url)
|
26
|
+
.with(query: { format: 'json', api_key: api_key })
|
27
|
+
.to_return(body: empty_body)
|
48
28
|
|
49
29
|
client.get("http://laika.io")
|
50
30
|
expect(stub).to have_been_requested
|
@@ -56,4 +36,23 @@ describe Luchadeer::Client do
|
|
56
36
|
end
|
57
37
|
end
|
58
38
|
|
39
|
+
describe '#connection' do
|
40
|
+
describe 'user agent header' do
|
41
|
+
it 'identifies the library' do
|
42
|
+
expect(client.send(:connection).headers[:user_agent]).to eq "Luchadeer v#{Luchadeer::VERSION}"
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
describe 'middleware stack' do
|
47
|
+
it 'includes all custom middleware and the Net::HTTP adapter' do
|
48
|
+
expect(client.send(:connection).builder.handlers).to include \
|
49
|
+
Luchadeer::Middleware::ParseAPIError,
|
50
|
+
Luchadeer::Middleware::ParseJSON,
|
51
|
+
Luchadeer::Middleware::ParseHTTPError,
|
52
|
+
Luchadeer::Middleware::FollowRedirects,
|
53
|
+
Faraday::Adapter::NetHttp
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
59
58
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Luchadeer::Middleware::FollowRedirects do
|
4
|
+
let(:response) { 'yay!' }
|
5
|
+
|
6
|
+
# adapted from:
|
7
|
+
# https://github.com/lostisland/faraday_middleware/blob/5a19d04a77650405a97ea0abc6152d23134b624e/spec/follow_redirects_spec.rb
|
8
|
+
[301, 302, 303, 307].each do |status|
|
9
|
+
it "follows redirects for responses with status #{status}" do
|
10
|
+
connection = Faraday.new do |f|
|
11
|
+
f.use described_class
|
12
|
+
f.adapter :test do |stub|
|
13
|
+
stub.get('/redirect') { [status, { 'Location' => '/found' }, ''] }
|
14
|
+
stub.get('/found') { [200, { 'Content-Type' => 'text/plain' }, response] }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
expect(connection.get('/redirect').body).to eq response
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'raises a RedirectLimitReached after three redirects' do
|
23
|
+
connection = Faraday.new do |f|
|
24
|
+
f.use described_class
|
25
|
+
f.adapter :test do |stub|
|
26
|
+
stub.get('/') { [301, {'Location' => '/redirect'}, ''] }
|
27
|
+
stub.get('/redirect') { [301, {'Location' => '/redirect2'}, ''] }
|
28
|
+
stub.get('/redirect2') { [301, {'Location' => '/redirect3'}, ''] }
|
29
|
+
stub.get('/redirect3') { [301, {'Location' => '/found'}, ''] }
|
30
|
+
stub.get('/found') { [200, {'Content-Type' => 'text/plain'}, 'fin'] }
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
expect { connection.get('/') }.to raise_error(Luchadeer::Error::RedirectLimitReached)
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -55,7 +55,7 @@ describe Luchadeer::Resource do
|
|
55
55
|
|
56
56
|
it 'fetches details and returns the new object' do
|
57
57
|
stub_request(:get, %r(#{url})).to_return(body: '{ "results": { "detailed?": true } }')
|
58
|
-
expect(resource.detail.detailed?).to
|
58
|
+
expect(resource.detail.detailed?).to be true
|
59
59
|
end
|
60
60
|
end
|
61
61
|
|
@@ -174,15 +174,15 @@ describe Luchadeer::Search do
|
|
174
174
|
search
|
175
175
|
end
|
176
176
|
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
177
|
+
it { expect(subject[0]).to be_instance_of Luchadeer::Character }
|
178
|
+
it { expect(subject[1]).to be_instance_of Luchadeer::Company }
|
179
|
+
it { expect(subject[2]).to be_instance_of Luchadeer::Concept }
|
180
|
+
it { expect(subject[3]).to be_instance_of Luchadeer::Franchise }
|
181
|
+
it { expect(subject[4]).to be_instance_of Luchadeer::Game }
|
182
|
+
it { expect(subject[5]).to be_instance_of Luchadeer::Location }
|
183
|
+
it { expect(subject[6]).to be_instance_of Luchadeer::Object }
|
184
|
+
it { expect(subject[7]).to be_instance_of Luchadeer::Person }
|
185
|
+
it { expect(subject[8]).to be_instance_of Luchadeer::Video }
|
186
186
|
end
|
187
187
|
|
188
188
|
context 'when the resource type isn\'t mapped' do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: luchadeer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Friedman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-04-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0.
|
19
|
+
version: '0.10'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0.
|
26
|
+
version: '0.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -103,9 +103,9 @@ extra_rdoc_files: []
|
|
103
103
|
files:
|
104
104
|
- ".gitignore"
|
105
105
|
- ".rspec"
|
106
|
+
- ".ruby-version"
|
106
107
|
- ".travis.yml"
|
107
108
|
- Gemfile
|
108
|
-
- Gemfile.lock
|
109
109
|
- LICENSE
|
110
110
|
- README.md
|
111
111
|
- Rakefile
|
@@ -125,6 +125,7 @@ files:
|
|
125
125
|
- spec/luchadeer/api_spec.rb
|
126
126
|
- spec/luchadeer/client_spec.rb
|
127
127
|
- spec/luchadeer/error_spec.rb
|
128
|
+
- spec/luchadeer/middleware/follow_redirects_spec.rb
|
128
129
|
- spec/luchadeer/resource_spec.rb
|
129
130
|
- spec/luchadeer/resources_spec.rb
|
130
131
|
- spec/luchadeer/search_spec.rb
|
@@ -152,7 +153,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
152
153
|
version: '0'
|
153
154
|
requirements: []
|
154
155
|
rubyforge_project:
|
155
|
-
rubygems_version: 2.
|
156
|
+
rubygems_version: 2.7.6
|
156
157
|
signing_key:
|
157
158
|
specification_version: 4
|
158
159
|
summary: The bombingest Giant Bomb API client library for Ruby.
|
@@ -160,6 +161,7 @@ test_files:
|
|
160
161
|
- spec/luchadeer/api_spec.rb
|
161
162
|
- spec/luchadeer/client_spec.rb
|
162
163
|
- spec/luchadeer/error_spec.rb
|
164
|
+
- spec/luchadeer/middleware/follow_redirects_spec.rb
|
163
165
|
- spec/luchadeer/resource_spec.rb
|
164
166
|
- spec/luchadeer/resources_spec.rb
|
165
167
|
- spec/luchadeer/search_spec.rb
|
@@ -167,4 +169,3 @@ test_files:
|
|
167
169
|
- spec/spec_helper.rb
|
168
170
|
- spec/support/shared_resource.rb
|
169
171
|
- spec/support/shared_searchable.rb
|
170
|
-
has_rdoc:
|
data/Gemfile.lock
DELETED
@@ -1,60 +0,0 @@
|
|
1
|
-
PATH
|
2
|
-
remote: .
|
3
|
-
specs:
|
4
|
-
luchadeer (0.3.1)
|
5
|
-
faraday (~> 0.9.0)
|
6
|
-
|
7
|
-
GEM
|
8
|
-
remote: https://rubygems.org/
|
9
|
-
specs:
|
10
|
-
addressable (2.3.5)
|
11
|
-
coveralls (0.7.0)
|
12
|
-
multi_json (~> 1.3)
|
13
|
-
rest-client
|
14
|
-
simplecov (>= 0.7)
|
15
|
-
term-ansicolor
|
16
|
-
thor
|
17
|
-
crack (0.4.2)
|
18
|
-
safe_yaml (~> 1.0.0)
|
19
|
-
diff-lcs (1.2.5)
|
20
|
-
docile (1.1.3)
|
21
|
-
faraday (0.9.0)
|
22
|
-
multipart-post (>= 1.2, < 3)
|
23
|
-
mime-types (2.1)
|
24
|
-
multi_json (1.8.4)
|
25
|
-
multipart-post (2.0.0)
|
26
|
-
rake (10.1.1)
|
27
|
-
rest-client (1.6.7)
|
28
|
-
mime-types (>= 1.16)
|
29
|
-
rspec (2.14.1)
|
30
|
-
rspec-core (~> 2.14.0)
|
31
|
-
rspec-expectations (~> 2.14.0)
|
32
|
-
rspec-mocks (~> 2.14.0)
|
33
|
-
rspec-core (2.14.7)
|
34
|
-
rspec-expectations (2.14.5)
|
35
|
-
diff-lcs (>= 1.1.3, < 2.0)
|
36
|
-
rspec-mocks (2.14.5)
|
37
|
-
safe_yaml (1.0.1)
|
38
|
-
simplecov (0.8.2)
|
39
|
-
docile (~> 1.1.0)
|
40
|
-
multi_json
|
41
|
-
simplecov-html (~> 0.8.0)
|
42
|
-
simplecov-html (0.8.0)
|
43
|
-
term-ansicolor (1.3.0)
|
44
|
-
tins (~> 1.0)
|
45
|
-
thor (0.18.1)
|
46
|
-
tins (1.0.0)
|
47
|
-
webmock (1.17.2)
|
48
|
-
addressable (>= 2.2.7)
|
49
|
-
crack (>= 0.3.2)
|
50
|
-
|
51
|
-
PLATFORMS
|
52
|
-
ruby
|
53
|
-
|
54
|
-
DEPENDENCIES
|
55
|
-
bundler (~> 1.5)
|
56
|
-
coveralls
|
57
|
-
luchadeer!
|
58
|
-
rake
|
59
|
-
rspec
|
60
|
-
webmock
|