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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8252b97b715b1aba6f8ffdad48a9b55d09cd31af
4
- data.tar.gz: 136512762d8792e5266fce4d65ca024717ddefea
3
+ metadata.gz: 20fabf6dcdaace6c88808c75eef38417a958de60
4
+ data.tar.gz: 112cd37e00140a5bb8d5fcb9934ecbc097ea1327
5
5
  SHA512:
6
- metadata.gz: 6d19f1c392f3ab66556271dafb2697f4cbf10ef0df3159a5ecb9153289bc7d19adf38890456fa8cea3b38164b1e02d80602e938829027cebff4f980c5568140c
7
- data.tar.gz: 7beec9138edba7bc14392cd57c4476ee33f298896164dcab9ab3899064968c6dd61312a49e395e40e19852b018d748539a4b2cc346f91fee8bad2c23602d9024
6
+ metadata.gz: 91fa09829edf14034623f97afefccdef77082664b52cfe2ce0176a2d72b10eeb1685847e8ffbdb3368c21bf3bf97212a46aa851d11e86bf3d14f3edcbb4c5203
7
+ data.tar.gz: 78c1275eef6a9281f034dc59e02862f0c678301ce4d85dc1cd025c2aee126ea4064f6d6eb2bed3628c0f631da1d39663a3c0c6b43f72166b0241d92ab78d5f13
@@ -0,0 +1,3 @@
1
+ machine:
2
+ ruby:
3
+ version: rbx-2.2.2
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ .idea
11
+ .env
@@ -1,3 +1,6 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.2.2
4
+ env:
5
+ - CODECLIMATE_REPO_TOKEN=8ffbec2a216b73652275893dbfb29f9b73035ba8e7d00f4743ec4824f8eacfdd
6
+ script: bundle exec rspec spec
data/README.md CHANGED
@@ -1,34 +1,53 @@
1
- # Igdb
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
- Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/igdb`. To experiment with that code, run `bin/console` for an interactive prompt.
8
+ ## Installation
9
+ $ gem install igdb
4
10
 
5
- TODO: Delete this and the text above, and describe your gem
11
+ ## Usage
6
12
 
7
- ## Installation
13
+ ##### Connect
8
14
 
9
- Add this line to your application's Gemfile:
15
+ $ Igdb.connect('api_key')
10
16
 
11
- ```ruby
12
- gem 'igdb'
13
- ```
17
+ ##### Game
18
+ Find game by ID
14
19
 
15
- And then execute:
20
+ $ Igdb::Game.find(1971)
16
21
 
17
- $ bundle
22
+ Search for a game
18
23
 
19
- Or install it yourself as:
24
+ $ Igdb::Game.search(query: 'batman')
20
25
 
21
- $ gem install igdb
26
+ Return the number of games in the database
22
27
 
23
- ## Usage
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
- TODO: Write usage instructions here
42
+ Return the number of people in the database
26
43
 
27
- ## Development
44
+ $ Igdb::Person.meta
28
45
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
46
+ Return a list of all games with an offset and/or limit
30
47
 
31
- To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
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
 
@@ -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 "bundler", "~> 1.9"
23
- spec.add_development_dependency "rake", "~> 10.0"
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 "rest-client", "~> 1.7.3"
32
+ spec.add_runtime_dependency 'rest-client'
35
33
  spec.add_runtime_dependency 'require_all'
36
34
  end
@@ -1,9 +1,8 @@
1
1
  require 'require_all'
2
-
3
2
  require_all 'lib'
4
3
 
5
4
  module Igdb
6
- def self.connect(api_key = 'egBf-guz6Z8ZIMYw0GMykId-V0-OumqBwy988YFyq2E')
5
+ def self.connect(api_key)
7
6
  Igdb::Configuration::Api.instance.tap do |api|
8
7
  api.connect(api_key)
9
8
  end
@@ -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,11 @@
1
+ module Igdb::Exception
2
+ class Base < ::Exception
3
+ def initialize(message)
4
+ super(message)
5
+ end
6
+ end
7
+
8
+ class Api < Base; end
9
+ class ArgumentError < Base; end
10
+ class JsonParseError < Base; end
11
+ 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,2 @@
1
+ class Igdb::Company < Igdb::ApiResource
2
+ 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,2 @@
1
+ class Igdb::GameCompany < Igdb::ApiResource
2
+ end
@@ -0,0 +1,2 @@
1
+ class Igdb::GameGenre < Igdb::ApiResource
2
+ end
@@ -0,0 +1,2 @@
1
+ class Igdb::GameReleaseDate < Igdb::ApiResource
2
+ end
@@ -0,0 +1,2 @@
1
+ class Igdb::GameScreenshot < Igdb::ApiResource
2
+ end
@@ -0,0 +1,2 @@
1
+ class Igdb::GameTheme < Igdb::ApiResource
2
+ end
@@ -0,0 +1,2 @@
1
+ class Igdb::GameVideo < Igdb::ApiResource
2
+ 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,2 @@
1
+ class Igdb::Shop < Igdb::ApiResource
2
+ end
@@ -0,0 +1,7 @@
1
+ module GameCompanyRespresenter
2
+ include Representable::JSON
3
+
4
+ property :name
5
+ property :developer
6
+ property :publisher
7
+ end
@@ -0,0 +1,5 @@
1
+ module GameGenreRepresenter
2
+ include Representable::JSON
3
+
4
+ property :name
5
+ end
@@ -0,0 +1,6 @@
1
+ module GameReleaseDateRespresenter
2
+ include Representable::JSON
3
+
4
+ property :platform_name
5
+ property :release_date
6
+ 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,6 @@
1
+ module GameScreenshotRepresenter
2
+ include Representable::JSON
3
+
4
+ property :title
5
+ property :thumb
6
+ end
@@ -0,0 +1,5 @@
1
+ module GameThemeRepresenter
2
+ include Representable::JSON
3
+
4
+ property :name
5
+ end
@@ -0,0 +1,6 @@
1
+ module GameVideoRepresenter
2
+ include Representable::JSON
3
+
4
+ property :title
5
+ property :uid
6
+ 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
@@ -1,3 +1,3 @@
1
1
  module Igdb
2
- VERSION = "0.2.0"
2
+ VERSION = "0.4.0"
3
3
  end
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.2.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-29 00:00:00.000000000 Z
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: guard-rspec
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: vcr
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: webmock
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: 1.7.3
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: 1.7.3
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:
@@ -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/)