Class: OVH::REST

Inherits:
Object
  • Object
show all
Defined in:
lib/ovh/rest.rb

Constant Summary collapse

DEFAULT_API_URL =
"https://api.ovh.com/1.0"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_key, api_secret, consumer_key, api_url = nil) ⇒ REST

Returns a new instance of REST.



37
38
39
40
# File 'lib/ovh/rest.rb', line 37

def initialize(api_key, api_secret, consumer_key, api_url = nil)
  @api_url = api_url || DEFAULT_API_URL
  @api_key, @api_secret, @consumer_key = api_key, api_secret, consumer_key
end

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



14
15
16
# File 'lib/ovh/rest.rb', line 14

def api_url
  @api_url
end

Class Method Details

.build_http_object(host, port) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/ovh/rest.rb', line 27

def build_http_object(host, port)
  if ENV['https_proxy']
    proxy = URI.parse(ENV['https_proxy'])
    Net::HTTP::Proxy(proxy.host, proxy.port).new(host, port)
  else
    Net::HTTP.new(host, port)
  end
end

.generate_consumer_key(api_key, access_rules, api_url = nil) ⇒ Object



17
18
19
20
21
22
23
24
25
# File 'lib/ovh/rest.rb', line 17

def generate_consumer_key(api_key, access_rules, api_url = nil)
  uri = URI.parse("#{api_url || DEFAULT_API_URL}/auth/credential")
  request = Net::HTTP::Post.new(uri.path, initheader = {"X-Ovh-Application" => api_key, "Content-type" => "application/json"})
  request.body = access_rules.to_json
  http = build_http_object(uri.host, uri.port)
  http.use_ssl = true
  response = http.request(request)
  JSON.parse(response.body)
end