lib/fastly/client.rb in fastly-1.1.2 vs lib/fastly/client.rb in fastly-1.1.3

- old
+ new

@@ -6,11 +6,11 @@ require 'uri' class Fastly # The UserAgent to communicate with the API class Client #:nodoc: all - begin + begin require 'curb-fu' CURB_FU=true rescue LoadError CURB_FU=false end @@ -48,23 +48,23 @@ # Some methods require full username and password rather than just auth token def fully_authed? !(user.nil? || password.nil?) end - + def set_customer(id) - + end def get(path, params={}) - path += "?"+make_params(params) unless params.empty? + path += "?"+make_params(params) unless params.empty? resp = self.http.get(path, headers) return nil if 404 == resp.status raise Fastly::Error, resp.message unless resp.success? JSON.parse(resp.body) end - + def get_stats(path, params={}) content = get(path, params) raise Fastly::Error, content["message"] unless content["status"] == 'success' content["data"] end @@ -96,23 +96,23 @@ headers.merge( 'Fastly-Explicit-Customer' => customer ) if customer headers.merge( 'Content-Accept' => 'application/json') end def make_params(params) - params.map { |key,val| + params.map { |key,val| next if val.nil? unless val.is_a?(Hash) "#{CGI.escape(key.to_s)}=#{CGI.escape(val.to_s)}" - else + else val.map { |sub_key, sub_val| new_key = "#{key}[#{sub_key}]" "#{CGI.escape(new_key)}=#{CGI.escape(sub_val.to_s)}" - } + } end }.flatten.delete_if { |v| v.nil? }.join("&") end - + # :nodoc: all class Curl attr_accessor :host, :port, :protocol def initialize(host, port=443) @@ -143,11 +143,11 @@ end end end # :nodoc: all -class Net::HTTPResponse +class Net::HTTPResponse def success? return Net::HTTPSuccess === self end def status @@ -156,10 +156,10 @@ end # :nodoc: all -class CurbFu::Response::Base +class CurbFu::Response::Base def get_fields(key) if ( match = @headers.find{|k,v| k.downcase == key.downcase} ) [match.last].flatten else []