igdb 0.2.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circle.yml +3 -0
- data/.gitignore +2 -0
- data/.travis.yml +3 -0
- data/README.md +36 -17
- data/igdb.gemspec +4 -6
- data/lib/igdb.rb +1 -2
- data/lib/igdb/configuration/api.rb +27 -0
- data/lib/igdb/exceptions.rb +11 -0
- data/lib/igdb/models/api_resource.rb +14 -0
- data/lib/igdb/models/company.rb +2 -0
- data/lib/igdb/models/game.rb +27 -0
- data/lib/igdb/models/game_company.rb +2 -0
- data/lib/igdb/models/game_genre.rb +2 -0
- data/lib/igdb/models/game_release_date.rb +2 -0
- data/lib/igdb/models/game_screenshot.rb +2 -0
- data/lib/igdb/models/game_theme.rb +2 -0
- data/lib/igdb/models/game_video.rb +2 -0
- data/lib/igdb/models/person.rb +19 -0
- data/lib/igdb/models/shop.rb +2 -0
- data/lib/igdb/representers/game_company_representer.rb +7 -0
- data/lib/igdb/representers/game_genre_representer.rb +5 -0
- data/lib/igdb/representers/game_release_date_representer.rb +6 -0
- data/lib/igdb/representers/game_representer.rb +26 -0
- data/lib/igdb/representers/game_screenshot_representer.rb +6 -0
- data/lib/igdb/representers/game_theme_representer.rb +5 -0
- data/lib/igdb/representers/game_video_representer.rb +6 -0
- data/lib/igdb/representers/person_representer.rb +11 -0
- data/lib/igdb/requester.rb +56 -0
- data/lib/igdb/version.rb +1 -1
- metadata +32 -38
- data/CODE_OF_CONDUCT.md +0 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 20fabf6dcdaace6c88808c75eef38417a958de60
|
4
|
+
data.tar.gz: 112cd37e00140a5bb8d5fcb9934ecbc097ea1327
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 91fa09829edf14034623f97afefccdef77082664b52cfe2ce0176a2d72b10eeb1685847e8ffbdb3368c21bf3bf97212a46aa851d11e86bf3d14f3edcbb4c5203
|
7
|
+
data.tar.gz: 78c1275eef6a9281f034dc59e02862f0c678301ce4d85dc1cd025c2aee126ea4064f6d6eb2bed3628c0f631da1d39663a3c0c6b43f72166b0241d92ab78d5f13
|
data/.circle.yml
ADDED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,34 +1,53 @@
|
|
1
|
-
#
|
1
|
+
# IGDB: Internet Game Database
|
2
|
+
[![Build Status](https://travis-ci.org/ahmetabdi/igdb.svg)](https://travis-ci.org/ahmetabdi/igdb)
|
3
|
+
[![Code Climate](https://codeclimate.com/github/ahmetabdi/igdb/badges/gpa.svg)](https://codeclimate.com/github/ahmetabdi/igdb)
|
4
|
+
[![Test Coverage](https://codeclimate.com/github/ahmetabdi/igdb/badges/coverage.svg)](https://codeclimate.com/github/ahmetabdi/igdb/coverage)
|
5
|
+
[![Gem Version](https://badge.fury.io/rb/igdb.svg)](http://badge.fury.io/rb/igdb)
|
6
|
+
[![Dependency Status](https://gemnasium.com/ahmetabdi/igdb.svg)](https://gemnasium.com/ahmetabdi/igdb)
|
2
7
|
|
3
|
-
|
8
|
+
## Installation
|
9
|
+
$ gem install igdb
|
4
10
|
|
5
|
-
|
11
|
+
## Usage
|
6
12
|
|
7
|
-
|
13
|
+
##### Connect
|
8
14
|
|
9
|
-
|
15
|
+
$ Igdb.connect('api_key')
|
10
16
|
|
11
|
-
|
12
|
-
|
13
|
-
```
|
17
|
+
##### Game
|
18
|
+
Find game by ID
|
14
19
|
|
15
|
-
|
20
|
+
$ Igdb::Game.find(1971)
|
16
21
|
|
17
|
-
|
22
|
+
Search for a game
|
18
23
|
|
19
|
-
|
24
|
+
$ Igdb::Game.search(query: 'batman')
|
20
25
|
|
21
|
-
|
26
|
+
Return the number of games in the database
|
22
27
|
|
23
|
-
|
28
|
+
$ Igdb::Game.meta
|
29
|
+
|
30
|
+
Return a list of all games with an offset and/or limit
|
31
|
+
|
32
|
+
$ Igdb::Game.all
|
33
|
+
$ Igdb::Game.all(limit: 10) # Limit to 10 results - Default 100
|
34
|
+
$ Igdb::Game.all(offset: 5) # Offset result starting at 5th - Default 0
|
35
|
+
|
36
|
+
##### Person
|
37
|
+
Find person by ID or name
|
38
|
+
|
39
|
+
$ Igdb::Person.find(4)
|
40
|
+
$ Igdb::Person.find('derek-watts')
|
24
41
|
|
25
|
-
|
42
|
+
Return the number of people in the database
|
26
43
|
|
27
|
-
|
44
|
+
$ Igdb::Person.meta
|
28
45
|
|
29
|
-
|
46
|
+
Return a list of all games with an offset and/or limit
|
30
47
|
|
31
|
-
|
48
|
+
$ Igdb::Person.all
|
49
|
+
$ Igdb::Person.all(limit: 10) # Limit to 10 results - Default 100
|
50
|
+
$ Igdb::Person.all(offset: 5) # Offset result starting at 5th - Default 0
|
32
51
|
|
33
52
|
## Contributing
|
34
53
|
|
data/igdb.gemspec
CHANGED
@@ -19,18 +19,16 @@ Gem::Specification.new do |spec|
|
|
19
19
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
20
|
spec.require_paths = ["lib"]
|
21
21
|
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
22
|
+
spec.add_development_dependency 'bundler', "~> 1.9"
|
23
|
+
spec.add_development_dependency 'rake', "~> 10.0"
|
24
24
|
spec.add_development_dependency 'rspec'
|
25
|
-
spec.add_development_dependency 'byebug'
|
26
|
-
spec.add_development_dependency 'guard'
|
27
25
|
spec.add_development_dependency 'fuubar'
|
28
|
-
spec.add_development_dependency 'guard-rspec'
|
29
26
|
spec.add_development_dependency 'vcr'
|
30
27
|
spec.add_development_dependency 'webmock'
|
28
|
+
spec.add_development_dependency 'codeclimate-test-reporter'
|
31
29
|
|
32
30
|
spec.add_runtime_dependency 'representable'
|
33
31
|
spec.add_runtime_dependency 'multi_json'
|
34
|
-
spec.add_runtime_dependency
|
32
|
+
spec.add_runtime_dependency 'rest-client'
|
35
33
|
spec.add_runtime_dependency 'require_all'
|
36
34
|
end
|
data/lib/igdb.rb
CHANGED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Igdb::Configuration
|
4
|
+
class Api
|
5
|
+
include Singleton
|
6
|
+
|
7
|
+
attr_reader :base_url, :version, :api_key
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
self.base_url = "https://www.igdb.com/api/v1/".freeze
|
11
|
+
self.version = 1.freeze
|
12
|
+
end
|
13
|
+
|
14
|
+
def connect(api_key)
|
15
|
+
@api_key = api_key
|
16
|
+
end
|
17
|
+
|
18
|
+
def url_for(action, params={})
|
19
|
+
url = URI.join(base_url, action)
|
20
|
+
url.query = URI.encode_www_form(params) if params
|
21
|
+
url.to_s
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
attr_writer :base_url, :api_key, :version, :oauth_url
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'representable/json'
|
2
|
+
class Igdb::ApiResource < OpenStruct
|
3
|
+
|
4
|
+
private
|
5
|
+
def self.build_single_resource(response, representer)
|
6
|
+
self.new.extend(representer).from_hash(response)
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.build_collection(response, representer)
|
10
|
+
response.reduce([]) do |resources, response|
|
11
|
+
resources << self.new.extend(representer).from_hash(response)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class Igdb::Game < Igdb::ApiResource
|
2
|
+
|
3
|
+
def self.meta
|
4
|
+
build_single_resource(Igdb::Requester.get("games/meta"), GameRepresenter).size
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.find(id)
|
8
|
+
build_single_resource(Igdb::Requester.get("games/#{id}")['game'], GameRepresenter)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.search(opts={})
|
12
|
+
params = Hash.new.tap do |hash|
|
13
|
+
hash['q'] = opts[:query] if opts[:query]
|
14
|
+
hash['filters'] = opts[:filters] if opts[:filters]
|
15
|
+
end
|
16
|
+
build_collection(Igdb::Requester.get("games/search", params)['games'], GameRepresenter)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.all(opts={})
|
20
|
+
params = Hash.new.tap do |hash|
|
21
|
+
hash['offset'] = opts[:offset] || 0
|
22
|
+
hash['limit'] = opts[:limit] || 100
|
23
|
+
end
|
24
|
+
build_collection(Igdb::Requester.get("games", params)['games'], GameRepresenter)
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
class Igdb::Person < Igdb::ApiResource
|
2
|
+
|
3
|
+
def self.meta
|
4
|
+
build_single_resource(Igdb::Requester.get('people/meta'), PersonRepresenter).size
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.find(id)
|
8
|
+
build_single_resource(Igdb::Requester.get("people/#{id}")['person'], PersonRepresenter)
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.all(opts={})
|
12
|
+
params = Hash.new.tap do |hash|
|
13
|
+
hash['offset'] = opts[:offset] || 0
|
14
|
+
hash['limit'] = opts[:limit] || 100
|
15
|
+
end
|
16
|
+
build_collection(Igdb::Requester.get("people", params)['people'], PersonRepresenter)
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module GameRepresenter
|
2
|
+
include Representable::JSON
|
3
|
+
|
4
|
+
property :id # The id of the game.
|
5
|
+
property :name # The name of the game.
|
6
|
+
property :slug # Not documented in V1 API
|
7
|
+
property :summary # Not documented in V1 API
|
8
|
+
property :alternative_name # The alternative name of the game.
|
9
|
+
property :rating # The rating of the game.
|
10
|
+
property :platform_name # The platform name.
|
11
|
+
property :release_date # Release date of the game.
|
12
|
+
property :developer # True if the company is the developer of the game.
|
13
|
+
property :publisher # True if the company is the publisher of the game.
|
14
|
+
property :name # The name of the company.
|
15
|
+
property :cover # The cover image of the game.
|
16
|
+
property :subtitle # The subtitle of the screenshot.
|
17
|
+
property :src # The source of the image in the thumbnail format.
|
18
|
+
property :size # The number of games in the database.
|
19
|
+
|
20
|
+
collection :release_dates, extend: GameReleaseDateRespresenter, class: Igdb::GameReleaseDate # The release dates of the game.
|
21
|
+
collection :screenshots, extend: GameScreenshotRepresenter, class: Igdb::GameScreenshot # The list of screenshots of the game.
|
22
|
+
collection :videos, extend: GameVideoRepresenter, class: Igdb::GameVideo # Not documented in v1 API
|
23
|
+
collection :genres, extend: GameGenreRepresenter, class: Igdb::GameGenre # Not documented in v1 API
|
24
|
+
collection :themes, extend: GameThemeRepresenter, class: Igdb::GameTheme # Not documented in v1 API
|
25
|
+
collection :companies, extend: GameCompanyRespresenter, class: Igdb::GameCompany # List of companies that developed and published.
|
26
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module PersonRepresenter
|
2
|
+
include Representable::JSON
|
3
|
+
|
4
|
+
property :id # The id of the person.
|
5
|
+
property :name # The name of the person.
|
6
|
+
property :dob # The day of birth of the person ISO standard is followed.
|
7
|
+
property :country # The country of the person in http://en.wikipedia.org/wiki/ISO_3166-1_numeric .
|
8
|
+
property :bio # The bio of the person.
|
9
|
+
property :slug # Not listed in the API
|
10
|
+
property :size # The number of people in the database.
|
11
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rest_client'
|
2
|
+
|
3
|
+
class Igdb::Requester
|
4
|
+
class << self
|
5
|
+
|
6
|
+
def get(action, params={})
|
7
|
+
url = api.url_for(action, params)
|
8
|
+
perform_request do
|
9
|
+
parse_response(RestClient.get(url, request_headers))
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def post(action, params={}, form_data={})
|
14
|
+
url = api.url_for(action, params)
|
15
|
+
perform_request do
|
16
|
+
parse_response(RestClient.post(url, form_data.to_json, request_headers))
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def delete(action)
|
21
|
+
url = api.url_for(action)
|
22
|
+
perform_request do
|
23
|
+
parse_response(RestClient.post(url, {}, request_headers))
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
def api
|
29
|
+
Igdb::Configuration::Api.instance
|
30
|
+
end
|
31
|
+
|
32
|
+
def perform_request(&block)
|
33
|
+
begin
|
34
|
+
block.call
|
35
|
+
rescue RestClient::Exception => e
|
36
|
+
raise Igdb::Exception::Api.new(e.message)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def request_headers
|
41
|
+
Hash.new.tap do |headers|
|
42
|
+
headers['Accept'] = 'application/json'
|
43
|
+
headers['Content-Type'] = 'application/json'
|
44
|
+
headers['Authorization'] = 'Token token="' + api.api_key + '"'
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def parse_response(response_body)
|
49
|
+
begin
|
50
|
+
JSON.parse(response_body)
|
51
|
+
rescue JSON::ParserError => e
|
52
|
+
raise Igdb::Exception::JsonParseError.new("Response body could not be parsed: #{e.message}")
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/lib/igdb/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: igdb
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmet Abdi
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-07-
|
11
|
+
date: 2015-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -52,34 +52,6 @@ dependencies:
|
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: byebug
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - ">="
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - ">="
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0'
|
69
|
-
- !ruby/object:Gem::Dependency
|
70
|
-
name: guard
|
71
|
-
requirement: !ruby/object:Gem::Requirement
|
72
|
-
requirements:
|
73
|
-
- - ">="
|
74
|
-
- !ruby/object:Gem::Version
|
75
|
-
version: '0'
|
76
|
-
type: :development
|
77
|
-
prerelease: false
|
78
|
-
version_requirements: !ruby/object:Gem::Requirement
|
79
|
-
requirements:
|
80
|
-
- - ">="
|
81
|
-
- !ruby/object:Gem::Version
|
82
|
-
version: '0'
|
83
55
|
- !ruby/object:Gem::Dependency
|
84
56
|
name: fuubar
|
85
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -95,7 +67,7 @@ dependencies:
|
|
95
67
|
- !ruby/object:Gem::Version
|
96
68
|
version: '0'
|
97
69
|
- !ruby/object:Gem::Dependency
|
98
|
-
name:
|
70
|
+
name: vcr
|
99
71
|
requirement: !ruby/object:Gem::Requirement
|
100
72
|
requirements:
|
101
73
|
- - ">="
|
@@ -109,7 +81,7 @@ dependencies:
|
|
109
81
|
- !ruby/object:Gem::Version
|
110
82
|
version: '0'
|
111
83
|
- !ruby/object:Gem::Dependency
|
112
|
-
name:
|
84
|
+
name: webmock
|
113
85
|
requirement: !ruby/object:Gem::Requirement
|
114
86
|
requirements:
|
115
87
|
- - ">="
|
@@ -123,7 +95,7 @@ dependencies:
|
|
123
95
|
- !ruby/object:Gem::Version
|
124
96
|
version: '0'
|
125
97
|
- !ruby/object:Gem::Dependency
|
126
|
-
name:
|
98
|
+
name: codeclimate-test-reporter
|
127
99
|
requirement: !ruby/object:Gem::Requirement
|
128
100
|
requirements:
|
129
101
|
- - ">="
|
@@ -168,16 +140,16 @@ dependencies:
|
|
168
140
|
name: rest-client
|
169
141
|
requirement: !ruby/object:Gem::Requirement
|
170
142
|
requirements:
|
171
|
-
- - "
|
143
|
+
- - ">="
|
172
144
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
145
|
+
version: '0'
|
174
146
|
type: :runtime
|
175
147
|
prerelease: false
|
176
148
|
version_requirements: !ruby/object:Gem::Requirement
|
177
149
|
requirements:
|
178
|
-
- - "
|
150
|
+
- - ">="
|
179
151
|
- !ruby/object:Gem::Version
|
180
|
-
version:
|
152
|
+
version: '0'
|
181
153
|
- !ruby/object:Gem::Dependency
|
182
154
|
name: require_all
|
183
155
|
requirement: !ruby/object:Gem::Requirement
|
@@ -199,10 +171,10 @@ executables: []
|
|
199
171
|
extensions: []
|
200
172
|
extra_rdoc_files: []
|
201
173
|
files:
|
174
|
+
- ".circle.yml"
|
202
175
|
- ".gitignore"
|
203
176
|
- ".rspec"
|
204
177
|
- ".travis.yml"
|
205
|
-
- CODE_OF_CONDUCT.md
|
206
178
|
- Gemfile
|
207
179
|
- LICENSE.txt
|
208
180
|
- README.md
|
@@ -211,6 +183,28 @@ files:
|
|
211
183
|
- bin/setup
|
212
184
|
- igdb.gemspec
|
213
185
|
- lib/igdb.rb
|
186
|
+
- lib/igdb/configuration/api.rb
|
187
|
+
- lib/igdb/exceptions.rb
|
188
|
+
- lib/igdb/models/api_resource.rb
|
189
|
+
- lib/igdb/models/company.rb
|
190
|
+
- lib/igdb/models/game.rb
|
191
|
+
- lib/igdb/models/game_company.rb
|
192
|
+
- lib/igdb/models/game_genre.rb
|
193
|
+
- lib/igdb/models/game_release_date.rb
|
194
|
+
- lib/igdb/models/game_screenshot.rb
|
195
|
+
- lib/igdb/models/game_theme.rb
|
196
|
+
- lib/igdb/models/game_video.rb
|
197
|
+
- lib/igdb/models/person.rb
|
198
|
+
- lib/igdb/models/shop.rb
|
199
|
+
- lib/igdb/representers/game_company_representer.rb
|
200
|
+
- lib/igdb/representers/game_genre_representer.rb
|
201
|
+
- lib/igdb/representers/game_release_date_representer.rb
|
202
|
+
- lib/igdb/representers/game_representer.rb
|
203
|
+
- lib/igdb/representers/game_screenshot_representer.rb
|
204
|
+
- lib/igdb/representers/game_theme_representer.rb
|
205
|
+
- lib/igdb/representers/game_video_representer.rb
|
206
|
+
- lib/igdb/representers/person_representer.rb
|
207
|
+
- lib/igdb/requester.rb
|
214
208
|
- lib/igdb/version.rb
|
215
209
|
homepage: ''
|
216
210
|
licenses:
|
data/CODE_OF_CONDUCT.md
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
# Contributor Code of Conduct
|
2
|
-
|
3
|
-
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities.
|
4
|
-
|
5
|
-
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, age, or religion.
|
6
|
-
|
7
|
-
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct.
|
8
|
-
|
9
|
-
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team.
|
10
|
-
|
11
|
-
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by opening an issue or contacting one or more of the project maintainers.
|
12
|
-
|
13
|
-
This Code of Conduct is adapted from the [Contributor Covenant](http:contributor-covenant.org), version 1.0.0, available at [http://contributor-covenant.org/version/1/0/0/](http://contributor-covenant.org/version/1/0/0/)
|