class OVH::REST

Constants

DEFAULT_API_URL

Attributes

api_url[RW]

Public Class Methods

build_http_object(host, port) click to toggle source
# 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) click to toggle source
# 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
new(api_key, api_secret, consumer_key, api_url = nil) click to toggle source
# 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

Private Instance Methods

build_headers(method, url, body) click to toggle source
# File lib/ovh/rest.rb, line 79
def build_headers(method, url, body)
  ts = Time.now.to_i.to_s
  sig = compute_signature(method, url, body, ts)

  headers = {
    "X-Ovh-Application" => @api_key,
    "X-Ovh-Consumer" => @consumer_key,
    "X-Ovh-Timestamp" => ts,
    "X-Ovh-Signature" => sig,
    "Content-type" => "application/json"
  }
end
compute_signature(method, url, body, ts) click to toggle source
# File lib/ovh/rest.rb, line 92
def compute_signature(method, url, body, ts)
  "$1$" + Digest::SHA1.hexdigest("#{@api_secret}+#{@consumer_key}+#{method.upcase}+#{url}+#{body}+#{ts}")
end