Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Tim Adler committed Feb 2, 2015
1 parent 8571bf0 commit 48ea469
Show file tree
Hide file tree
Showing 28 changed files with 426 additions and 34 deletions.
37 changes: 3 additions & 34 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,34 +1,3 @@
*.gem
*.rbc
/.config
/coverage/
/InstalledFiles
/pkg/
/spec/reports/
/test/tmp/
/test/version_tmp/
/tmp/

## Specific to RubyMotion:
.dat*
.repl_history
build/

## Documentation cache and generated files:
/.yardoc/
/_yardoc/
/doc/
/rdoc/

## Environment normalisation:
/.bundle/
/lib/bundler/man/

# for a library or gem, you might want to ignore these files since the code is
# intended to run in multiple environments; otherwise, check them in:
# Gemfile.lock
# .ruby-version
# .ruby-gemset

# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
.rvmrc
bin
coverage
*.gem
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--color
6 changes: 6 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
LineLength:
Max: 999
Documentation:
Enabled: false
StringLiterals:
Enabled: false
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
source "https://rubygems.org"
gemspec
46 changes: 46 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
PATH
remote: .
specs:
giant_bomb_api (0.1)
faraday

GEM
remote: https://rubygems.org/
specs:
codeclimate-test-reporter (0.4.5)
simplecov (>= 0.7.1, < 1.0.0)
diff-lcs (1.2.5)
docile (1.1.5)
faraday (0.9.0)
multipart-post (>= 1.2, < 3)
multi_json (1.10.1)
multipart-post (2.0.0)
rake (10.1.1)
rspec (3.1.0)
rspec-core (~> 3.1.0)
rspec-expectations (~> 3.1.0)
rspec-mocks (~> 3.1.0)
rspec-core (3.1.7)
rspec-support (~> 3.1.0)
rspec-expectations (3.1.2)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.1.0)
rspec-mocks (3.1.3)
rspec-support (~> 3.1.0)
rspec-support (3.1.2)
simplecov (0.9.1)
docile (~> 1.1.0)
multi_json (~> 1.0)
simplecov-html (~> 0.8.0)
simplecov-html (0.8.0)
timecop (0.7.1)

PLATFORMS
ruby

