Class: Fog::IBM::Connection
- Inherits:
-
Connection
- Object
- Core::Connection
- XML::SAXParserConnection
- Connection
- Fog::IBM::Connection
- Defined in:
- lib/fog/ibm/core.rb
Instance Method Summary collapse
- #auth_header ⇒ Object
- #form_encode(params) ⇒ Object
-
#initialize(user, password) ⇒ Connection
constructor
A new instance of Connection.
- #request(options) ⇒ Object
Methods inherited from Core::Connection
Constructor Details
#initialize(user, password) ⇒ Connection
Returns a new instance of Connection.
20 21 22 23 24 25 26 |
# File 'lib/fog/ibm/core.rb', line 20 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 |
Instance Method Details
#auth_header ⇒ Object
45 46 47 |
# File 'lib/fog/ibm/core.rb', line 45 def auth_header @auth_header ||= 'Basic ' + Base64.encode64("#{@user}:#{@password}").gsub("\n",'') end |
#form_encode(params) ⇒ Object
49 50 51 |
# File 'lib/fog/ibm/core.rb', line 49 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) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/fog/ibm/core.rb', line 28 def request() [:path] = @base_path + [:path] [:headers] ||= {} [:headers]['Authorization'] = auth_header [:headers]['Accept'] = 'application/json' [:headers]['Accept-Encoding'] = 'gzip' unless [:body].nil? [:headers]['Content-Type'] = 'application/x-www-form-urlencoded' [:body] = form_encode([:body]) end response = super() unless response.body.empty? response.body = Fog::JSON.decode(response.body) end response end |