reviewed 1.0.2 → 1.0.3

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: 5d738df20dc24d39375300b0a37b0a9e0532759c
4
- data.tar.gz: f6dfd6688353ac8a48d4969773aa5631848d8960
3
+ metadata.gz: cb80d253dffaf3400f36312ac88e8b23ff0cebb0
4
+ data.tar.gz: 58cf68e0686953752759e43a84b1ba10391c7532
5
5
  SHA512:
6
- metadata.gz: c1a7b307ba762476e641730fc1ae6a81e58af8c7d036a936883ba467c52e1d5ed5463cbd580befbcf0ed44c86b4c032cd090beaae5476e85945a9ee0813da6f8
7
- data.tar.gz: ee756006f5a2d295ecef726d4c25001aa433eb15a20ad2b0067ebff113402536c505bf1c6e6d1e8b8170ebfbf9318cfa561db1940a22b9b20e1a877617e4b217
6
+ metadata.gz: 7f27184cff50410fe59a27c30b2e24b3130652f320934bdf231537e92925b87720ddad50b84b597ae5504e112a42e3770ba45baa868083ec5a6481a33e263e38
7
+ data.tar.gz: 777670dd116d31c39ec4b12b92568be2d37e16d8bc5d2fd9a1a8cc14f110861adf874451ce09f5815a70e99801e7294f7fe06c4ad251a4c2ecc05d450effb041
@@ -64,7 +64,6 @@ module Reviewed
64
64
 
65
65
  def connection
66
66
  @connection ||= ::Faraday.new(url: base_uri) do |faraday|
67
- faraday.use Faraday::Cache if ENV['REVIEWED_CACHE_REDIS_URL']
68
67
  faraday.response :mashify
69
68
  faraday.response :errors
70
69
  faraday.response :json
@@ -1,4 +1,4 @@
1
1
  module Reviewed
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.3"
3
3
  API_VERSION = 'v1'
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reviewed
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Plante
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-05 00:00:00.000000000 Z
12
+ date: 2013-11-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activesupport
@@ -222,7 +222,6 @@ files:
222
222
  - README.md
223
223
  - Rakefile
224
224
  - lib/faraday/api_key.rb
225
- - lib/faraday/cache.rb
226
225
  - lib/faraday/errors.rb
227
226
  - lib/reviewed.rb
228
227
  - lib/reviewed/article.rb
@@ -232,7 +231,6 @@ files:
232
231
  - lib/reviewed/award.rb
233
232
  - lib/reviewed/base.rb
234
233
  - lib/reviewed/brand.rb
235
- - lib/reviewed/cache.rb
236
234
  - lib/reviewed/client.rb
237
235
  - lib/reviewed/collection.rb
238
236
  - lib/reviewed/deal.rb
@@ -257,7 +255,6 @@ files:
257
255
  - spec/embeddable_spec.rb
258
256
  - spec/error_spec.rb
259
257
  - spec/faraday/api_key_spec.rb
260
- - spec/faraday/cache_spec.rb
261
258
  - spec/faraday/errors_spec.rb
262
259
  - spec/fixtures/vcr/Reviewed_Article/associations/attachments/assigns_attachments_to_the_correct_class.yml
263
260
  - spec/fixtures/vcr/Reviewed_Article/associations/attachments/does_not_has_many_attachments.yml
@@ -335,7 +332,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
335
332
  version: '0'
336
333
  requirements: []
337
334
  rubyforge_project:
338
- rubygems_version: 2.0.3
335
+ rubygems_version: 2.0.2
339
336
  signing_key:
340
337
  specification_version: 4
341
338
  summary: A Ruby Gem for Accessing the Reviewed.com API
@@ -351,7 +348,6 @@ test_files:
351
348
  - spec/embeddable_spec.rb
352
349
  - spec/error_spec.rb
353
350
  - spec/faraday/api_key_spec.rb
354
- - spec/faraday/cache_spec.rb
355
351
  - spec/faraday/errors_spec.rb
356
352
  - spec/fixtures/vcr/Reviewed_Article/associations/attachments/assigns_attachments_to_the_correct_class.yml
357
353
  - spec/fixtures/vcr/Reviewed_Article/associations/attachments/does_not_has_many_attachments.yml
