luchadeer 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1b94d3d201a337e35c0fbaf18442c990fcafd6f2
4
- data.tar.gz: a95e9980249f97ff68359c88d5e9c186ecdef4b2
3
+ metadata.gz: b22250f9c3271c62347190dfd92e2e7789e39943
4
+ data.tar.gz: de1419a049fc0cea1271c07f1d050edd936ca0fc
5
5
  SHA512:
6
- metadata.gz: 7d362a2e26b74fe5fffd0f50053ea848a21257b12bc702e953a7bea2f473d9673b1310908a89f436a66d177578366fe398e9b1a474df544ea76d937a4661aa13
7
- data.tar.gz: 2fdb677622f7c27dae3da5549b23e8e73035e845a983d0eb5af6b630304faceb80c4386fe1ea1c2aedd1c8db5e3a958536df0ba99d903804dea91d7b2f58d819
6
+ metadata.gz: cfefb61e51e347137953212ad823fb70875e049f8e07f44c5ed10e93a3a93f8a6162702aaf56f2839774c3c10d174ee11e59c78ea63bd64d70668c893c32aa22
7
+ data.tar.gz: 982ec4afd6c622a9868af1b05c8cc56b6f59ca15f4ebf62b27a21817063bdecb441aae48ed1e80e1c5b568a283546dfb615aea7160688c2ae05986c478a7fdea
@@ -1,6 +1,7 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
+ - 1.9.3
4
5
  - 2.0.0
5
6
  - 2.1.0
6
7
  - 2.1.1
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- luchadeer (0.2.0)
4
+ luchadeer (0.3.1)
5
5
  faraday (~> 0.9.0)
6
6
 
7
7
  GEM
