giantbomb 0.0.2 → 0.1.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.
@@ -1,10 +1,10 @@
1
1
  require 'rubygems'
2
2
  require 'httparty'
3
3
 
4
- ["api", "search", "game", "company"].each do |inc|
4
+ ["api", "search", "resource", "game", "company", "character"].each do |inc|
5
5
  require File.join(File.dirname(__FILE__), "giantbomb", inc)
6
6
  end
7
7
 
8
8
  module GiantBomb
9
- VERSION = "0.0.2"
9
+ VERSION = "0.1.0"
10
10
  end
@@ -1,11 +1,15 @@
1
1
  module GiantBomb
2
- class Api
2
+ module Api
3
3
  include HTTParty
4
4
  base_uri 'api.giantbomb.com'
5
5
 
6
+ def self.config
7
+ @@config
8
+ end
9
+
6
10
  def self.key(api_key)
7
11
  @@config = { :api_key => api_key, :format => 'json' }
8
12
  end
9
-
10
13
  end
14
+
11
15
  end
@@ -0,0 +1,39 @@
1
+ module GiantBomb
2
+ class Character < Resource
3
+ has_resource 'character', :plural => 'characters'
4
+
5
+ # http://api.giantbomb.com/documentation/#character
6
+ @@fields = [
7
+ :aliases, # List of aliases that the character is known by. A \n (newline) separates each alias.
8
+ :api_detail_url, # URL pointing to the character detail resource
9
+ :birthday, # Birthday of the character
10
+ :companies, # Companies that have used the character in a game
11
+ :concepts, # Concepts related to the character
12
+ :date_added, # Date the character was added to Giant Bomb
13
+ :date_last_updated, # Date the character was last updated on Giant Bomb
14
+ :deck, # Brief summary of the character
15
+ :description, # Description of the character
16
+ :enemies, # Enemies of the character
17
+ :first_appeared_in_game, # Game that the character first appeared in
18
+ :franchises, # Franchises the character has appeared in
19
+ :friends, # Friends of the character
20
+ :games, # Games the character has appeared in
21
+ :gender, # Gender of the character. Available options are: Male, Female, Other
22
+ :id, # Unique ID of the character
23
+ :image, # Main Image of the character
24
+ :last_name, # Last name of the character
25
+ :locations, # Locations related to the character
26
+ :name, # Name of the character
27
+ :objects, # Objects related to the character
28
+ :people, # People who have worked with the character
29
+ :platforms, # Platforms having a game the character has appeared in
30
+ :real_name, # Real name of the character
31
+ :site_detail_url # URL pointing to the character on Giant Bomb
32
+ ]
33
+
34
+ @@fields.each do |field|
35
+ attr_accessor field
36
+ end
37
+
38
+ end
39
+ end
@@ -1,5 +1,7 @@
1
1
  module GiantBomb
2
- class Company < Api
2
+ class Company < Resource
3
+ has_resource 'company', :plural => 'companies'
4
+
3
5
  # http://api.giantbomb.com/documentation/#company
