Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Gems #51

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ branches:
only:
- master
before_install:
- gem update --system
- gem i rubygems-update -v '<3' && update_rubygems
- gem --version
1 change: 1 addition & 0 deletions CONTRIBUTORS
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ Jessie A. Young
Jason Nochlin
Sandeep Sharma
Scott Balentine
Benjamin Elias
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
source 'https://rubygems.org'

group :test do
gem 'rspec', '>= 2.11'
gem 'rspec', '>= 3.9'
gem 'simplecov', :require => false
gem 'coveralls', :require => false
gem 'webmock', '>= 1.22.0'
gem 'webmock', '>= 3.8'
end

gemspec
9 changes: 7 additions & 2 deletions lib/yammer/http_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,12 @@ def send_request(method, path, opts={})
result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code)
rescue => e
if e.is_a?(RestClient::ExceptionWithResponse)
e.response
case e.http_code
when 301, 302, 307
raise RestClient::TooManyRequests
else
e.response
end
else
raise e
end
Expand All @@ -97,4 +102,4 @@ def parsed_url
end

end
end
end
93 changes: 48 additions & 45 deletions spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@
:headers => {
'Accept'=>'application/json',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
})
})
response = subject.send(:request, method, path, params)

expect(response.code).to eq 200
Expand Down Expand Up @@ -180,12 +180,12 @@
:body => {
"first_name"=>"john",
"last_name"=>"smith"
},
},
:headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
}).to_return(:status => 200, :body => "", :headers => {})
}).to_return(:status => 200, :body => "", :headers => {})

response =subject.send(:request, :post, path, params)
expect(response.code).to eq 200
Expand All @@ -206,14 +206,14 @@
},
:headers => {
'Accept'=>'application/json',
'Content-Type'=>'application/x-www-form-urlencoded',
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
'Content-Type' => 'application/x-www-form-urlencoded',
'Authorization' => 'Bearer TolNOFka9Uls2DxahNi78A',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}).
to_return(:status => 200, :body => "", :headers => {})
to_return(:status => 200, :body => "", :headers => {})

response = subject.send(:request, :put, path, params)
expect(response.code).to eq 200
response = subject.send(:request, :put, path, params)
expect(response.code).to eq 200
end
end

Expand All @@ -223,15 +223,21 @@
:body => params,
:headers => {
'Accept' =>'application/json',
'Accept-Encoding' => 'gzip, deflate',
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 303, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})

stub_request(:get, "https://www.yammer.com/members").
with(:headers => {'Accept'=>'application/json', 'Accept-Encoding'=>'gzip, deflate', 'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"}).
to_return(:status => 200, :body => "", :headers => {})
stub_request(:get, "https://www.yammer.com/members").with(
:headers => {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Authorization'=>'Bearer TolNOFka9Uls2DxahNi78A',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 200, :body => "", :headers => {})

response = subject.send(:request, :post, '/users', params)

expect(response.code).to eq 200
Expand All @@ -240,52 +246,49 @@
it "respects the redirect limit " do
subject.connection_options = { :max_redirects => 1 }

stub_request(:get, "https://www.yammer.com/users").
with(
:headers => {
'Accept' => 'application/json',
'Accept-Encoding'=> 'gzip, deflate',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})
stub_request(:get, "https://www.yammer.com/users").with(
:headers => {
'Accept' =>'application/json',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/members'})


stub_request(:get, "https://www.yammer.com/members").
with(
:headers => {
'Accept' => 'application/json',
'Accept-Encoding'=> 'gzip, deflate',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/people'})
stub_request(:get, "https://www.yammer.com/members").with(
:headers => {
'Accept' =>'application/json',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 301, :body => "", :headers => { 'Location' => 'https://www.yammer.com/people'})

expect { subject.send(:request, :get, '/users') }.to raise_error(RestClient::MaxRedirectsReached)
expect { subject.send(:request, :get, '/users') }.to raise_error(RestClient::TooManyRequests)
end

it "modifies http 303 redirect from POST to GET " do
params = { :first_name => 'jane', :last_name => 'doe' }
stub_request(:post, "https://www.yammer.com/users").with(
:body => params,
:headers => {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip, deflate',
'Content-Length'=>'29',
'Content-Type'=>'application/x-www-form-urlencoded',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
'Accept' => 'application/json',
'Accept-Encoding' => 'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'Content-Length' => '29',
'Content-Type' => 'application/x-www-form-urlencoded',
'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(
:status => 303,
:body => "you are being redirected",
:headers => {'Location' => "http://yammer.com/members"}
)

stub_request(:get, "http://yammer.com/members").
with(
:headers => {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip, deflate',
'User-Agent'=> "Yammer Ruby Gem #{Yammer::Version}"
}
stub_request(:get, "http://yammer.com/members").with(
:headers => {
'Accept'=>'application/json',
'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3',
'User-Agent'=>"Yammer Ruby Gem #{Yammer::Version}"
}
).to_return(:status => 200, :body => "", :headers => {})

response = subject.send(:request, :post, '/users', params )
Expand All @@ -307,7 +310,7 @@
:body => { :name => 'alice' }).to_return({
:status => 200, :body => "", :headers => {}
})
subject.post('/users', { :name => 'alice'})
subject.post('/users', { :name => 'alice'})
end
end

Expand All @@ -323,7 +326,7 @@
:body => { :name => 'bob' }).to_return(
:status => 200, :body => "", :headers => {})

subject.put('/users/1', { :name => 'bob'})
subject.put('/users/1', { :name => 'bob'})
end
end

Expand Down
5 changes: 4 additions & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@
require 'simplecov'
require 'coveralls'

SimpleCov.start
SimpleCov.start do
add_filter '/spec/'
end


require 'yammer'
require 'rspec'
Expand Down
18 changes: 9 additions & 9 deletions yam.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,17 @@ Gem::Specification.new do |s|
s.cert_chain = ['certs/public.pem']
s.signing_key = File.expand_path("~/.gem/certs/private_key.pem") if $0 =~ /gem\z/

s.add_dependency 'oj', '~> 2.14'
s.add_dependency 'multi_json', '~> 1.8'
s.add_dependency 'rest-client', '~> 1.8'
s.add_dependency 'addressable', '~> 2.4'
s.add_dependency 'oj', '~> 3.10'
s.add_dependency 'multi_json', '~> 1.14'
s.add_dependency 'rest-client', '~> 2.1'
s.add_dependency 'addressable', '~> 2.7'
s.add_dependency 'oauth2-client', '~> 2.0'

s.add_development_dependency 'rake', '~> 0'
s.add_development_dependency 'rspec', '~> 0'
s.add_development_dependency 'simplecov', '~> 0.11.1'
s.add_development_dependency 'webmock', '~> 1.17', '>= 1.17.0'
s.add_development_dependency 'yard', '~> 0.8', '>= 0.8.7'
s.add_development_dependency 'rake', '~> 13.0'
s.add_development_dependency 'rspec', '~> 3.9'
s.add_development_dependency 'simplecov', '~> 0.18'
s.add_development_dependency 'webmock', '~> 3.8'
s.add_development_dependency 'yard', '~> 0.9'

s.post_install_message = %q{ Thanks for installing! For API help go to http://developer.yammer.com }
end