From c72c90482e73747550a45f24ad0019f2e4869f34 Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Thu, 6 Jul 2017 21:23:43 +1000 Subject: [PATCH 1/6] Changes for rest-client 2.0.2 --- lib/yammer/http_adapter.rb | 134 +++++++++++++++++++------------------ spec/client_spec.rb | 2 +- yam.gemspec | 8 +-- 3 files changed, 74 insertions(+), 70 deletions(-) diff --git a/lib/yammer/http_adapter.rb b/lib/yammer/http_adapter.rb index 02abf8f..2f0b4e4 100644 --- a/lib/yammer/http_adapter.rb +++ b/lib/yammer/http_adapter.rb @@ -17,84 +17,88 @@ require 'addressable/uri' module Yammer -class HttpAdapter + class HttpAdapter - def self.log=(output) - RestClient.log = output - end + def self.log=(output) + RestClient.log = output + end - attr_reader :site_url, :connection_options + attr_reader :site_url, :connection_options - def initialize(site_url, opts={}) - unless site_url =~ /^https?/ - raise ArgumentError, "site_url must include either http or https scheme" + def initialize(site_url, opts={}) + unless site_url =~ /^https?/ + raise ArgumentError, "site_url must include either http or https scheme" + end + @site_url = site_url + @connection_options = opts end - @site_url = site_url - @connection_options = opts - end - # set the url to be used for creating an http connection - # @param url [string] - def site_url=(url) - @site_url = url - @host = nil - @scheme = nil - end + # set the url to be used for creating an http connection + # @param url [string] + def site_url=(url) + @site_url = url + @host = nil + @scheme = nil + end - def host - @host ||= parsed_url.host - end + def host + @host ||= parsed_url.host + end - def scheme - @scheme ||= parsed_url.scheme - end + def scheme + @scheme ||= parsed_url.scheme + end - def absolute_url(path='') - "#{@site_url}#{path}" - end + def absolute_url(path='') + "#{@site_url}#{path}" + end - def connection_options=(opts) - raise ArgumentError, 'expected Hash' unless opts.is_a?(Hash) - @connection_options = opts - end + def connection_options=(opts) + raise ArgumentError, 'expected Hash' unless opts.is_a?(Hash) + @connection_options = opts + end - def send_request(method, path, opts={}) - begin - params = opts.fetch(:params, {}) - - req_opts = self.connection_options.merge({ - :method => method, - :headers => opts.fetch(:headers, {}) - }) - - case method - when :get, :delete - query = Addressable::URI.form_encode(params) - normalized_path = query.empty? ? path : [path, query].join("?") - req_opts[:url] = absolute_url(normalized_path) - when :post, :put - req_opts[:payload] = params - req_opts[:url] = absolute_url(path) - else - raise "Unsupported HTTP method, #{method}" + def send_request(method, path, opts={}) + begin + params = opts.fetch(:params, {}) + + req_opts = self.connection_options.merge({ + :method => method, + :headers => opts.fetch(:headers, {}) + }) + + case method + when :get, :delete + query = Addressable::URI.form_encode(params) + normalized_path = query.empty? ? path : [path, query].join("?") + req_opts[:url] = absolute_url(normalized_path) + when :post, :put + req_opts[:payload] = params + req_opts[:url] = absolute_url(path) + else + raise "Unsupported HTTP method, #{method}" + end + + resp = RestClient::Request.execute(req_opts) + + result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code) + rescue => e + if e.is_a?(RestClient::ExceptionWithResponse) + if [301, 302, 307].include? e.http_code + raise e + else + e.response + end + else + raise e + end end + end - resp = RestClient::Request.execute(req_opts) - - result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code) - rescue => e - if e.is_a?(RestClient::ExceptionWithResponse) - e.response - else - raise e - end + private + def parsed_url + Addressable::URI.parse(@site_url) end - end -private - def parsed_url - Addressable::URI.parse(@site_url) end - end -end \ No newline at end of file diff --git a/spec/client_spec.rb b/spec/client_spec.rb index bea67fe..6a345b2 100755 --- a/spec/client_spec.rb +++ b/spec/client_spec.rb @@ -259,7 +259,7 @@ } ).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::ExceptionWithResponse) end it "modifies http 303 redirect from POST to GET " do diff --git a/yam.gemspec b/yam.gemspec index f9d0bb7..6d26803 100644 --- a/yam.gemspec +++ b/yam.gemspec @@ -43,10 +43,10 @@ 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', '~> 2.18' + s.add_dependency 'multi_json', '~> 1.12' + s.add_dependency 'rest-client', '~> 2.0' + s.add_dependency 'addressable', '~> 2.5' s.add_dependency 'oauth2-client', '~> 2.0' s.add_development_dependency 'rake', '~> 0' From 51f83c879e589e7fd838f93b67817d70e00d61ea Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Thu, 6 Jul 2017 21:40:04 +1000 Subject: [PATCH 2/6] updated Gem version --- lib/yammer/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/yammer/version.rb b/lib/yammer/version.rb index e327caa..107d950 100755 --- a/lib/yammer/version.rb +++ b/lib/yammer/version.rb @@ -15,7 +15,7 @@ module Yammer class Version MAJOR = 2 unless defined? Yammer::MAJOR - MINOR = 5 unless defined? Yammer::MINOR + MINOR = 6 unless defined? Yammer::MINOR PATCH = 0 unless defined? Yammer::PATCH PRE = nil unless defined? Yammer::PRE From d267cac94996df01401680f3a483bb151a7ec32b Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Thu, 6 Jul 2017 22:33:01 +1000 Subject: [PATCH 3/6] Update Travis CI bundler/bundler#3558 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index da0598e..74256d7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,4 +9,5 @@ branches: - master before_install: - gem update --system + - gem update bundler - gem --version From c37a1748634f724bdc034a350ae87b2ec07d37b4 Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Thu, 6 Jul 2017 22:51:49 +1000 Subject: [PATCH 4/6] Added change to force update --- CONTRIBUTORS | 1 + 1 file changed, 1 insertion(+) 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 From 6eed78e1cea7f74da6cf2eab7cfb3488055cab46 Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Tue, 3 Mar 2020 23:10:45 +1100 Subject: [PATCH 5/6] Updates for rspec and webmock --- .travis.yml | 1 - Gemfile | 4 +- lib/yammer/http_adapter.rb | 135 +++++++++++++++++++------------------ lib/yammer/version.rb | 2 +- spec/client_spec.rb | 93 ++++++++++++------------- spec/spec_helper.rb | 5 +- yam.gemspec | 18 ++--- 7 files changed, 132 insertions(+), 126 deletions(-) diff --git a/.travis.yml b/.travis.yml index 74256d7..da0598e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,5 +9,4 @@ branches: - master before_install: - gem update --system - - gem update bundler - gem --version 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 2f0b4e4..7aeb131 100644 --- a/lib/yammer/http_adapter.rb +++ b/lib/yammer/http_adapter.rb @@ -17,88 +17,89 @@ require 'addressable/uri' module Yammer - class HttpAdapter +class HttpAdapter - def self.log=(output) - RestClient.log = output - end - - attr_reader :site_url, :connection_options + def self.log=(output) + RestClient.log = output + end - def initialize(site_url, opts={}) - unless site_url =~ /^https?/ - raise ArgumentError, "site_url must include either http or https scheme" - end - @site_url = site_url - @connection_options = opts - end + attr_reader :site_url, :connection_options - # set the url to be used for creating an http connection - # @param url [string] - def site_url=(url) - @site_url = url - @host = nil - @scheme = nil + def initialize(site_url, opts={}) + unless site_url =~ /^https?/ + raise ArgumentError, "site_url must include either http or https scheme" end + @site_url = site_url + @connection_options = opts + end - def host - @host ||= parsed_url.host - end + # set the url to be used for creating an http connection + # @param url [string] + def site_url=(url) + @site_url = url + @host = nil + @scheme = nil + end - def scheme - @scheme ||= parsed_url.scheme - end + def host + @host ||= parsed_url.host + end - def absolute_url(path='') - "#{@site_url}#{path}" - end + def scheme + @scheme ||= parsed_url.scheme + end - def connection_options=(opts) - raise ArgumentError, 'expected Hash' unless opts.is_a?(Hash) - @connection_options = opts - end + def absolute_url(path='') + "#{@site_url}#{path}" + end - def send_request(method, path, opts={}) - begin - params = opts.fetch(:params, {}) - - req_opts = self.connection_options.merge({ - :method => method, - :headers => opts.fetch(:headers, {}) - }) - - case method - when :get, :delete - query = Addressable::URI.form_encode(params) - normalized_path = query.empty? ? path : [path, query].join("?") - req_opts[:url] = absolute_url(normalized_path) - when :post, :put - req_opts[:payload] = params - req_opts[:url] = absolute_url(path) - else - raise "Unsupported HTTP method, #{method}" - end + def connection_options=(opts) + raise ArgumentError, 'expected Hash' unless opts.is_a?(Hash) + @connection_options = opts + end - resp = RestClient::Request.execute(req_opts) + def send_request(method, path, opts={}) + begin + params = opts.fetch(:params, {}) + + req_opts = self.connection_options.merge({ + :method => method, + :headers => opts.fetch(:headers, {}) + }) + + case method + when :get, :delete + query = Addressable::URI.form_encode(params) + normalized_path = query.empty? ? path : [path, query].join("?") + req_opts[:url] = absolute_url(normalized_path) + when :post, :put + req_opts[:payload] = params + req_opts[:url] = absolute_url(path) + else + raise "Unsupported HTTP method, #{method}" + end - result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code) - rescue => e - if e.is_a?(RestClient::ExceptionWithResponse) - if [301, 302, 307].include? e.http_code - raise e - else - e.response - end + resp = RestClient::Request.execute(req_opts) + + result = Yammer::ApiResponse.new(resp.headers, resp.body, resp.code) + rescue => e + if e.is_a?(RestClient::ExceptionWithResponse) + case e.http_code + when 301, 302, 307 + raise RestClient::TooManyRequests else - raise e + e.response end + else + raise e end end + end - private - def parsed_url - Addressable::URI.parse(@site_url) - end - +private + def parsed_url + Addressable::URI.parse(@site_url) end + +end end diff --git a/lib/yammer/version.rb b/lib/yammer/version.rb index 107d950..e327caa 100755 --- a/lib/yammer/version.rb +++ b/lib/yammer/version.rb @@ -15,7 +15,7 @@ module Yammer class Version MAJOR = 2 unless defined? Yammer::MAJOR - MINOR = 6 unless defined? Yammer::MINOR + MINOR = 5 unless defined? Yammer::MINOR PATCH = 0 unless defined? Yammer::PATCH PRE = nil unless defined? Yammer::PRE diff --git a/spec/client_spec.rb b/spec/client_spec.rb index 6a345b2..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::ExceptionWithResponse) + 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 6d26803..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.18' - s.add_dependency 'multi_json', '~> 1.12' - s.add_dependency 'rest-client', '~> 2.0' - s.add_dependency 'addressable', '~> 2.5' + 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 From 8a77ae86c1e07173eb921046e6855e00612def91 Mon Sep 17 00:00:00 2001 From: Benjamin Elias Date: Tue, 3 Mar 2020 23:15:49 +1100 Subject: [PATCH 6/6] Attempt to avoid rubygems 3.x in Ruby < 2.3 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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