Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change api url #9

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions .circle.yml

This file was deleted.

8 changes: 6 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
language: ruby
rvm:
- 2.2.2
env:
- CODECLIMATE_REPO_TOKEN=8ffbec2a216b73652275893dbfb29f9b73035ba8e7d00f4743ec4824f8eacfdd
addons:
code_climate:
repo_token: dfde3ea1f13524298878000db6943cb43bf37d9f3485b6f15392133157122853
script: bundle exec rspec spec
after_success:
- bundle exec codeclimate-test-reporter

1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in igdb.gemspec
gem 'byebug'
gemspec
2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015 Ahmet Abdi
Copyright (c) 2015 Leigh West

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
20 changes: 9 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
# IGDB: Internet Game Database
[![Circle CI](https://circleci.com/gh/ahmetabdi/igdb.svg?style=svg)](https://circleci.com/gh/ahmetabdi/igdb)
[![Build Status](https://travis-ci.org/ahmetabdi/igdb.svg)](https://travis-ci.org/ahmetabdi/igdb)
[![Code Climate](https://codeclimate.com/github/ahmetabdi/igdb/badges/gpa.svg)](https://codeclimate.com/github/ahmetabdi/igdb)
[![Test Coverage](https://codeclimate.com/github/ahmetabdi/igdb/badges/coverage.svg)](https://codeclimate.com/github/ahmetabdi/igdb/coverage)
[![Gem Version](https://badge.fury.io/rb/igdb.svg)](http://badge.fury.io/rb/igdb)
[![Dependency Status](https://gemnasium.com/ahmetabdi/igdb.svg)](https://gemnasium.com/ahmetabdi/igdb)
[![Build Status](https://travis-ci.org/tastycake/igdb_api.svg?branch=master)](https://travis-ci.org/tastycake/igdb_api)
[![Code Climate](https://codeclimate.com/github/tastycake/igdb_api/badges/gpa.svg)](https://codeclimate.com/github/tastycake/igdb_api)
[![Test Coverage](https://codeclimate.com/github/tastycake/igdb_api/badges/coverage.svg)](https://codeclimate.com/github/tastycake/igdb_api/coverage)
[![Gem Version](https://badge.fury.io/rb/igdb_api.svg)](https://badge.fury.io/rb/igdb_api)

![Banner](http://orig08.deviantart.net/b5c1/f/2011/204/b/9/umvc3_roster_by_kiradaidohji-d41fyaq.png)

## Installation
```ruby
$ gem install igdb
$ gem install igdb_api
```
## Usage

Expand All @@ -29,7 +27,7 @@ $ Igdb::Game.search(query: 'batman')
```
Return the number of games in the database
```ruby
$ Igdb::Game.meta
$ Igdb::Game.count
```
Return a list of all games with an offset and/or limit
```ruby
Expand All @@ -45,7 +43,7 @@ $ Igdb::Person.find('derek-watts')
```
Return the number of people in the database
```ruby
$ Igdb::Person.meta
$ Igdb::Person.count
```
Return a list of all games with an offset and/or limit
```ruby
Expand All @@ -61,15 +59,15 @@ $ Igdb::Company.find('nintendo')
```
Return the number of companies in the database.
```ruby
$ Igdb::Company.meta
$ Igdb::Company.count
```
Return the games for a company
```ruby
$ Igdb::Company.find('2000').games
```
## Contributing

1. Fork it ( https://github.com/ahmetabdi/igdb/fork )
1. Fork it ( https://github.com/tastycake/igdb_api/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
Expand Down
2 changes: 1 addition & 1 deletion bin/console
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env ruby

require "bundler/setup"
require "igdb"
require "igdb_api"
require 'byebug'

# You can add fixtures and/or initialization code here to make experimenting
Expand Down
16 changes: 9 additions & 7 deletions igdb.gemspec → igdb-api.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'igdb/version'

Gem::Specification.new do |spec|
spec.name = 'igdb'
spec.name = 'igdb_api'
spec.version = Igdb::VERSION
spec.authors = ['Ahmet Abdi']
spec.email = ['ahmetabdi@gmail.com']
spec.authors = ['Leigh West']
spec.email = ['iamtastycake@gmail.com']

spec.summary = 'A Ruby wrapper for the Internet Game Database API.'
spec.description = ''
spec.homepage = ''
spec.homepage = 'https://github.com/tastycake/igdb_api'
spec.license = 'MIT'

spec.files = Dir['README.md', 'igdb.gemspec', 'lib/**/*']
spec.files = Dir['README.md', 'igdb_api.gemspec', 'lib/**/*']
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']
Expand All @@ -23,8 +23,10 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.3.0'
spec.add_development_dependency 'vcr', '~> 2.9.3'
spec.add_development_dependency 'webmock', '~> 1.21.0'
spec.add_development_dependency 'codeclimate-test-reporter'
spec.add_development_dependency 'webmock', '~> 2.3.2'
spec.add_development_dependency 'simplecov'
spec.add_development_dependency 'codeclimate-test-reporter', '~> 1.0.0'
spec.add_development_dependency 'pry'

spec.add_runtime_dependency 'representable'
spec.add_runtime_dependency 'multi_json'
Expand Down
36 changes: 0 additions & 36 deletions lib/igdb.rb

This file was deleted.

17 changes: 13 additions & 4 deletions lib/igdb/configuration/api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,29 @@ module Igdb::Configuration
class Api
include Singleton

attr_reader :base_url, :version, :api_key
DEFAULT_API_URL = 'https://api-endpoint.igdb.com'

attr_reader :base_url, :api_key, :version

def initialize
self.base_url = "https://www.igdb.com/api/v1/".freeze
self.version = 1.freeze
end

def connect(api_key)
@api_key = api_key
end

def api_url
@base_url || DEFAULT_API_URL
end

def set_api_url(url)
@base_url = url
end

def url_for(action, params={})
url = URI.join(base_url, action)
url.query = URI.encode_www_form(params) if params
url = URI.parse "#{File.join(api_url, action)}/"
url.query = URI.encode_www_form(params) unless params.empty?
url.to_s
end

Expand Down
32 changes: 32 additions & 0 deletions lib/igdb/models/api_resource.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,38 @@
require 'representable/json'
require 'ostruct'

class Igdb::ApiResource < OpenStruct
class << self
attr_accessor :path
attr_accessor :representer
end

def self.count
Igdb::Requester.get("#{self.path}/count")['count']
end

def self.find(id)
params = { fields: '*' }
build_single_resource(Igdb::Requester.get("#{self.path}/#{id}", params)[0], self.representer)
end

def self.search(opts={})
params = Hash.new.tap do |hash|
hash['search'] = opts[:query] if opts[:query]
hash['filters'] = opts[:filters] if opts[:filters]
hash['fields'] = '*'
end
build_collection(Igdb::Requester.get("#{self.path}", params), self.representer)
end

def self.all(opts={})
params = Hash.new.tap do |hash|
hash['offset'] = opts[:offset] || 0
hash['limit'] = opts[:limit] || 50
hash['fields'] = '*'
end
build_collection(Igdb::Requester.get("#{self.path}", params), self.representer)
end

private
def self.build_single_resource(response, representer)
Expand Down
4 changes: 4 additions & 0 deletions lib/igdb/models/character.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Character < Igdb::ApiResource
@path = 'characters'
@representer = Igdb::CharacterRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/collection.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Collection < Igdb::ApiResource
@path = 'collections'
@representer = Igdb::CollectionRepresenter
end
20 changes: 2 additions & 18 deletions lib/igdb/models/company.rb
Original file line number Diff line number Diff line change
@@ -1,20 +1,4 @@
class Igdb::Company < Igdb::ApiResource

def self.meta
build_single_resource(Igdb::Requester.get("companies/meta"), Igdb::CompanyRepresenter).size
end

def self.find(id)
build_single_resource(Igdb::Requester.get("companies/#{id}")['company'], Igdb::CompanyRepresenter)
end

# Show games of a specific company
def games(opts={})
params = Hash.new.tap do |hash|
hash['offset'] = opts[:offset] || 0
hash['limit'] = opts[:limit] || 100
end
build_for_collection(Igdb::Requester.get("companies/#{id}/games", params)['games'], Igdb::CompanyRepresenter)
end

@path = 'companies'
@representer = Igdb::CompanyRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/franchise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Franchise < Igdb::ApiResource
@path = 'franchises'
@representer = Igdb::FranchiseRepresenter
end
27 changes: 2 additions & 25 deletions lib/igdb/models/game.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,4 @@
class Igdb::Game < Igdb::ApiResource

def self.meta
build_single_resource(Igdb::Requester.get("games/meta"), Igdb::GameRepresenter).size
end

def self.find(id)
build_single_resource(Igdb::Requester.get("games/#{id}")['game'], Igdb::GameRepresenter)
end

def self.search(opts={})
params = Hash.new.tap do |hash|
hash['q'] = opts[:query] if opts[:query]
hash['filters'] = opts[:filters] if opts[:filters]
end
build_collection(Igdb::Requester.get("games/search", params)['games'], Igdb::GameRepresenter)
end

def self.all(opts={})
params = Hash.new.tap do |hash|
hash['offset'] = opts[:offset] || 0
hash['limit'] = opts[:limit] || 100
end
build_collection(Igdb::Requester.get("games", params)['games'], Igdb::GameRepresenter)
end

@path = 'games'
@representer = Igdb::GameRepresenter
end
2 changes: 0 additions & 2 deletions lib/igdb/models/game_company.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/igdb/models/game_engine.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::GameEngine < Igdb::ApiResource
@path = 'game_engines'
@representer = Igdb::GameEngineRepresenter
end
2 changes: 0 additions & 2 deletions lib/igdb/models/game_genre.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/igdb/models/game_mode.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::GameMode < Igdb::ApiResource
@path = 'game_modes'
@representer = Igdb::GameModeRepresenter
end
2 changes: 0 additions & 2 deletions lib/igdb/models/game_release_date.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/igdb/models/game_screenshot.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/igdb/models/game_theme.rb

This file was deleted.

2 changes: 0 additions & 2 deletions lib/igdb/models/game_video.rb

This file was deleted.

4 changes: 4 additions & 0 deletions lib/igdb/models/genre.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Genre < Igdb::ApiResource
@path = 'genres'
@representer = Igdb::GenreRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/keyword.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Keyword < Igdb::ApiResource
@path = 'keywords'
@representer = Igdb::KeywordRepresenter
end
19 changes: 2 additions & 17 deletions lib/igdb/models/person.rb
Original file line number Diff line number Diff line change
@@ -1,19 +1,4 @@
class Igdb::Person < Igdb::ApiResource

def self.meta
build_single_resource(Igdb::Requester.get('people/meta'), Igdb::PersonRepresenter).size
end

def self.find(id)
build_single_resource(Igdb::Requester.get("people/#{id}")['person'], Igdb::PersonRepresenter)
end

def self.all(opts={})
params = Hash.new.tap do |hash|
hash['offset'] = opts[:offset] || 0
hash['limit'] = opts[:limit] || 100
end
build_collection(Igdb::Requester.get("people", params)['people'], Igdb::PersonRepresenter)
end

@path = 'people'
@representer = Igdb::PersonRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/platform.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Platform < Igdb::ApiResource
@path = 'platforms'
@representer = Igdb::PlatformRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/player_perspective.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::PlayerPerspective < Igdb::ApiResource
@path = 'player_perspectives'
@representer = Igdb::PlayerPerspectiveRepresenter
end
4 changes: 4 additions & 0 deletions lib/igdb/models/pulse.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
class Igdb::Pulse < Igdb::ApiResource
@path = 'pulses'
@representer = Igdb::PulseRepresenter
end
Loading