diff --git a/.travis.yml b/.travis.yml index da0598e..3fbb286 100644 --- a/.travis.yml +++ b/.travis.yml @@ -8,5 +8,5 @@ branches: only: - master before_install: - - gem update --system + - gem i rubygems-update -v '<3' && update_rubygems - gem --version diff --git a/CONTRIBUTORS b/CONTRIBUTORS index 12eb02d..714187d 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -2,3 +2,4 @@ Jessie A. Young Jason Nochlin Sandeep Sharma Scott Balentine +Benjamin Elias diff --git a/Gemfile b/Gemfile index 8e14f18..2cac5cc 100755 --- a/Gemfile +++ b/Gemfile @@ -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 diff --git a/lib/yammer/http_adapter.rb b/lib/yammer/http_adapter.rb index 02abf8f..7aeb131 100644 --- a/lib/yammer/http_adapter.rb +++ b/lib/yammer/http_adapter.rb @@ -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 @@ -97,4 +102,4 @@ def parsed_url end end -end \ No newline at end of file +end diff --git a/spec/client_spec.rb b/spec/client_spec.rb index bea67fe..66683cf 100755 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -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 @@ -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 @@ -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 @@ -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 @@ -240,26 +246,24 @@ 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 @@ -267,11 +271,11 @@ 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, @@ -279,13 +283,12 @@ :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 ) @@ -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 @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6c34ddc..7e05e8b 100755 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -20,7 +20,10 @@ require 'simplecov' require 'coveralls' -SimpleCov.start +SimpleCov.start do + add_filter '/spec/' +end + require 'yammer' require 'rspec' diff --git a/yam.gemspec b/yam.gemspec index f9d0bb7..268a108 100644 --- a/yam.gemspec +++ b/yam.gemspec @@ -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