giant_bomb_api 0.5.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.
Files changed (61) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +3 -0
  3. data/.rspec +1 -0
  4. data/.rubocop.yml +6 -0
  5. data/.ruby-gemset +1 -0
  6. data/.ruby-version +1 -0
  7. data/Gemfile +2 -0
  8. data/Gemfile.lock +81 -0
  9. data/LICENSE +22 -0
  10. data/README.md +155 -0
  11. data/Rakefile +7 -0
  12. data/circle.yml +6 -0
  13. data/giant_bomb_api.gemspec +31 -0
  14. data/lib/giant_bomb_api.rb +38 -0
  15. data/lib/giant_bomb_api/client.rb +54 -0
  16. data/lib/giant_bomb_api/collection_resource.rb +40 -0
  17. data/lib/giant_bomb_api/exception.rb +5 -0
  18. data/lib/giant_bomb_api/exception/api_error.rb +14 -0
  19. data/lib/giant_bomb_api/request.rb +10 -0
  20. data/lib/giant_bomb_api/request/collection.rb +36 -0
  21. data/lib/giant_bomb_api/request/detail.rb +9 -0
  22. data/lib/giant_bomb_api/request/search.rb +18 -0
  23. data/lib/giant_bomb_api/resource.rb +34 -0
  24. data/lib/giant_bomb_api/resource/accessory.rb +10 -0
  25. data/lib/giant_bomb_api/resource/character.rb +24 -0
  26. data/lib/giant_bomb_api/resource/chat.rb +11 -0
  27. data/lib/giant_bomb_api/resource/company.rb +32 -0
  28. data/lib/giant_bomb_api/resource/concept.rb +21 -0
  29. data/lib/giant_bomb_api/resource/factory.rb +36 -0
  30. data/lib/giant_bomb_api/resource/franchise.rb +17 -0
  31. data/lib/giant_bomb_api/resource/game.rb +40 -0
  32. data/lib/giant_bomb_api/resource/game_rating.rb +8 -0
  33. data/lib/giant_bomb_api/resource/genre.rb +10 -0
  34. data/lib/giant_bomb_api/resource/image.rb +12 -0
  35. data/lib/giant_bomb_api/resource/location.rb +12 -0
  36. data/lib/giant_bomb_api/resource/object.rb +20 -0
  37. data/lib/giant_bomb_api/resource/person.rb +24 -0
  38. data/lib/giant_bomb_api/resource/platform.rb +16 -0
  39. data/lib/giant_bomb_api/resource/promo.rb +11 -0
  40. data/lib/giant_bomb_api/resource/rating_board.rb +11 -0
  41. data/lib/giant_bomb_api/resource/region.rb +11 -0
  42. data/lib/giant_bomb_api/resource/release.rb +24 -0
  43. data/lib/giant_bomb_api/resource/review.rb +15 -0
  44. data/lib/giant_bomb_api/resource/theme.rb +7 -0
  45. data/lib/giant_bomb_api/resource/user_review.rb +11 -0
  46. data/lib/giant_bomb_api/resource/video.rb +17 -0
  47. data/lib/giant_bomb_api/resource/video_type.rb +8 -0
  48. data/lib/giant_bomb_api/resource_value_setter.rb +29 -0
  49. data/lib/giant_bomb_api/response.rb +17 -0
  50. data/spec/fixtures/detail-response.json +740 -0
  51. data/spec/fixtures/search-response.json +59 -0
  52. data/spec/lib/collection_resource_spec.rb +76 -0
  53. data/spec/lib/giant_bomb_api_spec.rb +56 -0
  54. data/spec/lib/request/collection_spec.rb +32 -0
  55. data/spec/lib/request/search_spec.rb +38 -0
  56. data/spec/lib/resource/factory_spec.rb +35 -0
  57. data/spec/lib/resource/game_spec.rb +28 -0
  58. data/spec/lib/resource_spec.rb +37 -0
  59. data/spec/lib/response_spec.rb +102 -0
  60. data/spec/spec_helper.rb +15 -0
  61. metadata +241 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6fd8d486158ad9852607a5d5449d7c178231d240
