Module: Fog::Oracle::Core
Instance Method Summary
collapse
Methods included from JsonUtils
#json_decode, #json_encode, #snakecase_hash_keys
Instance Method Details
#core_initialize(options) ⇒ Object
50
51
52
53
54
55
56
57
|
# File 'lib/fog/oracle/core.rb', line 50
def core_initialize(options)
@api_url = options[:oracle_url]
@username = options[:oracle_username]
@password = options[:oracle_password]
@connection_options = options[:connection_options] || {}
@persistent = options[:persistent] || false
@connection = Fog::XML::Connection.new(@api_url, @persistent, @connection_options)
end
|
#escape(str) ⇒ Object
59
60
61
62
63
|
# File 'lib/fog/oracle/core.rb', line 59
def escape(str)
str.gsub(/([^a-zA-Z0-9_.-]+)/) do
'%' + $1.unpack('H2' * $1.bytesize).join('%').upcase
end
end
|
#request(opts) ⇒ Object
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/fog/oracle/core.rb', line 65
def request(opts)
opts[:path] = '/ovm/core/wsapi/rest/' + opts[:path]
hash = Base64.encode64(@username + ":" + @password).delete("\r\n")
opts[:headers] = {
"Accept" => "application/json",
'Authorization' => "Basic #{hash}"
}.merge(opts[:headers] || {})
if opts[:body]
opts[:headers]["Content-Type"] = "application/json"
opts[:body] = json_encode(opts[:body])
end
response = @connection.request(opts)
if response.["Content-Type"] == "application/json"
response.body = json_decode(response.body)
end
response
end
|