giant_bomb 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da5d382e27fb7701bfb22b3f2383467e6a8353c5
4
+ data.tar.gz: cf9455bc85de35b763b8f5bb5d8b455a2644577d
5
+ SHA512:
6
+ metadata.gz: 784f6fcd68be6dd355ccf318dcccc314cc93b5e3e228ff59e40cb0912e861db2fed10172c17428ed583d6b34f73c9604fc0dfbbd4324a3b7922547c4dde7fa17
7
+ data.tar.gz: a91e7c9113a1570135c3046c775815dbe15d52f734f48ceb2abf1b0ac78d2906faa887e72dd58c7a845a41977e337ab940a84b121028b6fc0064294554f97260
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.0
1
+ 0.5.0
data/giant_bomb.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "giant_bomb"
8
- s.version = "0.4.0"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Jon Maddox"]
12
- s.date = "2013-06-22"
12
+ s.date = "2013-10-29"
13
13
  s.description = "Simple library to talkto the awesome GiantBomb data"
14
14
  s.email = "jon@fanzter.com"
15
15
  s.extra_rdoc_files = [
@@ -29,7 +29,6 @@ Gem::Specification.new do |s|
29
29
  "lib/giant_bomb/developer.rb",
30
30
  "lib/giant_bomb/game.rb",
31
31
  "lib/giant_bomb/genre.rb",
32
- "lib/giant_bomb/httparty_icebox.rb",
33
32
  "lib/giant_bomb/publisher.rb",
34
33
  "lib/giant_bomb/search.rb",
35
34
  "test/fixtures/get_info.json",
@@ -42,11 +41,11 @@ Gem::Specification.new do |s|
42
41
  ]
43
42
  s.homepage = "http://github.com/fanzter/giant_bomb"
44
43
  s.require_paths = ["lib"]
45
- s.rubygems_version = "1.8.23"
44
+ s.rubygems_version = "2.0.3"
46
45
  s.summary = "Simple library to talk to the awesome GiantBomb data"
47
46
 
48
47
  if s.respond_to? :specification_version then
49
- s.specification_version = 3
48
+ s.specification_version = 4
50
49
 
51
50
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
52
51
  s.add_runtime_dependency(%q<httparty>, [">= 0.4.3"])
data/lib/giant_bomb.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  require 'httparty'
2
2
 
3
3
  directory = File.expand_path(File.dirname(__FILE__))
4
- require File.join(directory, 'giant_bomb', 'httparty_icebox')
5
4
  require File.join(directory, 'giant_bomb', 'core_extensions')
6
5
  require File.join(directory, 'giant_bomb', 'attributes')
7
6
  require File.join(directory, 'giant_bomb', 'search')
@@ -2,20 +2,18 @@ module GiantBomb
2
2
  class Search
3
3
  include HTTParty
4
4
  format :json
5
- include HTTParty::Icebox
6
- cache :store => 'file', :timeout => 120, :location => Dir.tmpdir
7
-
5
+
8
6
  base_uri 'api.giantbomb.com'
9
7
 
10
8
  def initialize(the_api_key)
11
9
  @api_key = the_api_key
12
10
  end
13
-
11
+
14
12
  def default_query_options
15
13
  {"api_key" => @api_key, "format" => 'json'}
16
14
  end
17
-
18
-
15
+
16
+
19
17
  # http://api.giantbomb.com/search/?api_key=ABCDEF123456&query=halo&resources=game&format=json
20
18
  def find_game(keywords)
21
19
  options = {"query" => keywords, "resources" => "game"}
@@ -40,4 +38,4 @@ module GiantBomb
40
38
  end
41
39
 
42
40
  end
43
- end
41
+ end
metadata CHANGED
@@ -1,62 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: giant_bomb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Jon Maddox
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-06-22 00:00:00.000000000 Z
11
+ date: 2013-10-29 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: httparty
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: 0.4.3
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
28
25
  - !ruby/object:Gem::Version