4
+ data.tar.gz: 6db2a32b7bb1b96b9c0b2558f049f777aba75347
5
+ SHA512:
6
+ metadata.gz: e4c734f8103a813df3ed478f91066c14639282e48d3229b6274c01ad594e990455bfcb14b546d30f02095c6eeb06fe417b1373a7feaaf3245e53e557347e21fc
7
+ data.tar.gz: 148e746b6817d37b70cd31511c2a9419169dec0d18c781198ef5015a984fd6bdb92907da0c725e9a7a1e7bcad9ef830e6f907dcdfa9fab73c0558a564d78ee26
data/.gitignore ADDED
@@ -0,0 +1,3 @@
1
+ bin
2
+ coverage
3
+ *.gem
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.rubocop.yml ADDED
@@ -0,0 +1,6 @@
1
+ LineLength:
2
+ Max: 999
3
+ Documentation:
4
+ Enabled: false
5
+ StringLiterals:
6
+ Enabled: false
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ giant_bomb_api
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.0
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source "https://rubygems.org"
2
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,81 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ giant_bomb_api (0.1)
5
+ activesupport
6
+ faraday
7
+ faraday_middleware
8
+ require_all
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ activesupport (4.2.4)
14
+ i18n (~> 0.7)
15
+ json (~> 1.7, >= 1.7.7)
16
+ minitest (~> 5.1)
17
+ thread_safe (~> 0.3, >= 0.3.4)
18
+ tzinfo (~> 1.1)
19
+ byebug (3.5.1)
20
+ columnize (~> 0.8)
21
+ debugger-linecache (~> 1.2)
22
+ slop (~> 3.6)
23
+ codeclimate-test-reporter (0.4.5)
24
+ simplecov (>= 0.7.1, < 1.0.0)
25
+ coderay (1.1.0)
26
+ columnize (0.9.0)
27
+ debugger-linecache (1.2.0)
28
+ diff-lcs (1.2.5)
29
+ docile (1.1.5)
30
+ faraday (0.9.1)
31
+ multipart-post (>= 1.2, < 3)
32
+ faraday_middleware (0.10.0)
33
+ faraday (>= 0.7.4, < 0.10)
34
+ i18n (0.7.0)
35
+ json (1.8.3)
36
+ method_source (0.8.2)
37
+ minitest (5.8.0)
38
+ multi_json (1.10.1)
39
+ multipart-post (2.0.0)
40
+ pry (0.10.1)
41
+ coderay (~> 1.1.0)
42
+ method_source (~> 0.8.1)
43
+ slop (~> 3.4)
44
+ pry-byebug (3.0.1)
45
+ byebug (~> 3.4)
46
+ pry (~> 0.10)
47
+ rake (10.1.1)
48
+ require_all (1.3.2)
49
+ rspec (3.1.0)
50
+ rspec-core (~> 3.1.0)
51
+ rspec-expectations (~> 3.1.0)
52
+ rspec-mocks (~> 3.1.0)
53
+ rspec-core (3.1.7)
54
+ rspec-support (~> 3.1.0)
55
+ rspec-expectations (3.1.2)
56
+ diff-lcs (>= 1.2.0, < 2.0)
57
+ rspec-support (~> 3.1.0)
58
+ rspec-mocks (3.1.3)
59
+ rspec-support (~> 3.1.0)
60
+ rspec-support (3.1.2)
61
+ simplecov (0.9.1)
62
+ docile (~> 1.1.0)
63
+ multi_json (~> 1.0)
64
+ simplecov-html (~> 0.8.0)
65
+ simplecov-html (0.8.0)
66
+ slop (3.6.0)
67
+ thread_safe (0.3.5)
68
+ timecop (0.7.1)
69
+ tzinfo (1.2.2)
70
+ thread_safe (~> 0.1)
71
+
72
+ PLATFORMS
73
+ ruby
74
+
75
+ DEPENDENCIES
76
+ codeclimate-test-reporter
77
+ giant_bomb_api!
78
+ pry-byebug
79
+ rake (~> 10.1.0)
80
+ rspec (~> 3.0)
81
+ timecop
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Tim Adler
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, 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,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
data/README.md ADDED
@@ -0,0 +1,155 @@
1
+ # Giant Bomb API
2
+
3
+ An unofficial ruby wrapper for the [Giantbomb API](http://api.giantbomb.com). An API that provides structured data about videogames. You should inform yourself about the endpoints at http://www.giantbomb.com/api/documentation .
4
+
5
+ This gem aims to provide access to most endpoints on the API. You'll be able to **search**, **filter** and page throught most of them. See further below on what is supported.
6
+
7
+ **Contributors are welcome**. Please contact [@toadle](https://github.com/toadle).
8
+
9
+ [![Code Climate](https://codeclimate.com/github/toadle/giant_bomb_api/badges/gpa.svg)](https://codeclimate.com/github/toadle/giant_bomb_api)
10
+ [![Test Coverage](https://codeclimate.com/github/toadle/giant_bomb_api/badges/coverage.svg)](https://codeclimate.com/github/toadle/giant_bomb_api/coverage)
11
+ [![Circle CI](https://circleci.com/gh/toadle/giant_bomb_api/tree/dev.svg?style=svg)](https://circleci.com/gh/toadle/giant_bomb_api/tree/dev)
12
+
13
+ ## Changelog
14
+ * **2015-09-19**: Initial release as 0.5
15
+
16
+ # Installation
17
+
18
+ As you'd expect. Nothing special here:
19
+
20
+ ```
21
+ gem install giant_bomb_api
22
+ ```
23
+
24
+ or in your `Gemfile`
25
+
26
+ ```
27
+ gem giant_bomb_api
28
+ ```
29
+
30
+ # How to use
31
+
32
+ ## Configuration
33
+
34
+ Before you use GiantBombApi you need to configure it:
35
+ ```
36
+ GiantBombApi.configure do |config|
37
+ config.api_key = "your api-key"
38
+ end
39
+ ```
40
+
41
+ ## Usage
42
+
43
+ There is several ways to query the GiantBomb-Database.
44
+
45
+ ### General search
46
+ ```
47
+ GiantBombApi.search("your query")
48
+ ```
49
+ It will return a list of games that match you query.
50
+
51
+ If you want to be more specific, you can create your own search-request:
52
+
53
+ ```
54
+ GiantBombApi::Request::Search.new("your query", resources: [array of GiantBombApi::Resource-classes], limit: 100, page: 1)
55
+ ```
56
+
57
+ e.g.
58
+
59
+ ```
60
+ GiantBombApi::Request::Search.new("spelunky", resources: [GiantBombApi::Resource::Game], limit: 100, page: 1)
61
+ ```
62
+
63
+ or
64
+
65
+ ```
66
+ GiantBombApi::Request::Search.new("mario", resources: [GiantBombApi::Resource::Game, GiantBombApi::Resource::Character], limit: 100, page: 1)
67
+ ```
68
+
69
+ your can then use `GiantBombApi.client` to send the request like:
70
+
71
+ ```
72
+ GiantBombApi.client.send_request(<your request>)
73
+ ```
74
+
75
+ This returns a `GiantBombApi::Response` where your can find your results in `response.results`. This might be a collection of things or just one object.
76
+
77
+
78
+ ### Getting details
79
+
80
+ If you want a special object by ID you can just do something like:
81
+
82
+ ```
83
+ GiantBombApi::Resource::Game.find(id)
84
+ ```
85
+
86
+ Available resources are:
87
+
88
+ ```
89
+ - GiantBombApi::Resource::Accessory
90
+ - GiantBombApi::Resource::Character
91
+ - GiantBombApi::Resource::Chat
92
+ - GiantBombApi::Resource::Company
93
+ - GiantBombApi::Resource::Concept
94
+ - GiantBombApi::Resource::Franchise
95
+ - GiantBombApi::Resource::Game
96
+ - GiantBombApi::Resource::GameRating
97
+ - GiantBombApi::Resource::Genre
98
+ - GiantBombApi::Resource::Location
99
+ - GiantBombApi::Resource::Object
100
+ - GiantBombApi::Resource::Person
101
+ - GiantBombApi::Resource::Platform
102
+ - GiantBombApi::Resource::Promo
103
+ - GiantBombApi::Resource::RatingBoard
104
+ - GiantBombApi::Resource::Region
105
+ - GiantBombApi::Resource::Release
106
+ - GiantBombApi::Resource::Review
107
+ - GiantBombApi::Resource::Theme
108
+ - GiantBombApi::Resource::UserReview
109
+ - GiantBombApi::Resource::Video
110
+ - GiantBombApi::Resource::VideoType
111
+ ```
112
+
113
+ ### Requesting collections
114
+
115
+ You can also directly query a resource that has a collection-endpoint.
116
+
117
+ This is available for all resources that the [Giantbomb API](http://www.giantbomb.com/api/documentation) offers a 'collection' for. e.g. `game` and `games`or `character` and `characters`.
118
+
119
+ e.g. all:
120
+
121
+ ```
122
+ GiantBombApi::Resource::Game.all
123
+ ```
124
+
125
+ this call supports optional sorting, e.g.:
126
+
127
+ ```
128
+ GiantBombApi::Resource::Game.all(sort: { name: :desc })
129
+ ```
130
+
131
+ if you want to get more detailed your can do:
132
+
133
+ ```
134
+ GiantBombApi::Resource::Game.where(name: "spelunky", aliases: "something", sort: { name: :desc }, limit: 10, offset: 0)
135
+ ```
136
+
137
+
138
+ ## Response
139
+
140
+ Every API-request will always return a `GiantBombApi::Response`-object that has the following attributes:
141
+
142
+ - `limit`: The limit that applied
143
+ - `offset`: The offset that applied
144
+ - `number_of_page_results`: Guess!
145
+ - `number_of_total_results`: Meeeh...
146
+ - `results`: An array of stuff that you were looking for ;-)
147
+
148
+ For everything else I urge you to look through the code.
149
+
150
+ ## Feedback
151
+ Feedback and pull-request are always welcome.
152
+ You can find the author via http://toadle.me
153
+
154
+ ## License
155
+ The giant_bomb_api-gem is released under the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler"
2
+ require 'rspec/core/rake_task'
3
+
4
+ task :default => :spec
5
+
6
+ Bundler::GemHelper.install_tasks
7
+ RSpec::Core::RakeTask.new :spec
data/circle.yml ADDED
@@ -0,0 +1,6 @@
1
+ machine:
2
+ environment:
3
+ CODECLIMATE_REPO_TOKEN: "1fdcaf004abc7657d5aeb234af9f3da6419b07aaad7b78ea5d837bc9da2b78b9"
4
+ timezone: "Europe/Berlin"
5
+ ruby:
6
+ version: "2.2.2"
@@ -0,0 +1,31 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "giant_bomb_api"
3
+ s.version = "0.5.1"
4
+ s.default_executable = "giantbomb"
5
+
6
+ s.authors = ["Tim Adler"]
7
+ s.date = %q{2015-09-19}
8
+ s.description = %q{An unofficial ruby wrapper for the Giantbomb API (http://api.giantbomb.com). An API that provides structured data about videogames.}
9
+ s.summary = s.description
10
+ s.email = %q{mail (at) toadle (dot) me}
11
+ s.license = "MIT"
12
+
13
+ s.files = `git ls-files`.split("\n")
14
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
15
+ s.homepage = %q{https://github.com/toadle/giant_bomb_api}
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = %q{1.6.2}
18
+
19
+ s.add_dependency 'faraday'
20
+ s.add_dependency 'faraday_middleware'
21
+ s.add_dependency 'activesupport'
22
+ s.add_dependency 'require_all'
23
+
24
+ s.add_development_dependency 'rake', '~> 10.1.0'
25
+ s.add_development_dependency 'rspec', '~> 3.0'
26
+ s.add_development_dependency 'pry-byebug'
27
+ s.add_development_dependency 'timecop'
28
+ s.add_development_dependency 'codeclimate-test-reporter'
29
+
30
+ end
31
+
@@ -0,0 +1,38 @@
1
+ require 'active_support/all'
2
+ require 'require_all'
3
+
4
+ require_rel 'giant_bomb_api/**/*.rb'
5
+
6
+ module GiantBombApi
7
+
8
+ class Configuration
9
+ attr_accessor :api_key
10
+ end
11
+
12
+ class << self
13
+ attr_accessor :configuration
14
+ end
15
+
16
+ def self.raise_error(message)
17
+ raise Exception.new message
18
+ end
19
+
20
+ def self.configure
21
+ self.configuration ||= Configuration.new
22
+ yield(configuration)
23
+
24
+ @@client = nil
25
+ end
26
+
27
+ def self.search(query)
28
+ client.send_request(Request::Search.new(query))
29
+ end
30
+
31
+ def self.client
32
+ raise_error "Configure GiantBombApi-module before using" if configuration.nil?
33
+ raise_error "Configure 'api_key' first" if configuration.api_key.nil?
34
+
35
+ @@client ||= GiantBombApi::Client.new(api_key: configuration.api_key)
36
+ end
37
+
38
+ end
@@ -0,0 +1,54 @@
1
+ require 'digest'
2
+ require 'uri'
3
+ require 'faraday'
4
+ require 'faraday_middleware'
5
+ require 'json'
6
+
7
+ module GiantBombApi
8
+ class Client
9
+ attr_accessor :api_key
10
+
11
+ API_URL = 'http://api.giantbomb.com'
12
+
13
+ def initialize(api_key: nil, options: {})
14
+ @api_key = api_key
15
+ @options = options
16
+ end
17
+
18
+ def send_request(giant_bomb_api_request)
19
+ connection = Faraday.new(url: API_URL) do |faraday|
20
+ faraday.request :url_encoded
21
+ faraday.use FaradayMiddleware::FollowRedirects
22
+ faraday.adapter Faraday.default_adapter
23
+ end
24
+
25
+ response = connection.get do |req|
26
+ req.url giant_bomb_api_request.end_point
27
+ req.options[:timeout] = 5
28
+ req.options[:open_timeout] = 2
29
+ req.params = giant_bomb_api_request.params.merge(format: 'json', api_key: api_key)
30
+ end
31
+
32
+ response_json = JSON.parse(response.body)
33
+
34
+ if(response_json["status_code"] == 1)
35
+ response = handle_success_response(response_json)
36
+ response.request = giant_bomb_api_request
37
+ response
38
+ else
39
+ handle_error_response(response_json)
40
+ end
41
+ end
42
+
43
+ private
44
+
45
+ def handle_success_response(response_json)
46
+ GiantBombApi::Response.new response_json
47
+ end
48
+
49
+ def handle_error_response(response_json)
50
+ raise Exception::ApiError.new(response_json["status_code"], response_json["error"])
51
+ end
52
+
53
+ end
54
+ end
@@ -0,0 +1,40 @@
1
+ module GiantBombApi
2
+ module CollectionResource
3
+
4
+ def self.extended(base)
5
+ base.extend Resource
6
+ end
7
+
8
+ def collection_resource_name(collection_resource_name = nil)
9
+ if collection_resource_name.present?
10
+ self.instance_variable_set("@collection_resource_name", collection_resource_name)
11
+ end
12
+ self.instance_variable_get("@collection_resource_name") || self.resource_name.pluralize
13
+ end
14
+
15
+ def all(sort = {})
16
+ where(sort: sort)
17
+ end
18
+
19
+ def find(id, params = {})
20
+ GiantBombApi.client.send_request(Request::Detail.new(resource_name, id, params))
21
+ end
22
+
23
+ def where(params = {})
24
+ return GiantBombApi.client.send_request(Request::Collection.new(self)) unless params.present?
25
+
26
+ sort = params[:sort]
27
+ limit = params[:limit]
28
+ offset = params[:offset]
29
+
30
+ args = {}
31
+ args[:filter] = params.reject {|key,value| %i(sort limit offset).include?(key) }
32
+ args[:sort] = sort if sort.present?
33
+ args[:limit] = limit if limit.present?
34
+ args[:offset] = offset if offset.present?
35
+
36
+ GiantBombApi.client.send_request(Request::Collection.new(self, args))
37
+ end
38
+
39
+ end
40
+ end