data/lib/faraday/cache.rb DELETED
@@ -1,56 +0,0 @@
1
- require 'reviewed/cache'
2
-
3
- module Faraday
4
- class Cache
5
-
6
- def initialize(app)
7
- @app = app
8
- end
9
-
10
- def store
11
- Reviewed::Cache.store
12
- end
13
-
14
- def call(env)
15
- @url = env[:url]
16
-
17
- @website_id = env[:request_headers]['x-reviewed-website']
18
-
19
- if serve_from_cache? && store.exist?(cache_key)
20
- begin
21
- Hashie::Mash.new(MultiJson.load( store.read(cache_key) ))
22
- rescue => e
23
- raise e.message + ": #{cache_key}"
24
- end
25
- else
26
- @app.call(env).on_complete do |response|
27
- if store_response?(response)
28
- store.delete(cache_key)
29
- storeable_response = MultiJson.dump(response.slice(:status, :body, :response_headers))
30
- store.write(cache_key, storeable_response, write_options)
31
- end
32
- end
33
- end
34
- end
35
-
36
- private
37
-
38
- def serve_from_cache?
39
- @url.query.blank? || !@url.query.match(/\b(skip|reset)-cache\b/)
40
- end
41
-
42
- def store_response?(resp)
43
- return false if resp[:status] != 200
44
- @url.query.blank? || !@url.query.match(/\bskip-cache\b/)
45
- end
46
-
47
- def cache_key
48
- [@website_id, @url.request_uri].join(':')
49
- end
50
-
51
- def write_options
52
- { expires_in: Integer(ENV['REVIEWED_CACHE_TIMEOUT'] || 90).minutes }
53
- end
54
-
55
- end
56
- end
@@ -1,18 +0,0 @@
1
- require 'active_support/cache'
2
- require 'singleton'
3
-
4
- module Reviewed
5
- class Cache
6
- include Singleton
7
-
8
- def self.store
9
- @store ||= if ENV['REVIEWED_CACHE_REDIS_URL']
10
- puts "Reviewed::Cache - connecting to #{ENV['REVIEWED_CACHE_REDIS_URL']}"
11
- ActiveSupport::Cache.lookup_store(:redis_store, ENV['REVIEWED_CACHE_REDIS_URL'])
12
- else
13
- ActiveSupport::Cache.lookup_store(:memory_store)
14
- end
15
- end
16
-
17
- end
18
- end
@@ -1,67 +0,0 @@
1
- require 'spec_helper'
2
-
3
-
4
- describe Faraday::Cache do
5
-
6
- describe 'call' do
7
-
8
- conn = Faraday.new do |builder|
9
- builder.use Faraday::Cache
10
- builder.adapter :test, Faraday::Adapter::Test::Stubs.new do |stub|
11
- stub.get('/articles') { [200, {}, 'I like turtles'] }
12
- stub.get('/products') { [200, {}, 'Weee products'] }
13
- stub.get('/kaboom') { [500, {}, 'Kaboom'] }
14
- end
15
- end
16
-
17
- conn.headers = { "X-Reviewed-Website" => 'f0000123' }
18
-
19
- it "caches anything that doesn't have skip-cache or reset-cache" do
20
- mock_cache_val = double
21
- MultiJson.stub(:dump).with(hash_including(:body => 'I like turtles')).and_return(mock_cache_val)
22
- Reviewed::Cache.store.should_receive(:write).with("f0000123:/articles", mock_cache_val, anything)
23
- conn.get('/articles')
24
- end
25
-
26
- it "can cache more than one thing" do
27
- mock_cache_val = double
28
- MultiJson.stub(:dump => mock_cache_val)
29
- Reviewed::Cache.store.should_receive(:write).with("f0000123:/articles", mock_cache_val, anything)
30
- Reviewed::Cache.store.should_receive(:write).with("f0000123:/products", mock_cache_val, anything)
31
-
32
- conn.get('/articles')
33
- conn.get('/products')
34
- end
35
-
36
- it "serves responses from the cache when fresh and does not call the app" do
37
- marshalled_response = MultiJson.dump(body: 'old musty response')
38
- Reviewed::Cache.store.stub(:exist? => true)
39
- Reviewed::Cache.store.should_receive(:read).with("f0000123:/articles").and_return(marshalled_response)
40
- resp = conn.get '/articles'
41
- resp[:body].should eq("old musty response")
42
- end
43
-
44
- it "does not store response when result is 500" do
45
- Reviewed::Cache.store.should_not_receive(:write)
46
- conn.get('/kaboom')
47
- end
48
-
49
- describe "cache busting and skipping" do
50
- it "does not cache responses with skip-cache as a query param" do
51
- Reviewed::Cache.store.should_not_receive(:read)
52
- Reviewed::Cache.store.should_not_receive(:write)
53
- conn.get '/articles', {:"skip-cache" => true}
54
- end
55
-
56
- it "replaces cached content with app response when reset-cache is a query param" do
57
- mock_cache_val = double
58
- MultiJson.stub(:dump).and_return(mock_cache_val)
59
- Reviewed::Cache.store.should_not_receive(:read)
60
- Reviewed::Cache.store.should_receive(:write)
61
- conn.get '/articles', {:"reset-cache" => true}
62
- end
63
- end
64
-
65
- end
66
-
67
- end