29
26
  version: 0.4.3
30
27
  - !ruby/object:Gem::Dependency
31
28
  name: fakeweb
32
29
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
30
  requirements:
35
- - - ! '>='
31
+ - - '>='
36
32
  - !ruby/object:Gem::Version
37
33
  version: '0'
38
34
  type: :development
39
35
  prerelease: false
40
36
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
37
  requirements:
43
- - - ! '>='
38
+ - - '>='
44
39
  - !ruby/object:Gem::Version
45
40
  version: '0'
46
41
  - !ruby/object:Gem::Dependency
47
42
  name: thoughtbot-shoulda
48
43
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
44
  requirements:
51
- - - ! '>='
45
+ - - '>='
52
46
  - !ruby/object:Gem::Version
53
47
  version: '0'
54
48
  type: :development
55
49
  prerelease: false
56
50
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
51
  requirements:
59
- - - ! '>='
52
+ - - '>='
60
53
  - !ruby/object:Gem::Version
61
54
  version: '0'
62
55
  description: Simple library to talkto the awesome GiantBomb data
@@ -79,7 +72,6 @@ files:
79
72
  - lib/giant_bomb/developer.rb
80
73
  - lib/giant_bomb/game.rb
81
74
  - lib/giant_bomb/genre.rb
82
- - lib/giant_bomb/httparty_icebox.rb
83
75
  - lib/giant_bomb/publisher.rb
84
76
  - lib/giant_bomb/search.rb
85
77
  - test/fixtures/get_info.json
@@ -91,26 +83,25 @@ files:
91
83
  - test/test_helper.rb
92
84
  homepage: http://github.com/fanzter/giant_bomb
93
85
  licenses: []
86
+ metadata: {}
94
87
  post_install_message:
95
88
  rdoc_options: []
96
89
  require_paths:
97
90
  - lib
98
91
  required_ruby_version: !ruby/object:Gem::Requirement
99
- none: false
100
92
  requirements:
101
- - - ! '>='
93
+ - - '>='
102
94
  - !ruby/object:Gem::Version
103
95
  version: '0'
104
96
  required_rubygems_version: !ruby/object:Gem::Requirement
105
- none: false
106
97
  requirements:
107
- - - ! '>='
98
+ - - '>='
108
99
  - !ruby/object:Gem::Version
109
100
  version: '0'
110
101
  requirements: []
111
102
  rubyforge_project:
112
- rubygems_version: 1.8.23
103
+ rubygems_version: 2.0.3
113
104
  signing_key:
114
- specification_version: 3
105
+ specification_version: 4
115
106
  summary: Simple library to talk to the awesome GiantBomb data
116
107
  test_files: []
