luchadeer 0.1.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.
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
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 77d28c953c62036e898630d204bd3e630ecc90e5
4
+ data.tar.gz: 675625e43a2d925c7e1697d37ff5563a91536eb0
5
+ SHA512:
6
+ metadata.gz: 53d5e8f133ffabf11316572708618b7a937c374647b30d09ed0fd6ea142f8a99b8a2862cb4f9d8b1e27707f4f731c9ae8ad10a80ad7c76b86b72c4d28814990d
7
+ data.tar.gz: dc98a568a7fb9af7c92ddcac6b99e7744f0ceae2f9c34466484c4e5d91762f893a6c1d6632a728c044ac4bc978dab654d92bc4b881d9262945d07166a918031a
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ .DS_Store
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+
3
+ rvm:
4
+ - 2.0.0
5
+
6
+ script: bundle exec rspec
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in luchadeer.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,60 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ luchadeer (0.1.0)
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
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2014 Paul Friedman
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ 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, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,58 @@
1
+ # Luchadeer
2
+
3
+ [![Build Status](https://travis-ci.org/paulfri/luchadeer.png?branch=master)][build]
4
+ [![Coverage Status](https://coveralls.io/repos/paulfri/luchadeer/badge.png?branch=master)][coverage]
5
+ [![Code Climate](https://codeclimate.com/github/paulfri/luchadeer.png)][grade]
6
+
7
+ [build]: (https://travis-ci.org/paulfri/luchadeer)
8
+ [coverage]: https://coveralls.io/r/paulfri/luchadeer?branch=master
9
+ [grade]: https://codeclimate.com/github/paulfri/luchadeer
10
+
11
+ The bombingest Giant Bomb API client library for Ruby.
12
+
13
+ ## Features
14
+ 1. Fully unit-tested.
15
+ 2. Caches API responses.
16
+ 3. fully.recursive.dot.syntax, no random hash[:syntax] cutoff point
17
+ 4. Fetch full details for partial objects (e.g. embedded results) with object.detail.
18
+ 5. Thread-ready (thready?): no global or class state. Use convenience methods to use a default client per-thread, or use an alternate syntax for full control.
19
+
20
+ ## Configuration
21
+ Get your API key [here](http://www.giantbomb.com/api).
22
+
23
+ ```ruby
24
+ Luchadeer.configure(api_key: 'my_api_key') # default client for this thread
25
+ Luchadeer::Client.new(api_key: 'my_api_key')
26
+ ```
27
+
28
+ You can also pass a block to either method, and it will yield the client object to configure to your liking.
29
+
30
+ ```ruby
31
+ Luchadeer.configure do |client|
32
+ client.api_key = 'my_api_key'
33
+ end
34
+ ```
35
+
36
+ ## Supported resources
37
+ * game
38
+ * franchise
39
+ * character
40
+ * concept
41
+ * object
42
+ * location
43
+ * person
44
+ * company
45
+ * video
46
+
47
+ ## Usage
48
+
49
+ ```ruby
50
+ Luchadeer::Game.find(21373) # or...
51
+ my_client.game(21373) # => #<Luchadeer::Game name="Shin Megami Tensei: Persona 4" ...>
52
+ ```
53
+
54
+ ## TODO
55
+ 1. Add filtering to search.
56
+ 2. Add per-resource searching class methods on each resource object.
57
+ 3. Refactor the test suite with shared example groups.
58
+ 4. Make the caching layer more flexible - more options besides in-memory store. Add a null store, too.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/lib/luchadeer.rb ADDED
@@ -0,0 +1,32 @@
1
+ require 'luchadeer/version'
2
+
3
+ require 'luchadeer/api'
4
+ require 'luchadeer/client'
5
+ require 'luchadeer/error'
6
+ require 'luchadeer/search'
7
+
8
+ require 'luchadeer/character'
9
+ require 'luchadeer/company'
10
+ require 'luchadeer/concept'
11
+ require 'luchadeer/franchise'
12
+ require 'luchadeer/game'
13
+ require 'luchadeer/location'
14
+ require 'luchadeer/object'
15
+ require 'luchadeer/person'
16
+ require 'luchadeer/video'
17
+
18
+ module Luchadeer
19
+ class << self
20
+ def configure(opts = {}, &blk)
21
+ Luchadeer.client = Luchadeer::Client.new(opts, &blk)
22
+ end
23
+
24
+ def client
25
+ Thread.current[:luchadeer_client]
26
+ end
27
+
28
+ def client=(new_client)
29
+ Thread.current[:luchadeer_client] = new_client
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,51 @@
1
+ require 'luchadeer/api/characters'
2
+ require 'luchadeer/api/companies'
3
+ require 'luchadeer/api/concepts'
4
+ require 'luchadeer/api/franchises'
5
+ require 'luchadeer/api/games'
6
+ require 'luchadeer/api/locations'
7
+ require 'luchadeer/api/objects'
8
+ require 'luchadeer/api/people'
9
+ require 'luchadeer/api/videos'
10
+
11
+ module Luchadeer
12
+ module API
13
+ API_MODULES = [
14
+ Luchadeer::API::Characters,
15
+ Luchadeer::API::Companies,
16
+ Luchadeer::API::Concepts,
17
+ Luchadeer::API::Franchises,
18
+ Luchadeer::API::Games,
19
+ Luchadeer::API::Locations,
20
+ Luchadeer::API::Objects,
21
+ Luchadeer::API::People,
22
+ Luchadeer::API::Videos
23
+ ]
24
+
25
+ API_MODULES.each do |mod|
26
+ include mod
27
+ end
28
+
29
+ attr_writer :cache
30
+
31
+ def cache(key, refresh = false, &blk)
32
+ @cache ||= {}
33
+ @cache.delete(key) if refresh
34
+
35
+ if block_given?
36
+ @cache[key] || (@cache[key] = yield)
37
+ else
38
+ @cache.fetch(key)
39
+ end
40
+ end
41
+
42
+ def fetch(path, refresh = false, klass = Luchadeer::Resource)
43
+ return unless results = cache(path, refresh) do
44
+ get(path).body[:results]
45
+ end
46
+
47
+ results.is_a?(Array) ? results.map { |r| klass.new(r) } : klass.new(results)
48
+ end
49
+
50
+ end
51
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Characters
4
+
5
+ def character(id, refresh = false)
6
+ fetch("character/3005-#{id}", refresh, Luchadeer::Character)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Companies
4
+
5
+ def company(id, refresh = false)
6
+ fetch("company/3010-#{id}", refresh, Luchadeer::Company)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Concepts
4
+
5
+ def concept(id, refresh = false)
6
+ fetch("concept/3015-#{id}", refresh, Luchadeer::Concept)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Franchises
4
+
5
+ def franchise(id, refresh = false)
6
+ fetch("franchise/3025-#{id}", refresh, Luchadeer::Franchise)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Games
4
+
5
+ def game(id, refresh = false)
6
+ fetch("game/3030-#{id}", refresh, Luchadeer::Game)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Locations
4
+
5
+ def location(id, refresh = false)
6
+ fetch("location/3035-#{id}", refresh, Luchadeer::Location)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Objects
4
+
5
+ def object(id, refresh = false)
6
+ fetch("object/3055-#{id}", refresh, Luchadeer::Object)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module People
4
+
5
+ def person(id, refresh = false)
6
+ fetch("person/3040-#{id}", refresh, Luchadeer::Person)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ module Luchadeer
2
+ module API
3
+ module Videos
4
+
5
+ def video(id, refresh = false)
6
+ fetch("video/2300-#{id}", refresh, Luchadeer::Video)
7
+ end
8
+
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,13 @@
1
+ require 'luchadeer/resource'
2
+
3
+ module Luchadeer
4
+ class Character < Resource
5
+
6
+ class << self
7
+ def find(id, refresh = false)
8
+ Luchadeer.client.character(id, refresh)
9
+ end
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,73 @@
1
+ require 'faraday'
2
+ require 'luchadeer/middleware/follow_redirects'
3
+ require 'luchadeer/middleware/parse_json'
4
+ require 'luchadeer/middleware/parse_http_error'
5
+ require 'luchadeer/middleware/parse_api_error'
6
+
7
+ module Luchadeer
8
+ class Client
9
+ include Luchadeer::API
10
+
11
+ attr_accessor :api_key
12
+ GIANT_BOMB = 'http://www.giantbomb.com/api'
13
+
14
+ def initialize(opts = {})
15
+ opts.each do |key, value|
16
+ send(:"#{key}=", value)
17
+ end
18
+
19
+ yield self if block_given?
20
+ end
21
+
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
+ def get(path, params = {})
31
+ request(:get, path, params)
32
+ end
33
+
34
+ private
35
+
36
+ def connection
37
+ @_connection ||= Faraday.new(GIANT_BOMB, connection_options)
38
+ end
39
+
40
+ def connection_options
41
+ {
42
+ builder: middleware,
43
+ headers: {
44
+ accept: 'application/json',
45
+ user_agent: user_agent,
46
+ }
47
+ }
48
+ end
49
+
50
+ def middleware
51
+ Faraday::RackBuilder.new do |builder|
52
+ # order is important
53
+ builder.response :parse_api_error
54
+ builder.response :parse_json
55
+ builder.response :parse_http_error
56
+ builder.response :follow_redirects
57
+
58
+ builder.adapter :net_http
59
+ end
60
+ end
61
+
62
+ def request(method, path, params = {})
63
+ connection.send(method.to_sym, path, params.merge(default_params))
64
+ # rescue => e
65
+ # raise Luchadeer::Error.new(e)
66
+ end
67
+
68
+ def default_params
69
+ { format: 'json', api_key: api_key }
70
+ end
71
+
72
+ end
73
+ end