Skip to content

Commit

Permalink
make raw_request available for all clients
Browse files Browse the repository at this point in the history
  • Loading branch information
yann ARMAND committed Jun 14, 2012
1 parent 9eca292 commit 793edf2
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 44 deletions.
43 changes: 3 additions & 40 deletions lib/yammer/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,46 +50,9 @@ def current_user
end
alias_method :me, :current_user

private

def yammer_request(http_method, options)
request_uri = @api_path + options.delete(:resource).to_s
[:action, :id].each {|k| request_uri += "/#{options.delete(k)}" if options.has_key?(k) }
request_uri += ".json"

if options.any?
request_uri += "?#{create_query_string(options)}" unless http_method == :post
end

if http_method == :post
handle_response(@access_token.send(http_method, request_uri, options))
else
handle_response(@access_token.send(http_method, request_uri))
end
end

def create_query_string(options)
options.map {|k, v| "#{OAuth::Helper.escape(k)}=#{OAuth::Helper.escape(v)}"}.join('&')
end

def mash(json)
Mash.new(json)
end

def handle_response(response)
# TODO: Write classes for exceptions
case response.code.to_i
when 200..201
response
when 400
raise "400 Bad request"
when 401
raise "Authentication failed. Check your username and password"
when 503
raise "503: Service Unavailable"
else
raise "Error. HTTP Response #{response.code}"
end
def raw_request(resource,options = {})
options.merge!({:resource => resource})
yammer_request(:get,options)
end

end
Expand Down
4 changes: 0 additions & 4 deletions lib/yammer/token_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,6 @@ def initialize(options={})
@access_token = options[:token]
end

def raw_request(resource,options = {})
options.merge!({:resource => resource})
yammer_request(:get,options)
end

private

Expand Down

0 comments on commit 793edf2

Please sign in to comment.