@@ -1,259 +0,0 @@
1
- # = Icebox : Caching for HTTParty
2
- #
3
- # Cache responses in HTTParty models [http://github.com/jnunemaker/httparty]
4
- #
5
- # === Usage
6
- #
7
- # class Foo
8
- # include HTTParty
9
- # include HTTParty::Icebox
10
- # cache :store => 'file', :timeout => 600, :location => MY_APP_ROOT.join('tmp', 'cache')
11
- # end
12
- #
13
- # Modeled after Martyn Loughran's APICache [http://github.com/newbamboo/api_cache]
14
- # and Ruby On Rails's caching [http://api.rubyonrails.org/classes/ActiveSupport/Cache.html]
15
- #
16
- # Author: Karel Minarik [www.karmi.cz]
17
- #
18
- # === Notes
19
- #
20
- # Thanks to Amit Chakradeo to point out objects have to be stored marhalled on FS
21
- # Thanks to Marlin Forbes to point out query parameters have to be include in the cache key
22
- #
23
- #
24
-
25
- require 'logger'
26
- require 'fileutils'
27
- require 'tmpdir'
28
- require 'pathname'
29
- require 'digest/md5'
30
-
31
- module HTTParty #:nodoc:
32
- module Icebox
33
-
34
- module ClassMethods
35
-
36
- # Enable caching and set cache options
37
- # Returns memoized cache object
38
- #
39
- # Following options are available, default values are in []:
40
- #
41
- # +store+:: Storage mechanism for cached data (memory, filesystem, your own) [memory]
42
- # +timeout+:: Cache expiration in seconds [60]
43
- # +logger+:: Path to logfile or logger instance [STDOUT]
44
- #
45
- # Any additional options are passed to the Cache constructor
46
- #
47
- # Usage:
48
- #
49
- # # Enable caching in HTTParty, in memory, for 1 minute
50
- # cache # Use default values
51
- #
52
- # # Enable caching in HTTParty, on filesystem (/tmp), for 10 minutes
53
- # cache :store => 'file', :timeout => 600, :location => '/tmp/'
54
- #
55
- # # Use your own cache store (see AbstractStore class below)
56
- # cache :store => 'memcached', :timeout => 600, :server => '192.168.1.1:1001'
57
- #
58
- def cache(options={})
59
- options[:store] ||= 'memory'
60
- options[:timeout] ||= 60
61
- logger = options[:logger]
62
- @cache ||= Cache.new( options.delete(:store), options )
63
- end
64
-
65
- end
66
-
67
- # When included, extend class with +cache+ method
68
- # and redefine +get+ method to use cache
69
- #
70
- def self.included(receiver) #:nodoc:
71
- receiver.extend ClassMethods
72
- receiver.class_eval do
73
-
74
- # Get reponse from network
75
- # TODO: Why alias :new :old is not working here? Returns NoMethodError
76
- #
77
- def self.get_without_caching(path, options={})
78
- perform_request Net::HTTP::Get, path, options
79
- end
80
-
81
- # Get response from cache, if available
82
- #
83
- def self.get_with_caching(path, options={})
84
- key = path.clone
85
- key << options[:query].to_s if defined? options[:query]
86
-
87
- if cache.exists?(key) and not cache.stale?(key)
88
- Cache.logger.debug "CACHE -- GET #{path}#{options[:query]}"
89
- return cache.get(key)
90
- else
91
- Cache.logger.debug "/!\\ NETWORK -- GET #{path}#{options[:query]}"
92
- response = get_without_caching(path, options)
93
- cache.set(key, response) if response.code == 200
94
- return response
95
- end
96
- end
97
-
98
- # Redefine original HTTParty +get+ method to use cache
99
- #
100
- def self.get(path, options={})
101
- self.get_with_caching(path, options)
102
- end
103
-
104
- end
105
- end
106
-
107
- # === Cache container
108
- #
109
- # Pass a store name ('memory', etc) to initializer
110
- #
111
- class Cache
112
- attr_accessor :store
113
-
114
- def initialize(store, options={})
115
- self.class.logger = options[:logger]
116
- @store = self.class.lookup_store(store).new(options)
117
- end
118
-
119
- def get(key); @store.get encode(key) unless stale?(key); end
120
- def set(key, value); @store.set encode(key), value; end
121
- def exists?(key); @store.exists? encode(key); end
122
- def stale?(key); @store.stale? encode(key); end
123
-
124
- def self.logger; @logger || default_logger; end
125
- def self.default_logger; logger = ::Logger.new(STDERR); end
126
-
127
- # Pass a filename (String), IO object, Logger instance or +nil+ to silence the logger
128
- def self.logger=(device); @logger = device.kind_of?(::Logger) ? device : ::Logger.new(device); end
129
-
130
- private
131
-
132
- # Return store class based on passed name
133
- def self.lookup_store(name)
134
- store_name = "#{name.capitalize}Store"
135
- return Store::const_get(store_name)
136
- rescue NameError => e
137
- raise Store::StoreNotFound, "The cache store '#{store_name}' was not found. Did you loaded any such class?"
138
- end
139
-
140
- def encode(key); Digest::MD5.hexdigest(key); end
141
- end
142
-
143
-
144
- # === Cache stores
145
- #
146
- module Store
147
-
148
- class StoreNotFound < StandardError; end #:nodoc:
149
-
150
- # ==== Abstract Store
151
- # Inherit your store from this class
152
- # *IMPORTANT*: Do not forget to call +super+ in your +initialize+ method!
153
- #
154
- class AbstractStore
155
- def initialize(options={})
156
- raise ArgumentError, "You need to set the :timeout parameter" unless options[:timeout]
157
- @timeout = options[:timeout]
158
- message = "Cache: Using #{self.class.to_s.split('::').last}"
159
- message << " in location: #{options[:location]}" if options[:location]
160
- message << " with timeout #{options[:timeout]} sec"
161
- Cache.logger.info message unless options[:logger].nil?
162
- return self
163
- end
164
- %w{set get exists? stale?}.each do |method_name|
165
- define_method(method_name) { raise NoMethodError, "Please implement method set in your store class" }
166
- end
167
- end
168
-
169
- # ===== Store objects in memory
170
- #
171
- Struct.new("GiantBombResponse", :code, :body, :headers) { def to_s; self.body; end }
172
- class MemoryStore < AbstractStore
173
- def initialize(options={})
174
- super; @store = {}; self
175
- end
176
- def set(key, value)
177
- Cache.logger.info("Cache: set (#{key})")
178
- @store[key] = [Time.now, value]; true
179
- end
180
- def get(key)
181
- data = @store[key][1]
182
- Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
183
- data
184
- end
185
- def exists?(key)
186
- !@store[key].nil?
187
- end
188
- def stale?(key)
189
- return true unless exists?(key)
190
- Time.now - created(key) > @timeout
191
- end
192
- private
193
- def created(key)
194
- @store[key][0]
195
- end
196
- end
197
-
198
- # ===== Store objects on the filesystem
199
- #
200
- class FileStore < AbstractStore
201
- def initialize(options={})
202
- super
203
- options[:location] ||= Dir::tmpdir
204
- @path = Pathname.new( options[:location] )
205
- FileUtils.mkdir_p( @path )
206
- self
207
- end
208
- def set(key, value)
209
- Cache.logger.info("Cache: set (#{key})")
210
- File.open( @path.join(key), 'w' ) { |file| Marshal.dump(value, file) }
211
- true
212
- end
213
- def get(key)
214
- data = Marshal.load(File.new(@path.join(key)))
215
- Cache.logger.info("Cache: #{data.nil? ? "miss" : "hit"} (#{key})")
216
- data
217
- end
218
- def exists?(key)
219
- File.exists?( @path.join(key) )
220
- end
221
- def stale?(key)
222
- return true unless exists?(key)
223
- Time.now - created(key) > @timeout
224
- end
225
- private
226
- def created(key)
227
- File.mtime( @path.join(key) )
228
- end
229
- end
230
- end
231
-
232
- end
233
- end
234
-
235
-
236
- # Major parts of this code are based on architecture of ApiCache.
237
- # Copyright (c) 2008 Martyn Loughran
238
- #
239
- # Other parts are inspired by the ActiveSupport::Cache in Ruby On Rails.
240
- # Copyright (c) 2005-2009 David Heinemeier Hansson
241
- #
242
- # Permission is hereby granted, free of charge, to any person obtaining
243
- # a copy of this software and associated documentation files (the
244
- # "Software"), to deal in the Software without restriction, including
245
- # without limitation the rights to use, copy, modify, merge, publish,
246
- # distribute, sublicense, and/or sell copies of the Software, and to
247
- # permit persons to whom the Software is furnished to do so, subject to
248
- # the following conditions:
249
- #
250
- # The above copyright notice and this permission notice shall be
251
- # included in all copies or substantial portions of the Software.
252
- #
253
- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
254
- # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
255
- # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
256
- # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
257
- # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
258
- # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
259
- # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.