lib/fastly/client.rb in fastly-0.98 vs lib/fastly/client.rb in fastly-0.99

- old
+ new

@@ -13,22 +13,23 @@ CURB_FU=true rescue LoadError CURB_FU=false end - attr_accessor :http, :api_key, :user, :password, :cookie + attr_accessor :http, :api_key, :user, :password, :cookie, :customer def initialize(opts) [:api_key, :user, :password].each do |key| self.send("#{key}=", opts[key]) if opts.has_key?(key) end - base = opts[:base_url] || "https://api.fastly.com" - port = opts[:base_port] || 80 - uri = URI.parse(base) - scheme = uri.scheme - host = uri.host - curb = opts.has_key?(:use_curb) ? !!opts[:use_curb] && CURB_FU : CURB_FU + base = opts[:base_url] || "https://api.fastly.com" + customer = opts[:customer] + uri = URI.parse(base) + scheme = uri.scheme + host = uri.host + curb = opts.has_key?(:use_curb) ? !!opts[:use_curb] && CURB_FU : CURB_FU + port = opts.has_key?(:base_port) ? opts[:base_port] : (scheme == "https") ? 443 : 80 self.http = curb ? Fastly::Client::Curl.new(host, port) : Net::HTTP.new(host, port) self.http.use_ssl = (scheme == "https") return self unless fully_authed? # If we're fully authed (i.e username and password ) then we need to log in @@ -47,10 +48,14 @@ # 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? resp = self.http.get(path, headers) return nil if 404 == resp.status @@ -79,11 +84,13 @@ raise Fastly::Error, resp.message unless resp.success? JSON.parse(resp.body) end def headers - (fully_authed? ? { 'Cookie' => cookie } : { 'X-Fastly-Key' => api_key }).merge( 'Content-Accept' => 'application/json') + headers = fully_authed? ? { 'Cookie' => cookie } : { 'X-Fastly-Key' => api_key } + headers.merge( 'Fastly-Explicit-Customer' => customer ) if customer + headers.merge( 'Content-Accept' => 'application/json') end def make_params(params) params.map { |key,val| next if val.nil? @@ -100,10 +107,10 @@ # :nodoc: all class Curl attr_accessor :host, :port, :protocol - def initialize(host, port=80) + def initialize(host, port=443) self.host = host self.port = port self.protocol = 'https' end \ No newline at end of file