class Fog::IBM::Connection
Public Class Methods
new(user, password)
click to toggle source
Calls superclass method
# File lib/fog/ibm/core.rb, line 19 def initialize(user, password) @user = user @password = password @endpoint = URI.parse('https://www-147.ibm.com/computecloud/enterprise/api/rest/20100331') @base_path = @endpoint.path super("#{@endpoint.scheme}://#{@endpoint.host}:#{@endpoint.port}") end
Public Instance Methods
auth_header()
click to toggle source
# File lib/fog/ibm/core.rb, line 44 def auth_header @auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'') end
form_encode(params)
click to toggle source
# File lib/fog/ibm/core.rb, line 48 def form_encode(params) params.reject {|k, v| v.nil? }.map {|pair| pair.map {|x| URI.escape(x.to_s) }.join('=') }.join('&') end
request(options)
click to toggle source
Calls superclass method
# File lib/fog/ibm/core.rb, line 27 def request(options) options[:path] = @base_path + options[:path] options[:headers] ||= {} options[:headers]['Authorization'] = auth_header options[:headers]['Accept'] = 'application/json' options[:headers]['Accept-Encoding'] = 'gzip' unless options[:body].nil? options[:headers]['Content-Type'] = 'application/x-www-form-urlencoded' options[:body] = form_encode(options[:body]) end response = super(options) unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end