Skip to content

Commit

Permalink
return a response object instead of just a string
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Mar 17, 2010
1 parent 3aa13a7 commit 7385d00
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion lib/zendesk/main.rb
Expand Up @@ -60,7 +60,32 @@ def make_request(end_url, body = {})
if curl.body_str == "<error>Couldn't authenticate you</error>"
return "string" #raise CouldNotAuthenticateYou
end
curl.body_str
Response.new(curl)
end

class Response

attr_reader :status, :body, :headers_raw, :headers

def initialize(curl)
@status=curl.response_code
@body=curl.body_str
@headers_raw=curl.header_str
parse_headers
end

def parse_headers
hs={}
headers_raw.split("\r\n")[1..-1].each do |h|
# Rails.logger.info h
m=h.match(/([^:]+):\s?(.*)/)
next if m.nil? or m[2].nil?
# Rails.logger.info m.inspect
hs[m[1]]=m[2]
end
@headers=hs
end

end

include Zendesk::User
Expand Down

0 comments on commit 7385d00

Please sign in to comment.