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 4 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
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ branches:
- master
before_install:
- gem update --system
- gem update bundler
- 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
134 changes: 69 additions & 65 deletions lib/yammer/http_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/yammer/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion spec/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions yam.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down