luchadeer 0.3.0 → 0.3.1
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 +4 -4
- data/.travis.yml +1 -0
- data/Gemfile.lock +1 -1
- data/README.md +9 -9
- data/lib/luchadeer.rb +4 -2
- data/lib/luchadeer/api.rb +6 -14
- data/lib/luchadeer/client.rb +4 -2
- data/lib/luchadeer/resource.rb +2 -2
- data/lib/luchadeer/resources.rb +66 -66
- data/lib/luchadeer/version.rb +1 -1
- data/spec/luchadeer/api_spec.rb +6 -4
- data/spec/luchadeer/client_spec.rb +5 -0
- data/spec/luchadeer/search_spec.rb +1 -1
- data/spec/support/shared_resource.rb +6 -6
- data/spec/support/shared_searchable.rb +3 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b22250f9c3271c62347190dfd92e2e7789e39943
|
4
|
+
data.tar.gz: de1419a049fc0cea1271c07f1d050edd936ca0fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cfefb61e51e347137953212ad823fb70875e049f8e07f44c5ed10e93a3a93f8a6162702aaf56f2839774c3c10d174ee11e59c78ea63bd64d70668c893c32aa22
|
7
|
+
data.tar.gz: 982ec4afd6c622a9868af1b05c8cc56b6f59ca15f4ebf62b27a21817063bdecb441aae48ed1e80e1c5b568a283546dfb615aea7160688c2ae05986c478a7fdea
|
data/.travis.yml
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -3,10 +3,12 @@
|
|
3
3
|
[][build]
|
4
4
|
[][coverage]
|
5
5
|
[][grade]
|
6
|
+
[][gem]
|
6
7
|
|
7
8
|
[build]: https://travis-ci.org/paulfri/luchadeer
|
8
9
|
[coverage]: https://coveralls.io/r/paulfri/luchadeer?branch=master
|
9
10
|
[grade]: https://codeclimate.com/github/paulfri/luchadeer
|
11
|
+
[gem]: http://badge.fury.io/rb/luchadeer
|
10
12
|
|
11
13
|
The bombingest Giant Bomb API client library for Ruby.
|
12
14
|
|
@@ -44,21 +46,19 @@ my_client.game 21373
|
|
44
46
|
Luchadeer::RatingBoard.find 3
|
45
47
|
my_client.rating_board 3
|
46
48
|
|
47
|
-
# Custom searches
|
48
|
-
Luchadeer
|
49
|
+
# Custom searches (some random examples, mix and match as you like)
|
50
|
+
Luchadeer.search(page: 1, limit: 50, query: 'valkyria')
|
49
51
|
|
50
|
-
search
|
51
|
-
search.page(1).limit(50).sort('name', :desc) # default is :asc
|
52
|
-
search.resources [Luchadeer::Game, Luchadeer::Character] # strings work too
|
53
|
-
search.query 'valkyria'
|
54
|
-
search.fetch
|
55
|
-
|
56
|
-
search = Luchadeer::Search.new do |s|
|
52
|
+
Luchadeer.search do |s|
|
57
53
|
s.query = 'valkyria'
|
58
54
|
s.page = 1
|
59
55
|
s.limit = 50
|
60
56
|
end
|
61
57
|
|
58
|
+
search = Luchadeer::Search.new
|
59
|
+
search.page(1).limit(50).sort('name', :desc) # default is :asc
|
60
|
+
search.resources [Luchadeer::Game, Luchadeer::Character] # strings work too
|
61
|
+
search.query 'valkyria'
|
62
62
|
results = search.fetch
|
63
63
|
```
|
64
64
|
|
data/lib/luchadeer.rb
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
require 'luchadeer/api'
|
2
1
|
require 'luchadeer/client'
|
3
|
-
require 'luchadeer/error'
|
4
2
|
require 'luchadeer/search'
|
5
3
|
|
6
4
|
module Luchadeer
|
@@ -16,5 +14,9 @@ module Luchadeer
|
|
16
14
|
def client=(new_client)
|
17
15
|
Thread.current[:luchadeer_client] = new_client
|
18
16
|
end
|
17
|
+
|
18
|
+
def search(*args, &blk)
|
19
|
+
Luchadeer::Search.new(*args, &blk).fetch
|
20
|
+
end
|
19
21
|
end
|
20
22
|
end
|
data/lib/luchadeer/api.rb
CHANGED
@@ -30,20 +30,17 @@ module Luchadeer
|
|
30
30
|
]
|
31
31
|
|
32
32
|
RESOURCES.each do |resource|
|
33
|
-
define_method resource::
|
34
|
-
fetch("#{resource::
|
33
|
+
define_method resource::DETAIL do |id, refresh = false|
|
34
|
+
fetch("#{resource::DETAIL}/#{resource::ID}-#{id}", refresh, resource)
|
35
35
|
end
|
36
36
|
|
37
|
-
define_method resource::
|
38
|
-
|
37
|
+
define_method resource::LIST do |query = nil, refresh = false|
|
38
|
+
query_string = "?filter=name:#{query}" unless query.nil? or query.length < 1
|
39
|
+
fetch("#{resource::LIST}#{query_string}", refresh, resource)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
def
|
43
|
-
Luchadeer::Search.new(*args, &blk).fetch
|
44
|
-
end
|
45
|
-
|
46
|
-
def cache(key, refresh = false, &blk)
|
43
|
+
def cache(key, refresh = false)
|
47
44
|
@cache ||= {}
|
48
45
|
@cache.delete(key) if refresh
|
49
46
|
|
@@ -62,10 +59,5 @@ module Luchadeer
|
|
62
59
|
results.is_a?(Array) ? results.map { |r| klass.new(r) } : klass.new(results)
|
63
60
|
end
|
64
61
|
|
65
|
-
def search_resource(endpoint, query, refresh = false, klass = Luchadeer::Resource)
|
66
|
-
query_string = "?filter=name:#{query}" unless query.nil? or query.length < 1
|
67
|
-
fetch("#{endpoint}#{query_string}", refresh, klass)
|
68
|
-
end
|
69
|
-
|
70
62
|
end
|
71
63
|
end
|
data/lib/luchadeer/client.rb
CHANGED
@@ -1,4 +1,6 @@
|
|
1
1
|
require 'faraday'
|
2
|
+
require 'luchadeer/api'
|
3
|
+
require 'luchadeer/error'
|
2
4
|
require 'luchadeer/version'
|
3
5
|
require 'luchadeer/middleware/follow_redirects'
|
4
6
|
require 'luchadeer/middleware/parse_json'
|
@@ -58,8 +60,8 @@ module Luchadeer
|
|
58
60
|
|
59
61
|
def request(method, path, params = {})
|
60
62
|
connection.send(method.to_sym, path, params.merge(default_params))
|
61
|
-
|
62
|
-
|
63
|
+
rescue Faraday::Error => e
|
64
|
+
raise Luchadeer::Error.new e
|
63
65
|
end
|
64
66
|
|
65
67
|
def default_params
|
data/lib/luchadeer/resource.rb
CHANGED
@@ -5,11 +5,11 @@ module Luchadeer
|
|
5
5
|
|
6
6
|
class << self
|
7
7
|
def find(id, refresh = false)
|
8
|
-
Luchadeer.client.send(self::
|
8
|
+
Luchadeer.client.send(self::DETAIL, id, refresh)
|
9
9
|
end
|
10
10
|
|
11
11
|
def search(query = nil, refresh = false)
|
12
|
-
Luchadeer.client.send(self::
|
12
|
+
Luchadeer.client.send(self::LIST, query, refresh)
|
13
13
|
end
|
14
14
|
end
|
15
15
|
|
data/lib/luchadeer/resources.rb
CHANGED
@@ -2,134 +2,134 @@ require 'luchadeer/resource'
|
|
2
2
|
|
3
3
|
module Luchadeer
|
4
4
|
class Accessory < Resource
|
5
|
-
|
6
|
-
|
7
|
-
|
5
|
+
DETAIL = :accessory
|
6
|
+
LIST = :accessories
|
7
|
+
ID = 3000
|
8
8
|
end
|
9
9
|
|
10
10
|
class Character < Resource
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
DETAIL = :character
|
12
|
+
LIST = :characters
|
13
|
+
ID = 3005
|
14
14
|
end
|
15
15
|
|
16
16
|
class Chat < Resource
|
17
|
-
|
18
|
-
|
19
|
-
|
17
|
+
DETAIL = :chat
|
18
|
+
LIST = :chats
|
19
|
+
ID = 2450
|
20
20
|
end
|
21
21
|
|
22
22
|
class Company < Resource
|
23
|
-
|
24
|
-
|
25
|
-
|
23
|
+
DETAIL = :company
|
24
|
+
LIST = :companies
|
25
|
+
ID = 3010
|
26
26
|
end
|
27
27
|
|
28
28
|
class Concept < Resource
|
29
|
-
|
30
|
-
|
31
|
-
|
29
|
+
DETAIL = :concept
|
30
|
+
LIST = :concepts
|
31
|
+
ID = 3015
|
32
32
|
end
|
33
33
|
|
34
34
|
class Franchise < Resource
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
DETAIL = :franchise
|
36
|
+
LIST = :franchises
|
37
|
+
ID = 3025
|
38
38
|
end
|
39
39
|
|
40
40
|
class Game < Resource
|
41
|
-
|
42
|
-
|
43
|
-
|
41
|
+
DETAIL = :game
|
42
|
+
LIST = :games
|
43
|
+
ID = 3030
|
44
44
|
end
|
45
45
|
|
46
46
|
class GameRating < Resource
|
47
|
-
|
48
|
-
|
49
|
-
|
47
|
+
DETAIL = :game_rating
|
48
|
+
LIST = :game_ratings
|
49
|
+
ID = 3065
|
50
50
|
end
|
51
51
|
|
52
52
|
class Genre < Resource
|
53
|
-
|
54
|
-
|
55
|
-
|
53
|
+
DETAIL = :genre
|
54
|
+
LIST = :genres
|
55
|
+
ID = 3060
|
56
56
|
end
|
57
57
|
|
58
58
|
class Location < Resource
|
59
|
-
|
60
|
-
|
61
|
-
|
59
|
+
DETAIL = :location
|
60
|
+
LIST = :locations
|
61
|
+
ID = 3035
|
62
62
|
end
|
63
63
|
|
64
64
|
class Object < Resource
|
65
|
-
|
66
|
-
|
67
|
-
|
65
|
+
DETAIL = :object
|
66
|
+
LIST = :objects
|
67
|
+
ID = 3055
|
68
68
|
end
|
69
69
|
|
70
70
|
class Person < Resource
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
DETAIL = :person
|
72
|
+
LIST = :people
|
73
|
+
ID = 3040
|
74
74
|
end
|
75
75
|
|
76
76
|
class Platform < Resource
|
77
|
-
|
78
|
-
|
79
|
-
|
77
|
+
DETAIL = :platform
|
78
|
+
LIST = :platforms
|
79
|
+
ID = 3045
|
80
80
|
end
|
81
81
|
|
82
82
|
class Promo < Resource
|
83
|
-
|
84
|
-
|
85
|
-
|
83
|
+
DETAIL = :promo
|
84
|
+
LIST = :promos
|
85
|
+
ID = 1700
|
86
86
|
end
|
87
87
|
|
88
88
|
class RatingBoard < Resource
|
89
|
-
|
90
|
-
|
91
|
-
|
89
|
+
DETAIL = :rating_board
|
90
|
+
LIST = :rating_boards
|
91
|
+
ID = 3070
|
92
92
|
end
|
93
93
|
|
94
94
|
class Region < Resource
|
95
|
-
|
96
|
-
|
97
|
-
|
95
|
+
DETAIL = :region
|
96
|
+
LIST = :regions
|
97
|
+
ID = 3075
|
98
98
|
end
|
99
99
|
|
100
100
|
class Release < Resource
|
101
|
-
|
102
|
-
|
103
|
-
|
101
|
+
DETAIL = :release
|
102
|
+
LIST = :releases
|
103
|
+
ID = 3050
|
104
104
|
end
|
105
105
|
|
106
106
|
class Review < Resource
|
107
|
-
|
108
|
-
|
109
|
-
|
107
|
+
DETAIL = :review
|
108
|
+
LIST = :reviews
|
109
|
+
ID = 1900
|
110
110
|
end
|
111
111
|
|
112
112
|
class Theme < Resource
|
113
|
-
|
114
|
-
|
115
|
-
|
113
|
+
DETAIL = :theme
|
114
|
+
LIST = :themes
|
115
|
+
ID = 3032
|
116
116
|
end
|
117
117
|
|
118
118
|
class UserReview < Resource
|
119
|
-
|
120
|
-
|
121
|
-
|
119
|
+
DETAIL = :user_review
|
120
|
+
LIST = :user_reviews
|
121
|
+
ID = 2200
|
122
122
|
end
|
123
123
|
|
124
124
|
class Video < Resource
|
125
|
-
|
126
|
-
|
127
|
-
|
125
|
+
DETAIL = :video
|
126
|
+
LIST = :videos
|
127
|
+
ID = 2300
|
128
128
|
end
|
129
129
|
|
130
130
|
class VideoType < Resource
|
131
|
-
|
132
|
-
|
133
|
-
|
131
|
+
DETAIL = :video_type
|
132
|
+
LIST = :video_types
|
133
|
+
ID = 2320
|
134
134
|
end
|
135
135
|
end
|
data/lib/luchadeer/version.rb
CHANGED
data/spec/luchadeer/api_spec.rb
CHANGED
@@ -5,7 +5,11 @@ describe Luchadeer::API do
|
|
5
5
|
let(:key) { 'Chie' }
|
6
6
|
let(:val) { 'Tomoe Gozen' }
|
7
7
|
|
8
|
-
|
8
|
+
it 'defines RESOURCES' do
|
9
|
+
expect(described_class).to be_const_defined :RESOURCES
|
10
|
+
end
|
11
|
+
|
12
|
+
describe '#cache' do
|
9
13
|
context 'when value exists for key' do
|
10
14
|
it 'returns the value for the given key' do
|
11
15
|
client.cache = { key => val }
|
@@ -89,9 +93,7 @@ describe Luchadeer::API do
|
|
89
93
|
|
90
94
|
context 'with no results' do
|
91
95
|
it 'returns nil' do
|
92
|
-
stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373))
|
93
|
-
.to_return(body:'{ }')
|
94
|
-
|
96
|
+
stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373)).to_return(body:'{ }')
|
95
97
|
expect(client.fetch('game-3030/21373')).to be_nil
|
96
98
|
end
|
97
99
|
end
|
@@ -49,6 +49,11 @@ describe Luchadeer::Client do
|
|
49
49
|
client.get("http://laika.io")
|
50
50
|
expect(stub).to have_been_requested
|
51
51
|
end
|
52
|
+
|
53
|
+
it 'catches and reraises Faraday errors' do
|
54
|
+
allow(client).to receive(:connection).and_raise Faraday::Error
|
55
|
+
expect { client.get('path') }.to raise_error Luchadeer::Error
|
56
|
+
end
|
52
57
|
end
|
53
58
|
|
54
59
|
end
|
@@ -148,7 +148,7 @@ describe Luchadeer::Search do
|
|
148
148
|
end
|
149
149
|
|
150
150
|
it 'omits nil parameters' do
|
151
|
-
stub = stub_request(:get,
|
151
|
+
stub = stub_request(:get, 'http://www.giantbomb.com/api/search')
|
152
152
|
.with(query: { api_key: nil, format: 'json', query: query })
|
153
153
|
.to_return(empty_body)
|
154
154
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
shared_examples 'a resource' do
|
2
|
-
let(:
|
3
|
-
let(:
|
2
|
+
let(:detail) { described_class::DETAIL }
|
3
|
+
let(:list) { described_class::LIST }
|
4
4
|
let(:client) { Luchadeer::Client.new }
|
5
5
|
|
6
6
|
before :each do
|
@@ -13,12 +13,12 @@ shared_examples 'a resource' do
|
|
13
13
|
|
14
14
|
describe '.find' do
|
15
15
|
it "forwards to the client find method with arguments" do
|
16
|
-
expect(client).to receive(
|
16
|
+
expect(client).to receive(detail).with(1, true)
|
17
17
|
described_class.find(1, true)
|
18
18
|
end
|
19
19
|
|
20
20
|
it "forwards to the client find method with default refresh" do
|
21
|
-
expect(client).to receive(
|
21
|
+
expect(client).to receive(detail).with(1, false)
|
22
22
|
described_class.find(1)
|
23
23
|
end
|
24
24
|
end
|
@@ -27,12 +27,12 @@ shared_examples 'a resource' do
|
|
27
27
|
let(:query) { 'chie' }
|
28
28
|
|
29
29
|
it "forwards to the client search method with arguments" do
|
30
|
-
expect(client).to receive(
|
30
|
+
expect(client).to receive(list).with(query, true)
|
31
31
|
described_class.search(query, true)
|
32
32
|
end
|
33
33
|
|
34
34
|
it "forwards to the client search method with default refresh" do
|
35
|
-
expect(client).to receive(
|
35
|
+
expect(client).to receive(list).with(query, false)
|
36
36
|
described_class.search(query)
|
37
37
|
end
|
38
38
|
end
|
@@ -5,9 +5,9 @@ shared_examples 'a searchable resource' do
|
|
5
5
|
let(:client) { Luchadeer::Client.new }
|
6
6
|
|
7
7
|
describe 'find method' do
|
8
|
-
let(:find) { described_class::
|
8
|
+
let(:find) { described_class::DETAIL }
|
9
9
|
let(:id) { 14850 }
|
10
|
-
let(:path) { %r(#{Luchadeer::Client::GIANT_BOMB}/#{find}/#{described_class::
|
10
|
+
let(:path) { %r(#{Luchadeer::Client::GIANT_BOMB}/#{find}/#{described_class::ID}-#{id}) }
|
11
11
|
|
12
12
|
it 'requests the right url' do
|
13
13
|
stub = stub_request(:get, path).to_return(body: '{ }')
|
@@ -28,7 +28,7 @@ shared_examples 'a searchable resource' do
|
|
28
28
|
end
|
29
29
|
|
30
30
|
describe 'search method' do
|
31
|
-
let(:search) { described_class::
|
31
|
+
let(:search) { described_class::LIST }
|
32
32
|
let(:query) { 'chie' }
|
33
33
|
let(:path) { %r(#{Luchadeer::Client::GIANT_BOMB}/#{search}) }
|
34
34
|
|