lib/http_services.rb in koala-0.6.0 vs lib/http_services.rb in koala-0.7.0
- old
+ new
@@ -1,6 +1,15 @@
module Koala
+ class Response
+ attr_reader :status, :body, :headers
+ def initialize(status, body, headers)
+ @status = status
+ @body = body
+ @headers = headers
+ end
+ end
+
module NetHTTPService
# this service uses Net::HTTP to send requests to the graph
def self.included(base)
base.class_eval do
require 'net/http' unless defined?(Net::HTTP)
@@ -22,11 +31,11 @@
# see http://redcorundum.blogspot.com/2008/03/ssl-certificates-and-nethttps.html
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
result = http.start { |http|
response, body = (verb == "post" ? http.post(path, encode_params(args)) : http.get("#{path}?#{encode_params(args)}"))
- body
+ Koala::Response.new(response.code.to_i, body, response.to_hash)
}
end
protected
def self.encode_params(param_hash)
@@ -50,10 +59,11 @@
def self.make_request(path, args, verb, options = {})
# if the verb isn't get or post, send it as a post argument
args.merge!({:method => verb}) && verb = "post" if verb != "get" && verb != "post"
server = options[:rest_api] ? Facebook::REST_SERVER : Facebook::GRAPH_SERVER
- self.send(verb, "https://#{server}/#{path}", :params => args).body
+ response = self.send(verb, "https://#{server}/#{path}", :params => args)
+ Koala::Response.new(response.code, response.body, response.headers_hash)
end
end # class_eval
end
end
end
\ No newline at end of file