4
6
  @@fields = [
5
7
  :abbreviation, # Abbreviation of the company
@@ -35,39 +37,6 @@ module GiantBomb
35
37
  @@fields.each do |field|
36
38
  attr_accessor field
37
39
  end
38
-
39
- def initialize(attributes={})
40
- attributes.each do |key, value|
41
- if self.respond_to?(key.to_sym)
42
- self.instance_variable_set("@#{key}", value)
43
- end
44
- end
45
- end
46
-
47
- def self.detail(id, conditions={})
48
- search = GiantBomb::Search.new("/company/#{id}/")
49
- search.filter(conditions)
50
- Company.new(search.fetch)
51
- end
52
-
53
- def self.list(conditions={})
54
- search = GiantBomb::Search.new("/companies")
55
- search.filter(conditions)
56
- search.fetch.collect do |result|
57
- Company.new(result)
58
- end
59
- end
60
-
61
- def self.search(query)
62
- search = GiantBomb::Search.new
63
- search.resources('company')
64
- search.query(query)
65
- search.fetch
66
- end
67
-
68
- class << self
69
- alias_method :find, :search
70
- end
71
40
 
72
41
  end
73
42
  end
@@ -1,5 +1,7 @@
1
1
  module GiantBomb
2
- class Game < Api
2
+ class Game < Resource
3
+ has_resource 'game', :plural => 'games'
4
+
3
5
  # http://api.giantbomb.com/documentation/#game
4
6
  @@fields = [
5
7
  :aliases, # List of aliases the game is known by. A \n (newline) separates each alias.
@@ -45,39 +47,6 @@ module GiantBomb
45
47
  @@fields.each do |field|
46
48
  attr_accessor field
47
49
  end
48
-
49
- def initialize(attributes={})
50
- attributes.each do |key, value|
51
- if self.respond_to?(key.to_sym)
52
- self.instance_variable_set("@#{key}", value)
53
- end
54
- end
55
- end
56
-
57
- def self.detail(id, conditions={})
58
- search = GiantBomb::Search.new("/game/#{id}/")
59
- search.filter(conditions)
60
- Game.new(search.fetch)
61
- end
62
-
63
- def self.list(conditions={})
64
- search = GiantBomb::Search.new("/games")
65
- search.filter(conditions)
66
- search.fetch.collect do |result|
67
- Game.new(result)
68
- end
69
- end
70
-
71
- def self.search(query)
72
- search = GiantBomb::Search.new
73
- search.resources('game')
74
- search.query(query)
75
- search.fetch
76
- end
77
-
78
- class << self
79
- alias_method :find, :search
80
- end
81
50
 
82
51
  end
83
52
  end
@@ -0,0 +1,52 @@
1
+ module GiantBomb
2
+ class Resource
3
+ @@resource = {}
4
+
5
+ def self.has_resource(singular=nil, opts={})
6
+ @@resource[self.name.downcase] = {
7
+ :singular => singular.nil? ? "#{self.name.downcase}" : singular,
8
+ :plural => opts[:plural].nil? ? "#{self.name.downcase}s" : opts[:plural]
9
+ }
10
+ end
11
+
12
+ def self.resources
13
+ @@resource[self.name.downcase]
14
+ end
15
+
16
+ def self.detail(id, conditions={})
17
+ search = GiantBomb::Search.new("/#{self.resources[:singular]}/#{id}/")
18
+ search.filter(conditions)
19
+ self.new(search.fetch)
20
+ end
21
+
22
+ def self.list(conditions={})
23
+ search = GiantBomb::Search.new("/#{self.resources[:plural]}")
24
+ search.filter(conditions)
25
+ search.fetch.collect do |result|
26
+ self.new(result)
27
+ end
28
+ end
29
+
30
+ def self.search(query)
31
+ search = GiantBomb::Search.new
32
+ search.resources("#{self.resources[:singular]}")
33
+ search.query(query)
34
+ search.fetch.collect do |result|
35
+ self.new(result)
36
+ end
37
+ end
38
+
39
+ class << self
40
+ alias_method :find, :search
41
+ end
42
+
43
+ def initialize(attributes={})
44
+ attributes.each do |key, value|
45
+ if self.respond_to?(key.to_sym)
46
+ self.instance_variable_set("@#{key}", value)
47
+ end
48
+ end
49
+ end
50
+
51
+ end
52
+ end
@@ -1,5 +1,7 @@
1
1
  module GiantBomb
2
- class Search < Api
2
+ class Search
3
+ include GiantBomb::Api
4
+
3
5
  attr_reader :query, :resource
4
6
 
5
7
  def initialize(resource=nil)
@@ -53,8 +55,8 @@ module GiantBomb
53
55
 
54
56
  # GiantBomb::Search.new.query('duke nukem').fetch
55
57
  def fetch
56
- options = @params.merge(@@config)
57
- response = self.class.get(@resource, :query => options)
58
+ options = @params.merge(Api.config)
59
+ response = Api.get(@resource, :query => options)
58
60
  response['results']
59
61
  end
60
62
 
metadata CHANGED
@@ -5,9 +5,9 @@ version: !ruby/object:Gem::Version
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
+ - 1
8
9
  - 0
9
- - 2
10
- version: 0.0.2
10
+ version: 0.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Robert Coker
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-10 00:00:00 -05:00
18
+ date: 2011-01-11 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies: []
21
21
 
@@ -36,8 +36,10 @@ files:
36
36
  - giantbomb.gemspec
37
37
  - lib/giantbomb.rb
38
38
  - lib/giantbomb/api.rb
39
+ - lib/giantbomb/character.rb
39
40
  - lib/giantbomb/company.rb
40
41
  - lib/giantbomb/game.rb
42
+ - lib/giantbomb/resource.rb
41
43
  - lib/giantbomb/search.rb
42
44
  has_rdoc: true
43
45
  homepage: http://rubygems.org/gems/giantbomb