luchadeer 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/Gemfile.lock +60 -0
  7. data/LICENSE +20 -0
  8. data/README.md +58 -0
  9. data/Rakefile +1 -0
  10. data/lib/luchadeer.rb +32 -0
  11. data/lib/luchadeer/api.rb +51 -0
  12. data/lib/luchadeer/api/characters.rb +11 -0
  13. data/lib/luchadeer/api/companies.rb +11 -0
  14. data/lib/luchadeer/api/concepts.rb +11 -0
  15. data/lib/luchadeer/api/franchises.rb +11 -0
  16. data/lib/luchadeer/api/games.rb +11 -0
  17. data/lib/luchadeer/api/locations.rb +11 -0
  18. data/lib/luchadeer/api/objects.rb +11 -0
  19. data/lib/luchadeer/api/people.rb +11 -0
  20. data/lib/luchadeer/api/videos.rb +11 -0
  21. data/lib/luchadeer/character.rb +13 -0
  22. data/lib/luchadeer/client.rb +73 -0
  23. data/lib/luchadeer/company.rb +13 -0
  24. data/lib/luchadeer/concept.rb +13 -0
  25. data/lib/luchadeer/error.rb +50 -0
  26. data/lib/luchadeer/franchise.rb +13 -0
  27. data/lib/luchadeer/game.rb +13 -0
  28. data/lib/luchadeer/location.rb +13 -0
  29. data/lib/luchadeer/middleware/follow_redirects.rb +50 -0
  30. data/lib/luchadeer/middleware/parse_api_error.rb +18 -0
  31. data/lib/luchadeer/middleware/parse_http_error.rb +18 -0
  32. data/lib/luchadeer/middleware/parse_json.rb +28 -0
  33. data/lib/luchadeer/object.rb +13 -0
  34. data/lib/luchadeer/person.rb +13 -0
  35. data/lib/luchadeer/resource.rb +37 -0
  36. data/lib/luchadeer/search.rb +45 -0
  37. data/lib/luchadeer/version.rb +3 -0
  38. data/lib/luchadeer/video.rb +13 -0
  39. data/luchadeer.gemspec +27 -0
  40. data/spec/luchadeer/api/characters_spec.rb +28 -0
  41. data/spec/luchadeer/api/companies_spec.rb +28 -0
  42. data/spec/luchadeer/api/concepts_spec.rb +28 -0
  43. data/spec/luchadeer/api/franchises_spec.rb +28 -0
  44. data/spec/luchadeer/api/games_spec.rb +28 -0
  45. data/spec/luchadeer/api/locations_spec.rb +28 -0
  46. data/spec/luchadeer/api/objects_spec.rb +28 -0
  47. data/spec/luchadeer/api/people_spec.rb +28 -0
  48. data/spec/luchadeer/api/videos_spec.rb +28 -0
  49. data/spec/luchadeer/api_spec.rb +101 -0
  50. data/spec/luchadeer/character_spec.rb +27 -0
  51. data/spec/luchadeer/client_spec.rb +54 -0
  52. data/spec/luchadeer/company_spec.rb +27 -0
  53. data/spec/luchadeer/concept_spec.rb +27 -0
  54. data/spec/luchadeer/error_spec.rb +53 -0
  55. data/spec/luchadeer/franchise_spec.rb +27 -0
  56. data/spec/luchadeer/game_spec.rb +27 -0
  57. data/spec/luchadeer/location_spec.rb +27 -0
  58. data/spec/luchadeer/object_spec.rb +27 -0
  59. data/spec/luchadeer/person_spec.rb +27 -0
  60. data/spec/luchadeer/resource_spec.rb +70 -0
  61. data/spec/luchadeer/search_spec.rb +69 -0
  62. data/spec/luchadeer/video_spec.rb +27 -0
  63. data/spec/luchadeer_spec.rb +24 -0
  64. data/spec/spec_helper.rb +5 -0
  65. metadata +216 -0
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Concepts do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#concepts' do
7
+ let(:concept_id) { 1 }
8
+ let(:concept_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/concept/3015-#{concept_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, concept_path).to_return(body: '{ }')
12
+ client.concept("#{concept_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Concept' do
17
+ stub_request(:get, concept_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.concept("#{concept_id}")).to be_instance_of Luchadeer::Concept
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, concept_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.concept("#{concept_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Franchises do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#games' do
7
+ let(:franchise_id) { 1 }
8
+ let(:franchise_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/franchise/3025-#{franchise_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, franchise_path).to_return(body: '{ }')
12
+ client.franchise("#{franchise_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Franchise' do
17
+ stub_request(:get, franchise_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.franchise("#{franchise_id}")).to be_instance_of Luchadeer::Franchise
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, franchise_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.franchise("#{franchise_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Games do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#games' do
7
+ let(:game_id) { 1 }
8
+ let(:game_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/game/3030-#{game_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, game_path).to_return(body: '{ }')
12
+ client.game("#{game_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Game' do
17
+ stub_request(:get, game_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.game("#{game_id}")).to be_instance_of Luchadeer::Game
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, game_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.game("#{game_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Locations do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#Locations' do
7
+ let(:location_id) { 1 }
8
+ let(:location_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/location/3035-#{location_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, location_path).to_return(body: '{ }')
12
+ client.location("#{location_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Location' do
17
+ stub_request(:get, location_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.location("#{location_id}")).to be_instance_of Luchadeer::Location
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, location_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.location("#{location_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Objects do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#games' do
7
+ let(:object_id) { 1 }
8
+ let(:object_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/object/3055-#{object_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, object_path).to_return(body: '{ }')
12
+ client.object("#{object_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Object' do
17
+ stub_request(:get, object_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.object("#{object_id}")).to be_instance_of Luchadeer::Object
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, object_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.object("#{object_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::People do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#games' do
7
+ let(:person_id) { 1 }
8
+ let(:person_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/person/3040-#{person_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, person_path).to_return(body: '{ }')
12
+ client.person("#{person_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Object' do
17
+ stub_request(:get, person_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.person("#{person_id}")).to be_instance_of Luchadeer::Person
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, person_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.person("#{person_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API::Videos do
4
+ let(:client) { Luchadeer::Client.new }
5
+
6
+ describe '#games' do
7
+ let(:video_id) { 1 }
8
+ let(:video_path) { %r(#{Luchadeer::Client::GIANT_BOMB}/video/2300-#{video_id}) }
9
+
10
+ it 'requests the right url' do
11
+ stub = stub_request(:get, video_path).to_return(body: '{ }')
12
+ client.video("#{video_id}")
13
+ expect(stub).to have_been_requested
14
+ end
15
+
16
+ it 'returns a Luchadeer::Object' do
17
+ stub_request(:get, video_path).to_return(body: '{ "results": { "key": "value"}}')
18
+ expect(client.video("#{video_id}")).to be_instance_of Luchadeer::Video
19
+ end
20
+
21
+ it 'caches responses' do
22
+ stub_request(:get, video_path).to_return(body: '{ }')
23
+ expect(client).to receive :cache
24
+ client.video("#{video_id}")
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,101 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::API do
4
+ let(:client) { Luchadeer::Client.new }
5
+ let(:key) { 'Chie' }
6
+ let(:val) { 'Tomoe Gozen' }
7
+
8
+ describe '#cache' do
9
+ context 'when value exists for key' do
10
+ it 'returns the value for the given key' do
11
+ client.cache = { key => val }
12
+ expect(client.cache(key)).to eq val
13
+ end
14
+ end
15
+
16
+ context 'when value does not exist for key' do
17
+ context 'and no block is provided' do
18
+ it 'raises KeyError' do
19
+ expect { client.cache(key) }.to raise_error KeyError
20
+ end
21
+ end
22
+
23
+ context 'and block is provided' do
24
+ it 'assigns the result of the block to the given key' do
25
+ client.cache(key) { val }
26
+ expect(client.cache(key)).to eq val
27
+ end
28
+ end
29
+ end
30
+
31
+ context 'when refresh is true' do
32
+ let(:new_val) { 'Suzuka Gongen' }
33
+
34
+ it 'assigns the result of the block to the given key' do
35
+ client.cache(key) { val }
36
+ client.cache(key, true) { new_val }
37
+ expect(client.cache(key)).to eq new_val
38
+ end
39
+
40
+ context 'and no block is provided' do
41
+ it 'raises KeyError' do
42
+ expect { client.cache(key, true) }.to raise_error KeyError
43
+ end
44
+ end
45
+ end
46
+
47
+ describe '#fetch' do
48
+ it 'uses the cache' do
49
+ stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373))
50
+ .to_return(body:'{ }')
51
+
52
+ client.should_receive :cache
53
+ client.fetch('game-3030/21373')
54
+ end
55
+
56
+ context 'with a single result' do
57
+ before :each do
58
+ stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373))
59
+ .to_return(body:'{ "results": { "name": "Narukami" } }')
60
+ end
61
+
62
+ it 'returns an object of the provided class' do
63
+ expect(client.fetch('game-3030/21373', false, Luchadeer::Game))
64
+ .to be_instance_of Luchadeer::Game
65
+ end
66
+
67
+ it 'defaults to Luchadeer::Resource' do
68
+ expect(client.fetch('game-3030/21373')).to be_instance_of Luchadeer::Resource
69
+ end
70
+ end
71
+
72
+ context 'with an array of results' do
73
+ before :each do
74
+ stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373))
75
+ .to_return(body:'{ "results": [{ "name": "Narukami" }, { "name": "Hanamura"}] }')
76
+ end
77
+
78
+ it 'returns an array' do
79
+ expect(client.fetch('game-3030/21373')).to be_instance_of Array
80
+ end
81
+
82
+ it 'returns objects of the provided class' do
83
+ expect(client.fetch('game-3030/21373', false, Luchadeer::Game)[0])
84
+ .to be_instance_of Luchadeer::Game
85
+ expect(client.fetch('game-3030/21373', false, Luchadeer::Game)[1])
86
+ .to be_instance_of Luchadeer::Game
87
+ end
88
+ end
89
+
90
+ context 'with no results' do
91
+ it 'returns nil' do
92
+ stub_request(:get, %r(http://www.giantbomb.com/api/game-3030/21373))
93
+ .to_return(body:'{ }')
94
+
95
+ expect(client.fetch('game-3030/21373')).to be_nil
96
+ end
97
+ end
98
+ end
99
+ end
100
+
101
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::Character do
4
+
5
+ it 'is a resource' do
6
+ expect(described_class.new).to be_a Luchadeer::Resource
7
+ end
8
+
9
+ describe '.find' do
10
+ let(:client) { Luchadeer::Client.new }
11
+
12
+ before :each do
13
+ Luchadeer.client = client
14
+ end
15
+
16
+ it 'forwards to Client#character with arguments' do
17
+ expect(client).to receive(:character).with(1, true)
18
+ described_class.find(1, true)
19
+ end
20
+
21
+ it 'forwards to Client#character with default refresh' do
22
+ expect(client).to receive(:character).with(1, false)
23
+ described_class.find(1)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,54 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::Client do
4
+ let(:api_key) { 'luchadeer' }
5
+ let(:client) { described_class.new(api_key: api_key) }
6
+
7
+ describe '#initialize' do
8
+ it 'yields itself for configuration' do
9
+ expect { |b| described_class.new(&b) }.to yield_control.once
10
+ end
11
+ end
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
+ describe '#get' do
36
+ let(:url) { %r(http://laika.io) }
37
+
38
+ it 'makes a GET request' do
39
+ stub = stub_request(:get, url).to_return(body: '{ "asdf": "asdf" }')
40
+ client.get("http://laika.io")
41
+
42
+ expect(stub).to have_been_requested
43
+ end
44
+
45
+ it 'adds default parameters' do
46
+ stub = stub_request(:get, url).with(format: 'json', api_key: api_key)
47
+ .to_return(body: '{ "asdf": "asdf" }')
48
+
49
+ client.get("http://laika.io")
50
+ expect(stub).to have_been_requested
51
+ end
52
+ end
53
+
54
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::Company do
4
+
5
+ it 'is a resource' do
6
+ expect(described_class.new).to be_a Luchadeer::Resource
7
+ end
8
+
9
+ describe '.find' do
10
+ let(:client) { Luchadeer::Client.new }
11
+
12
+ before :each do
13
+ Luchadeer.client = client
14
+ end
15
+
16
+ it 'forwards to Client#company with arguments' do
17
+ expect(client).to receive(:company).with(1, true)
18
+ described_class.find(1, true)
19
+ end
20
+
21
+ it 'forwards to Client#company with default refresh' do
22
+ expect(client).to receive(:company).with(1, false)
23
+ described_class.find(1)
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Luchadeer::Concept do
4
+
5
+ it 'is a resource' do
6
+ expect(described_class.new).to be_a Luchadeer::Resource
7
+ end
8
+
9
+ describe '.find' do
10
+ let(:client) { Luchadeer::Client.new }
11
+
12
+ before :each do
13
+ Luchadeer.client = client
14
+ end
15
+
16
+ it 'forwards to Client#concept with arguments' do
17
+ expect(client).to receive(:concept).with(1, true)
18
+ described_class.find(1, true)
19
+ end
20
+
21
+ it 'forwards to Client#concept with default refresh' do
22
+ expect(client).to receive(:concept).with(1, false)
23
+ described_class.find(1)
24
+ end
25
+ end
26
+
27
+ end