igdb2 0.8.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.
- checksums.yaml +7 -0
- data/README.md +86 -0
- data/lib/igdb.rb +91 -0
- data/lib/igdb/configuration/api.rb +30 -0
- data/lib/igdb/exceptions.rb +13 -0
- data/lib/igdb/models/alternative_name.rb +5 -0
- data/lib/igdb/models/api_resource.rb +67 -0
- data/lib/igdb/models/character.rb +6 -0
- data/lib/igdb/models/collection.rb +6 -0
- data/lib/igdb/models/company.rb +6 -0
- data/lib/igdb/models/credits.rb +6 -0
- data/lib/igdb/models/esrb.rb +5 -0
- data/lib/igdb/models/external.rb +5 -0
- data/lib/igdb/models/feature.rb +5 -0
- data/lib/igdb/models/feature_value.rb +5 -0
- data/lib/igdb/models/feed.rb +6 -0
- data/lib/igdb/models/franchise.rb +6 -0
- data/lib/igdb/models/game.rb +6 -0
- data/lib/igdb/models/game_engine.rb +6 -0
- data/lib/igdb/models/game_mode.rb +6 -0
- data/lib/igdb/models/genre.rb +6 -0
- data/lib/igdb/models/image.rb +5 -0
- data/lib/igdb/models/keyword.rb +6 -0
- data/lib/igdb/models/page.rb +6 -0
- data/lib/igdb/models/pegi.rb +5 -0
- data/lib/igdb/models/person.rb +6 -0
- data/lib/igdb/models/platform.rb +6 -0
- data/lib/igdb/models/platform_company.rb +5 -0
- data/lib/igdb/models/platform_version.rb +5 -0
- data/lib/igdb/models/platform_version_release_date.rb +5 -0
- data/lib/igdb/models/player_perspective.rb +6 -0
- data/lib/igdb/models/pulse.rb +6 -0
- data/lib/igdb/models/pulse_group.rb +6 -0
- data/lib/igdb/models/pulse_source.rb +6 -0
- data/lib/igdb/models/release_date.rb +6 -0
- data/lib/igdb/models/review.rb +6 -0
- data/lib/igdb/models/theme.rb +6 -0
- data/lib/igdb/models/time_to_beat.rb +5 -0
- data/lib/igdb/models/title.rb +6 -0
- data/lib/igdb/models/version.rb +6 -0
- data/lib/igdb/models/video.rb +6 -0
- data/lib/igdb/models/website.rb +5 -0
- data/lib/igdb/representers/alternative_name_representer.rb +10 -0
- data/lib/igdb/representers/character_representer.rb +18 -0
- data/lib/igdb/representers/collection_representer.rb +11 -0
- data/lib/igdb/representers/company_representer.rb +24 -0
- data/lib/igdb/representers/credits_representer.rb +22 -0
- data/lib/igdb/representers/esrb_representer.rb +12 -0
- data/lib/igdb/representers/external_representer.rb +9 -0
- data/lib/igdb/representers/feature_representer.rb +17 -0
- data/lib/igdb/representers/feature_value_representer.rb +12 -0
- data/lib/igdb/representers/feed_representer.rb +16 -0
- data/lib/igdb/representers/franchise_representer.rb +11 -0
- data/lib/igdb/representers/game_engine_representer.rb +15 -0
- data/lib/igdb/representers/game_mode_representer.rb +11 -0
- data/lib/igdb/representers/game_representer.rb +64 -0
- data/lib/igdb/representers/genre_representer.rb +10 -0
- data/lib/igdb/representers/image_representer.rb +14 -0
- data/lib/igdb/representers/keyword_representer.rb +12 -0
- data/lib/igdb/representers/page_representer.rb +38 -0
- data/lib/igdb/representers/pegi_representer.rb +12 -0
- data/lib/igdb/representers/person_representer.rb +15 -0
- data/lib/igdb/representers/platform_company_representer.rb +12 -0
- data/lib/igdb/representers/platform_representer.rb +17 -0
- data/lib/igdb/representers/platform_version_release_date_representer.rb +12 -0
- data/lib/igdb/representers/platform_version_representer.rb +32 -0
- data/lib/igdb/representers/player_perspective_representer.rb +11 -0
- data/lib/igdb/representers/pulse_group_representer.rb +21 -0
- data/lib/igdb/representers/pulse_representer.rb +25 -0
- data/lib/igdb/representers/pulse_source_representer.rb +15 -0
- data/lib/igdb/representers/release_date_representer.rb +21 -0
- data/lib/igdb/representers/representer.rb +14 -0
- data/lib/igdb/representers/review_representer.rb +28 -0
- data/lib/igdb/representers/theme_representer.rb +10 -0
- data/lib/igdb/representers/time_to_beat_representer.rb +13 -0
- data/lib/igdb/representers/title_representer.rb +13 -0
- data/lib/igdb/representers/version_representer.rb +19 -0
- data/lib/igdb/representers/video_representer.rb +10 -0
- data/lib/igdb/representers/website_representer.rb +12 -0
- data/lib/igdb/requester.rb +54 -0
- data/lib/igdb/version.rb +3 -0
- metadata +278 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 69b27188f6559dbed98d21041334bf8e110fdf857f1e56f020508fd8008efd02
|
4
|
+
data.tar.gz: df7d26cd5a96c70974999031bb2481571fc6a737e7eaecd51b9aba47bbee5747
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8f41bc2879a91637689edd54789e9f947e1e5db5daf827035d1da60f7e08ec63f87001497d6cd1f95b016ad1ba13203edce7f39ddbe10c66c7a8017734c0440a
|
7
|
+
data.tar.gz: ae12f2121d43232f1a5f46272fccd421c3a07203a977181e8114e989459e8744fb4eac440a5226f3232ec6667f54c9518deb2f28d7b80f3dd5dca02430c1da7b
|
data/README.md
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
# IGDB: Internet Game Database
|
2
|
+
[](https://circleci.com/gh/kalynrobinson/igdb)
|
3
|
+
[](https://travis-ci.org/kalynrobinson/igdb)
|
4
|
+
[](https://codeclimate.com/github/kalynrobinson/igdb/maintainability)
|
5
|
+
[](https://codeclimate.com/github/kalynrobinson/igdb/test_coverage)
|
6
|
+
[](http://badge.fury.io/rb/igdb2)
|
7
|
+
[](https://beta.gemnasium.com/projects/github.com/kalynrobinson/igdb)
|
8
|
+
|
9
|
+
## Installation
|
10
|
+
```ruby
|
11
|
+
$ gem install igdb2
|
12
|
+
```
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
##### Connect
|
16
|
+
```ruby
|
17
|
+
$ Igdb.connect('api_key')
|
18
|
+
```
|
19
|
+
If no parameter is given, Igdb will default to ENV['IGDB_KEY'].
|
20
|
+
```ruby
|
21
|
+
$ Igdb.connect # => Igdb.connect(ENV['IGDB_KEY'])
|
22
|
+
```
|
23
|
+
##### Usage
|
24
|
+
Find game by ID
|
25
|
+
```ruby
|
26
|
+
$ Igdb::Game.find(1971)
|
27
|
+
```
|
28
|
+
Find game by ID with options
|
29
|
+
```ruby
|
30
|
+
$ Igdb::Game.find(1971, { fields: 'slug,name' })
|
31
|
+
```
|
32
|
+
Find a game by slug
|
33
|
+
```ruby
|
34
|
+
$ Igdb::Game.slug('batman')
|
35
|
+
```
|
36
|
+
Search for a game
|
37
|
+
```ruby
|
38
|
+
$ Igdb::Game.search(query: 'batman')
|
39
|
+
```
|
40
|
+
Return the number of games in the database
|
41
|
+
```ruby
|
42
|
+
$ Igdb::Game.count
|
43
|
+
```
|
44
|
+
Return a list of all games with an offset and/or limit
|
45
|
+
```ruby
|
46
|
+
$ Igdb::Game.all
|
47
|
+
$ Igdb::Game.all(limit: 10) # Limit to 10 results - Default 100
|
48
|
+
$ Igdb::Game.all(offset: 5) # Offset result starting at 5th - Default 0
|
49
|
+
```
|
50
|
+
Return the available properties of games
|
51
|
+
```ruby
|
52
|
+
$ Igdb::Game.meta
|
53
|
+
```
|
54
|
+
### Endpoints
|
55
|
+
```ruby
|
56
|
+
Igdb::Character
|
57
|
+
Igdb::Collection
|
58
|
+
Igdb::Company
|
59
|
+
Igdb::Credits
|
60
|
+
Igdb::Feed
|
61
|
+
Igdb::Franchise
|
62
|
+
Igdb::GameEngine
|
63
|
+
Igdb::GameMode
|
64
|
+
Igdb::Game
|
65
|
+
Igdb::Genre
|
66
|
+
Igdb::Keyword
|
67
|
+
Igdb::Page
|
68
|
+
Igdb::Person
|
69
|
+
Igdb::Platform
|
70
|
+
Igdb::PlayerPerspective
|
71
|
+
Igdb::PulseGroup
|
72
|
+
Igdb::Pulse
|
73
|
+
Igdb::PulseSource
|
74
|
+
Igdb::ReleaseDate
|
75
|
+
Igdb::Review
|
76
|
+
Igdb::Theme
|
77
|
+
Igdb::Title
|
78
|
+
Igdb::Version
|
79
|
+
```
|
80
|
+
## Contributing
|
81
|
+
|
82
|
+
1. Fork it ( https://github.com/kalynrobinson/igdb/fork )
|
83
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
84
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
85
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
86
|
+
5. Create a new Pull Request
|
data/lib/igdb.rb
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
module Igdb
|
2
|
+
# Utilities
|
3
|
+
autoload :Configuration, 'igdb/configuration/api'
|
4
|
+
autoload :Requester, 'igdb/requester'
|
5
|
+
autoload :Exception, 'igdb/exceptions'
|
6
|
+
autoload :VERSION, 'igdb/version'
|
7
|
+
|
8
|
+
# Models
|
9
|
+
autoload :AlternativeName, 'igdb/models/alternative_name'
|
10
|
+
autoload :ApiResource, 'igdb/models/api_resource'
|
11
|
+
autoload :Character, 'igdb/models/character'
|
12
|
+
autoload :Collection, 'igdb/models/collection'
|
13
|
+
autoload :Company, 'igdb/models/company'
|
14
|
+
autoload :Credits, 'igdb/models/credits'
|
15
|
+
autoload :Esrb, 'igdb/models/esrb'
|
16
|
+
autoload :External, 'igdb/models/external'
|
17
|
+
autoload :Feature, 'igdb/models/feature'
|
18
|
+
autoload :FeatureValue, 'igdb/models/feature_value'
|
19
|
+
autoload :Feed, 'igdb/models/feed'
|
20
|
+
autoload :Franchise, 'igdb/models/franchise'
|
21
|
+
autoload :Game, 'igdb/models/game'
|
22
|
+
autoload :GameEngine, 'igdb/models/game_engine'
|
23
|
+
autoload :GameMode, 'igdb/models/game_mode'
|
24
|
+
autoload :Genre, 'igdb/models/genre'
|
25
|
+
autoload :Image, 'igdb/models/image'
|
26
|
+
autoload :Keyword, 'igdb/models/keyword'
|
27
|
+
autoload :Page, 'igdb/models/page'
|
28
|
+
autoload :Pegi, 'igdb/models/pegi'
|
29
|
+
autoload :Person, 'igdb/models/person'
|
30
|
+
autoload :Platform, 'igdb/models/platform'
|
31
|
+
autoload :PlatformCompany, 'igdb/models/platform_company'
|
32
|
+
autoload :PlatformVersion, 'igdb/models/platform_version'
|
33
|
+
autoload :PlatformVersionReleaseDate, 'igdb/models/platform_version_release_date'
|
34
|
+
autoload :PlayerPerspective, 'igdb/models/player_perspective'
|
35
|
+
autoload :Pulse, 'igdb/models/pulse'
|
36
|
+
autoload :PulseGroup, 'igdb/models/pulse_group'
|
37
|
+
autoload :PulseSource, 'igdb/models/pulse_source'
|
38
|
+
autoload :ReleaseDate, 'igdb/models/release_date'
|
39
|
+
autoload :Review, 'igdb/models/review'
|
40
|
+
autoload :Theme, 'igdb/models/theme'
|
41
|
+
autoload :TimeToBeat, 'igdb/models/time_to_beat'
|
42
|
+
autoload :Title, 'igdb/models/title'
|
43
|
+
autoload :Version, 'igdb/models/version'
|
44
|
+
autoload :Video, 'igdb/models/video'
|
45
|
+
autoload :Website, 'igdb/models/website'
|
46
|
+
|
47
|
+
# Presenters
|
48
|
+
autoload :AlternativeNameRepresenter, 'igdb/representers/alternative_name_representer'
|
49
|
+
autoload :CharacterRepresenter, 'igdb/representers/character_representer'
|
50
|
+
autoload :CollectionRepresenter, 'igdb/representers/collection_representer'
|
51
|
+
autoload :CompanyRepresenter, 'igdb/representers/company_representer'
|
52
|
+
autoload :CreditsRepresenter, 'igdb/representers/credits_representer'
|
53
|
+
autoload :EsrbRepresenter, 'igdb/representers/esrb_representer'
|
54
|
+
autoload :ExternalRepresenter, 'igdb/representers/external_representer'
|
55
|
+
autoload :FeatureRepresenter, 'igdb/representers/feature_representer'
|
56
|
+
autoload :FeatureValueRepresenter, 'igdb/representers/feature_value_representer'
|
57
|
+
autoload :FeedRepresenter, 'igdb/representers/feed_representer'
|
58
|
+
autoload :FranchiseRepresenter, 'igdb/representers/franchise_representer'
|
59
|
+
autoload :GameEngineRepresenter, 'igdb/representers/game_engine_representer'
|
60
|
+
autoload :GameModeRepresenter, 'igdb/representers/game_mode_representer'
|
61
|
+
autoload :GameRepresenter, 'igdb/representers/game_representer'
|
62
|
+
autoload :GenreRepresenter, 'igdb/representers/genre_representer'
|
63
|
+
autoload :ImageRepresenter, 'igdb/representers/image_representer'
|
64
|
+
autoload :KeywordRepresenter, 'igdb/representers/keyword_representer'
|
65
|
+
autoload :PageRepresenter, 'igdb/representers/page_representer'
|
66
|
+
autoload :PegiRepresenter, 'igdb/representers/pegi_representer'
|
67
|
+
autoload :PersonRepresenter, 'igdb/representers/person_representer'
|
68
|
+
autoload :PlatformCompanyRepresenter, 'igdb/representers/platform_company_representer'
|
69
|
+
autoload :PlatformRepresenter, 'igdb/representers/platform_representer'
|
70
|
+
autoload :PlatformVersionReleaseDateRepresenter, 'igdb/representers/platform_version_release_date_representer'
|
71
|
+
autoload :PlatformVersionRepresenter, 'igdb/representers/platform_version_representer'
|
72
|
+
autoload :PlayerPerspectiveRepresenter, 'igdb/representers/player_perspective_representer'
|
73
|
+
autoload :PulseGroupRepresenter, 'igdb/representers/pulse_group_representer'
|
74
|
+
autoload :PulseRepresenter, 'igdb/representers/pulse_representer'
|
75
|
+
autoload :PulseSourceRepresenter, 'igdb/representers/pulse_source_representer'
|
76
|
+
autoload :ReleaseDateRepresenter, 'igdb/representers/release_date_representer'
|
77
|
+
autoload :Representer, 'igdb/representers/representer'
|
78
|
+
autoload :ReviewRepresenter, 'igdb/representers/review_representer'
|
79
|
+
autoload :ThemeRepresenter, 'igdb/representers/theme_representer'
|
80
|
+
autoload :TimeToBeatRepresenter, 'igdb/representers/time_to_beat_representer'
|
81
|
+
autoload :TitleRepresenter, 'igdb/representers/title_representer'
|
82
|
+
autoload :VersionRepresenter, 'igdb/representers/version_representer'
|
83
|
+
autoload :VideoRepresenter, 'igdb/representers/video_representer'
|
84
|
+
autoload :WebsiteRepresenter, 'igdb/representers/website_representer'
|
85
|
+
|
86
|
+
def self.connect(api_key = ENV['IGDB_KEY'])
|
87
|
+
Igdb::Configuration::Api.instance.tap do |api|
|
88
|
+
api.connect(api_key)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'singleton'
|
2
|
+
|
3
|
+
module Igdb
|
4
|
+
module Configuration
|
5
|
+
class Api
|
6
|
+
include Singleton
|
7
|
+
|
8
|
+
attr_reader :base_url, :version, :api_key
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
self.base_url = 'https://api-2445582011268.apicast.io'.freeze
|
12
|
+
self.version = 1
|
13
|
+
end
|
14
|
+
|
15
|
+
def connect(api_key)
|
16
|
+
@api_key = api_key
|
17
|
+
end
|
18
|
+
|
19
|
+
def url_for(action, params = {})
|
20
|
+
url = URI.join(base_url, action)
|
21
|
+
url.query = URI.encode_www_form(params) unless params.empty?
|
22
|
+
url.to_s
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
attr_writer :base_url, :api_key, :version
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'representable/json'
|
2
|
+
require 'ostruct'
|
3
|
+
|
4
|
+
module Igdb
|
5
|
+
class ApiResource < OpenStruct
|
6
|
+
class << self
|
7
|
+
attr_accessor :path, :representer
|
8
|
+
|
9
|
+
def count
|
10
|
+
Igdb::Requester.get("#{path}/count")['count']
|
11
|
+
end
|
12
|
+
|
13
|
+
def meta
|
14
|
+
Igdb::Requester.get("#{path}/meta")
|
15
|
+
end
|
16
|
+
|
17
|
+
def find(id, options = {})
|
18
|
+
params = options
|
19
|
+
params[:fields] = '*' unless params[:fields]
|
20
|
+
|
21
|
+
if id.class == Array
|
22
|
+
build_collection(Igdb::Requester.get("#{path}/#{id.join(',')}", params), representer)
|
23
|
+
else
|
24
|
+
build_single_resource(Igdb::Requester.get("#{path}/#{id}", params)[0], representer)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def slug(id, options = {})
|
29
|
+
params = options
|
30
|
+
params['fields'] = '*' unless params[:fields]
|
31
|
+
params['filter[slug][eq]'] = id
|
32
|
+
|
33
|
+
build_single_resource(Igdb::Requester.get("#{path}/", params)[0], representer)
|
34
|
+
end
|
35
|
+
|
36
|
+
def search(opts = {})
|
37
|
+
params = {}.tap do |hash|
|
38
|
+
hash['search'] = opts[:query] if opts[:query]
|
39
|
+
hash['filters'] = opts[:filters] if opts[:filters]
|
40
|
+
hash['fields'] = '*'
|
41
|
+
end
|
42
|
+
|
43
|
+
build_collection(Igdb::Requester.get("#{path}/", params), representer)
|
44
|
+
end
|
45
|
+
|
46
|
+
def all(opts = {})
|
47
|
+
params = {}.tap do |hash|
|
48
|
+
hash['offset'] = opts[:offset] || 0
|
49
|
+
hash['limit'] = opts[:limit] || 50
|
50
|
+
hash['fields'] = '*'
|
51
|
+
end
|
52
|
+
|
53
|
+
build_collection(Igdb::Requester.get("#{path}/", opts), representer)
|
54
|
+
end
|
55
|
+
|
56
|
+
private
|
57
|
+
|
58
|
+
def build_single_resource(response, representer)
|
59
|
+
representer.new(new).from_hash(response)
|
60
|
+
end
|
61
|
+
|
62
|
+
def build_collection(response, representer)
|
63
|
+
representer.for_collection.new([]).from_hash(response)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|