Skip to content

Commit

Permalink
Use FaradayMiddleware::Gzip in faraday_middleware 0.10.0
Browse files Browse the repository at this point in the history
This should eliminate the need for user to specify the "unzip" option
(introduced by #766) when a gzip'd content is returned through
Accept/Content-Encoding negotiation.

tumblr_agent currently refuses to work with faraday_middleware 0.10.0,
which version requirement must be relaxed. (tumblr/tumblr_client#48)
  • Loading branch information
knu committed Aug 3, 2015
1 parent 67ff37a commit 2caf45a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Gemfile
Expand Up @@ -29,7 +29,7 @@ gem 'twitter-stream', github: 'cantino/twitter-stream', branch: 'huginn'
gem 'omniauth-twitter'

# Tumblr Agents
gem 'tumblr_client'
gem 'tumblr_client', github: 'knu/tumblr_client', branch: 'patch-1'
gem 'omniauth-tumblr'

# Dropbox Agents
Expand Down Expand Up @@ -64,7 +64,7 @@ gem 'devise', '~> 3.4.0'
gem 'dotenv-rails', '~> 2.0.1'
gem 'em-http-request', '~> 1.1.2'
gem 'faraday', '~> 0.9.0'
gem 'faraday_middleware'
gem 'faraday_middleware', '>= 0.10.0'
gem 'feed-normalizer'
gem 'font-awesome-sass', '~> 4.3.2'
gem 'foreman', '~> 0.63.0'
Expand Down
26 changes: 16 additions & 10 deletions Gemfile.lock
Expand Up @@ -19,6 +19,19 @@ GIT
oauth2 (~> 0.9.1)
rest-client (~> 1.8)

GIT
remote: git://github.com/knu/tumblr_client.git
revision: d6f1f64a7cba381345c588e28ebcff28048c3a6c
branch: patch-1
specs:
tumblr_client (0.8.5)
faraday (~> 0.9.0)
faraday_middleware (~> 0.9)
json
mime-types
oauth
simple_oauth

GIT
remote: git://github.com/wunderlist/omniauth-wunderlist.git
revision: d0910d0396107b9302aa1bc50e74bb140990ccb8
Expand Down Expand Up @@ -153,7 +166,7 @@ GEM
extlib (0.9.16)
faraday (0.9.1)
multipart-post (>= 1.2, < 3)
faraday_middleware (0.9.1)
faraday_middleware (0.10.0)
faraday (>= 0.7.4, < 0.10)
feed-normalizer (1.5.2)
hpricot (>= 0.6)
Expand Down Expand Up @@ -437,13 +450,6 @@ GEM
tins (1.3.2)
treetop (1.5.3)
polyglot (~> 0.3)
tumblr_client (0.8.4)
faraday (~> 0.9.0)
faraday_middleware (~> 0.9.0)
json
mime-types
oauth
simple_oauth
twilio-ruby (3.11.6)
builder (>= 2.1.2)
jwt (>= 0.1.2)
Expand Down Expand Up @@ -508,7 +514,7 @@ DEPENDENCIES
dropbox-api
em-http-request (~> 1.1.2)
faraday (~> 0.9.0)
faraday_middleware
faraday_middleware (>= 0.10.0)
feed-normalizer
ffi (>= 1.9.4)
font-awesome-sass (~> 4.3.2)
Expand Down Expand Up @@ -566,7 +572,7 @@ DEPENDENCIES
spring-commands-rspec
string-scrub
therubyracer (~> 0.12.2)
tumblr_client
tumblr_client!
twilio-ruby (~> 3.11.5)
twitter (~> 5.14.0)
twitter-stream!
Expand Down
2 changes: 2 additions & 0 deletions app/concerns/web_request_concern.rb
Expand Up @@ -59,6 +59,8 @@ def faraday
builder.request :basic_auth, *userinfo
end

builder.use FaradayMiddleware::Gzip

case backend = faraday_backend
when :typhoeus
require 'typhoeus/adapters/faraday'
Expand Down
31 changes: 30 additions & 1 deletion spec/models/agents/website_agent_spec.rb
Expand Up @@ -170,6 +170,35 @@
end

describe 'unzipping' do
it 'should unzip automatically if the response has Content-Encoding: gzip' do
json = {
'response' => {
'version' => 2,
'title' => "hello!"
}
}
zipped = ActiveSupport::Gzip.compress(json.to_json)
stub_request(:any, /gzip/).to_return(body: zipped, headers: { 'Content-Encoding' => 'gzip' }, status: 200)
site = {
'name' => "Some JSON Response",
'expected_update_period_in_days' => "2",
'type' => "json",
'url' => "http://gzip.com",
'mode' => 'on_change',
'extract' => {
'version' => { 'path' => 'response.version' },
},
# no unzip option
}
checker = Agents::WebsiteAgent.new(:name => "Weather Site", :options => site)
checker.user = users(:bob)
checker.save!

checker.check
event = Event.last
expect(event.payload['version']).to eq(2)
end

it 'should unzip with unzip option' do
json = {
'response' => {
Expand All @@ -178,7 +207,7 @@
}
}
zipped = ActiveSupport::Gzip.compress(json.to_json)
stub_request(:any, /gzip/).to_return(:body => zipped, :status => 200)
stub_request(:any, /gzip/).to_return(body: zipped, status: 200)
site = {
'name' => "Some JSON Response",
'expected_update_period_in_days' => "2",
Expand Down

0 comments on commit 2caf45a

Please sign in to comment.