data/README.md CHANGED
@@ -3,10 +3,12 @@
3
3
  [![Build Status](https://travis-ci.org/paulfri/luchadeer.png?branch=master)][build]
4
4
  [![Coverage Status](https://coveralls.io/repos/paulfri/luchadeer/badge.png?branch=master)][coverage]
5
5
  [![Code Climate](https://codeclimate.com/github/paulfri/luchadeer.png)][grade]
6
+ [![Gem Version](https://badge.fury.io/rb/luchadeer.png)][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::Search.new(page: 1, limit: 50, query: 'valkyria').fetch
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 = Luchadeer::Search.new
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
 
@@ -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
@@ -30,20 +30,17 @@ module Luchadeer
30
30
  ]
31
31
 
32
32
  RESOURCES.each do |resource|
33
- define_method resource::SINGULAR do |id, refresh = false|
34
- fetch("#{resource::SINGULAR}/#{resource::RESOURCE_ID}-#{id}", refresh, 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::PLURAL do |query = nil, refresh = false|
38
- search_resource(resource::PLURAL, query, refresh, resource)
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 search(*args, &blk)
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
@@ -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
- # rescue => e
62
- # raise Luchadeer::Error.new(e)
63
+ rescue Faraday::Error => e
64
+ raise Luchadeer::Error.new e
63
65
  end
64
66
 
65
67
  def default_params
@@ -5,11 +5,11 @@ module Luchadeer
5
5
 
6
6
  class << self
7
7
  def find(id, refresh = false)
8
- Luchadeer.client.send(self::SINGULAR, id, refresh)
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::PLURAL, query, refresh)
12
+ Luchadeer.client.send(self::LIST, query, refresh)
13
13
  end
14
14
  end
15
15
 
@@ -2,134 +2,134 @@ require 'luchadeer/resource'
2
2
 
3
3
  module Luchadeer
4
4
  class Accessory < Resource
5
- SINGULAR = :accessory
6
- PLURAL = :accessories
7
- RESOURCE_ID = 3000
5
+ DETAIL = :accessory
6
+ LIST = :accessories
7
+ ID = 3000
8
8
  end
9
9
 
10
10
  class Character < Resource
11
- SINGULAR = :character
12
- PLURAL = :characters
13
- RESOURCE_ID = 3005
11
+ DETAIL = :character
12
+ LIST = :characters
13
+ ID = 3005
14
14
  end
15
15
 
16
16
  class Chat < Resource
17
- SINGULAR = :chat
18
- PLURAL = :chats
19
- RESOURCE_ID = 2450
17
+ DETAIL = :chat
18
+ LIST = :chats
19
+ ID = 2450
20
20
  end
21
21
 
22
22
  class Company < Resource
23
- SINGULAR = :company
24
- PLURAL = :companies
25
- RESOURCE_ID = 3010
23
+ DETAIL = :company
24
+ LIST = :companies
25
+ ID = 3010
26
26
  end
27
27
 
28
28
  class Concept < Resource
29
- SINGULAR = :concept
30
- PLURAL = :concepts
31
- RESOURCE_ID = 3015
29
+ DETAIL = :concept
30
+ LIST = :concepts
31
+ ID = 3015
32
32
  end
33
33
 
34
34
  class Franchise < Resource
35
- SINGULAR = :franchise
36
- PLURAL = :franchises
37
- RESOURCE_ID = 3025
35
+ DETAIL = :franchise
36
+ LIST = :franchises
37
+ ID = 3025
38
38
  end
39
39
 
40
40
  class Game < Resource
41
- SINGULAR = :game
42
- PLURAL = :games
43
- RESOURCE_ID = 3030
41
+ DETAIL = :game
42
+ LIST = :games
43
+ ID = 3030
44
44
  end
45
45
 
46
46
  class GameRating < Resource
47
- SINGULAR = :game_rating
48
- PLURAL = :game_ratings
49
- RESOURCE_ID = 3065
47
+ DETAIL = :game_rating
48
+ LIST = :game_ratings
49
+ ID = 3065
50
50
  end
51
51
 
52
52
  class Genre < Resource
53
- SINGULAR = :genre
54
- PLURAL = :genres
55
- RESOURCE_ID = 3060
53
+ DETAIL = :genre
54
+ LIST = :genres
55
+ ID = 3060
56
56
  end
57
57
 
58
58
  class Location < Resource
59
- SINGULAR = :location
60
- PLURAL = :locations
61
- RESOURCE_ID = 3035
59
+ DETAIL = :location
60
+ LIST = :locations
61
+ ID = 3035
62
62
  end
63
63
 
64
64
  class Object < Resource
65
- SINGULAR = :object
66
- PLURAL = :objects
67
- RESOURCE_ID = 3055
65
+ DETAIL = :object
66
+ LIST = :objects
67
+ ID = 3055
68
68
  end
69
69
 
70
70
  class Person < Resource
71
- SINGULAR = :person
72
- PLURAL = :people
73
- RESOURCE_ID = 3040
71
+ DETAIL = :person
72
+ LIST = :people
73
+ ID = 3040
74
74
  end
75
75
 
76
76
  class Platform < Resource
77
- SINGULAR = :platform
78
- PLURAL = :platforms
79
- RESOURCE_ID = 3045
77
+ DETAIL = :platform
78
+ LIST = :platforms
79
+ ID = 3045
80
80
  end
81
81
 
82
82
  class Promo < Resource
83
- SINGULAR = :promo
84
- PLURAL = :promos
85
- RESOURCE_ID = 1700
83
+ DETAIL = :promo
84
+ LIST = :promos
85
+ ID = 1700
86
86
  end
87
87
 
88
88
  class RatingBoard < Resource
89
- SINGULAR = :rating_board
90
- PLURAL = :rating_boards
91
- RESOURCE_ID = 3070
89
+ DETAIL = :rating_board
90
+ LIST = :rating_boards
91
+ ID = 3070
92
92
  end
93
93
 
94
94
  class Region < Resource
95
- SINGULAR = :region
96
- PLURAL = :regions
97
- RESOURCE_ID = 3075
95
+ DETAIL = :region
96
+ LIST = :regions
97
+ ID = 3075
98
98
  end
99
99
 
100
100
  class Release < Resource
101
- SINGULAR = :release
102
- PLURAL = :releases
103
- RESOURCE_ID = 3050
101
+ DETAIL = :release
102
+ LIST = :releases
103
+ ID = 3050
104
104
  end
105
105
 
106
106
  class Review < Resource
107
- SINGULAR = :review
108
- PLURAL = :reviews
109
- RESOURCE_ID = 1900
107
+ DETAIL = :review
108
+ LIST = :reviews
109
+ ID = 1900
110
110
  end
111
111
 
112
112
  class Theme < Resource
113
- SINGULAR = :theme
114
- PLURAL = :themes
115
- RESOURCE_ID = 3032
113
+ DETAIL = :theme
114
+ LIST = :themes
115
+ ID = 3032
116
116
  end
117
117
 
118
118
  class UserReview < Resource
119
- SINGULAR = :user_review
120
- PLURAL = :user_reviews
121
- RESOURCE_ID = 2200
119
+ DETAIL = :user_review
120
+ LIST = :user_reviews
121
+ ID = 2200
122
122
  end
123
123
 
124
124
  class Video < Resource
125
- SINGULAR = :video
126
- PLURAL = :videos
127
- RESOURCE_ID = 2300
125
+ DETAIL = :video
126
+ LIST = :videos
127
+ ID = 2300
128
128
  end
129
129
 
130
130
  class VideoType < Resource
131
- SINGULAR = :video_type
132
- PLURAL = :video_types
133
- RESOURCE_ID = 2320
131
+ DETAIL = :video_type
132
+ LIST = :video_types
133
+ ID = 2320
134
134
  end
135
135
  end
@@ -1,3 +1,3 @@
1
1
  module Luchadeer
2
- VERSION = '0.3.0'
2
+ VERSION = '0.3.1'
3
3
  end
@@ -5,7 +5,11 @@ describe Luchadeer::API do
5
5
  let(:key) { 'Chie' }
6
6
  let(:val) { 'Tomoe Gozen' }
7
7
 
8
- describe '#cache' do
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, "http://www.giantbomb.com/api/search")
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(:singular) { described_class::SINGULAR }
3
- let(:plural) { described_class::PLURAL }
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(singular).with(1, true)
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(singular).with(1, false)
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(plural).with(query, true)
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(plural).with(query, false)
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::SINGULAR }
8
+ let(:find) { described_class::DETAIL }
9
9
  let(:id) { 14850 }
10
- let(:path) { %r(#{Luchadeer::Client::GIANT_BOMB}/#{find}/#{described_class::RESOURCE_ID}-#{id}) }
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::PLURAL }
31
+ let(:search) { described_class::LIST }
32
32
  let(:query) { 'chie' }
33
33
  let(:path) { %r(#{Luchadeer::Client::GIANT_BOMB}/#{search}) }
34
34
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: luchadeer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Paul Friedman