DEPENDENCIES
codeclimate-test-reporter
giant_bomb_api!
rake (~> 10.1.0)
rspec (~> 3.0)
timecop
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,51 @@
<<<<<<< HEAD
# giant_bomb_api
=======
# filter8
A unofficial ruby wrapper for Filter8 (http://filter8.com). An API to filter lots of stuff from texts, e.g. bad words.

[![Code Climate](https://codeclimate.com/github/toadle/filter8/badges/gpa.svg)](https://codeclimate.com/github/toadle/filter8)
[![Test Coverage](https://codeclimate.com/github/toadle/filter8/badges/coverage.svg)](https://codeclimate.com/github/toadle/filter8)

# Installation


As you'd expect. Nothing special here:

```
gem install filter8
```

# How to use

## Configuration

Before you use Filter8 you need to configure it:
```
Filter8.configure do |config|
config.api_key = "your filter8-api-key"
config.api_secret = "your filter8-api-secret"
end
```

## Usage

Simply send the content, you wish to filter with the filter-method:
```
Filter8.filter("your content")
```

If you want to change the **default-options** of filter8 (https://filter8.com/documentation), you can pass an optional options-hash with the filter-configuration:
```
Filter8.filter("your content", blacklist: {enabled: true, locales: [:en, :de, :fr], tags: ["AsciiArt"]})
```

The **email** and **urls** filters are not yet supported.

## Feedback
Feedback and pull-request are always welcome.
You can find the author via http://toadle.me

## License
The filter8-gem is released under the [MIT License](http://opensource.org/licenses/MIT).
>>>>>>> initial commit
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require "bundler"
require 'rspec/core/rake_task'

task :default => :spec

Bundler::GemHelper.install_tasks
RSpec::Core::RakeTask.new :spec
27 changes: 27 additions & 0 deletions giant_bomb_api.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
Gem::Specification.new do |s|
s.name = "giant_bomb_api"
s.version = "0.1"
s.default_executable = "giantbomb"

s.authors = ["Tim Adler"]
s.date = %q{2015-02-01}
s.description = %q{An unofficial ruby wrapper for the Giantbomb API (http://api.giantbomb.com). An API that provides structured data about videogames.}
s.summary = s.description
s.email = %q{mail (at) toadle (dot) me}
s.license = "MIT"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.homepage = %q{https://github.com/toadle/giant_bomb_api}
s.require_paths = ["lib"]
s.rubygems_version = %q{1.6.2}

s.add_dependency 'faraday'

s.add_development_dependency 'rake', '~> 10.1.0'
s.add_development_dependency 'rspec', '~> 3.0'
s.add_development_dependency 'timecop'
s.add_development_dependency 'codeclimate-test-reporter'

end

40 changes: 40 additions & 0 deletions lib/giant_bomb_api.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
require "giant_bomb_api/exception"
require "giant_bomb_api/client"
require "giant_bomb_api/request"
require "giant_bomb_api/request/search"
require "giant_bomb_api/resource"
require "giant_bomb_api/resource/game"

module GiantBombApi

class Configuration
attr_accessor :api_key
end

class << self
attr_accessor :configuration
end

def self.raise_error(message)
raise Exception.new message
end

def self.configure
self.configuration ||= Configuration.new
yield(configuration)

@@client = nil
end

def self.search(query)
client.send_request(Request::Search.new(query))
end

def self.client
raise_error "Configure GiantBombApi-module before using" if GiantBombApi.configuration.nil?
raise_error "Configure 'api_key' first" if GiantBombApi.configuration.api_key.nil?

@@client ||= Client.new(api_key: GiantBombApi.configuration.api_key)
end

end
31 changes: 31 additions & 0 deletions lib/giant_bomb_api/client.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require 'digest'
require 'uri'
require 'faraday'
require 'json'

module GiantBombApi
class Client
attr_accessor :api_key

API_URL = 'http://api.giantbomb.com'

def initialize(api_key: nil, options: {})
@api_key = api_key
@options = options
end

def send_request(giant_bomb_api_request)
conn = Faraday.new(:url => API_URL) do |faraday|
faraday.request :url_encoded
faraday.adapter Faraday.default_adapter
end

response = conn.get "#{API_ENDPOINT}", giant_bomb_api_request.request_params

raise Exception.new("Status: #{response.status}): #{response.body}") if(response.status != GiantBomb::Response::Status::OK)

JSON.parse(response.body)
end

end
end
5 changes: 5 additions & 0 deletions lib/giant_bomb_api/exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module GiantBombApi
class Exception < StandardError

end
end
9 changes: 9 additions & 0 deletions lib/giant_bomb_api/request.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
module GiantBombApi
class Request
attr_accessor :params

def initialize(endpoint, params)
@params = params
end
end
end
15 changes: 15 additions & 0 deletions lib/giant_bomb_api/request/search.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module GiantBombApi
class Request::Search < GiantBombApi::Request
ENDPOINT = '/search'

def initialize(query, resources: [GiantBombApi::Resource::Game], limit: 100, page: 1)
params = {
query: query,
resources: resources.map { |clazz| clazz.name.split('::').last.downcase }.join(','),
limit: limit,
page: page
}
super ENDPOINT, params
end
end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/character.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Character < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/company.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Company < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/concept.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Concept < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/franchise.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Franchise < Resource

private

end
end
4 changes: 4 additions & 0 deletions lib/giant_bomb_api/resource/game.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module GiantBombApi
class Resource::Game < GiantBombApi::Resource
end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/location.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Location < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/object.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Object < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/person.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Person < Resource

private

end
end
7 changes: 7 additions & 0 deletions lib/giant_bomb_api/resource/video.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module GiantBombApi
class Video < Resource

private

end
end
10 changes: 10 additions & 0 deletions lib/giant_bomb_api/response.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module GiantBombApi
class Response
attr_accessor :json

def initialize(json)
@json = json
end

end
end
Loading

0 comments on commit 48ea469

Please sign in to comment.