Sha256: 9a67075892d9ec3ce7141eb2d203b074e48826ef3a46604b6600e77bc6f63c4b

Contents?: true

Size: 1.02 KB

Versions: 32

Compression:

Stored size: 1.02 KB

Contents

module RestClient
	module Mixin
		module Response
			attr_reader :net_http_res

			# HTTP status code, always 200 since RestClient throws exceptions for
			# other codes.
			def code
				@code ||= @net_http_res.code.to_i
			end

			# A hash of the headers, beautified with symbols and underscores.
			# e.g. "Content-type" will become :content_type.
			def headers
				@headers ||= self.class.beautify_headers(@net_http_res.to_hash)
			end

			# Hash of cookies extracted from response headers
			def cookies
				@cookies ||= (self.headers[:set_cookie] || "").split('; ').inject({}) do |out, raw_c|
					key, val = raw_c.split('=')
					unless %w(expires domain path secure).member?(key)
						out[key] = val
					end
					out
				end
			end

			def self.included(receiver)
				receiver.extend(RestClient::Mixin::Response::ClassMethods)
			end

			module ClassMethods
				def beautify_headers(headers)
					headers.inject({}) do |out, (key, value)|
						out[key.gsub(/-/, '_').to_sym] = value.first
					out
					end
				end
			end
		end
	end
end

Version data entries

32 entries across 32 versions & 9 rubygems

Version Path
adamwiggins-rest-client-1.0.1 lib/restclient/mixin/response.rb
adamwiggins-rest-client-1.0.2 lib/restclient/mixin/response.rb
adamwiggins-rest-client-1.0.3 lib/restclient/mixin/response.rb
adamwiggins-rest-client-1.0.4 lib/restclient/mixin/response.rb
auser-poolparty-1.2.10 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-poolparty-1.2.3 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-poolparty-1.2.4 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-poolparty-1.2.7 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-poolparty-1.2.8 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-poolparty-1.2.9 vendor/gems/rest-client/lib/restclient/mixin/response.rb
auser-rest-client-1.0.1 lib/restclient/mixin/response.rb
auser-rest-client-1.0 lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.0 vendor/rest-client/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.1 vendor/rest-client/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.2 vendor/rest-client-1.0.1/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.3 vendor/rest-client-1.0.1/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.4 vendor/rest-client-1.0.1/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.5 vendor/rest-client-1.0.1/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.6 vendor/rest-client-1.0.1/lib/restclient/mixin/response.rb
benschwarz-smoke-0.5.7 vendor/gems/gems/rest-client-1.0.1/lib/restclient/mixin/response.rb