class Runabove

Application Name : demo

Attributes

flavor[R]
image[R]
instance[R]
labs[R]
me[R]
price[R]
project[R]
region[R]
ssh[R]
stackMysql[R]
storage[R]
time[R]
token[R]

Public Class Methods

new(appkey, secret, consumerkey = "") click to toggle source
# File lib/runabove.rb, line 14
def initialize(appkey, secret, consumerkey = "")
  @appkey = appkey
  @secret = secret
  @consumerkey = consumerkey
  @baseurl = "https://api.runabove.com/1.0"
  @server_time = self.timeServer.to_i
  @delta_time = @server_time - Time.now.to_i
  self.loadObjects if self.class.to_s == "Runabove"
end

Public Instance Methods

createConsumerKey() click to toggle source
# File lib/runabove.rb, line 40
def createConsumerKey
  uri = URI.parse("https://api.runabove.com/1.0/auth/credential")
  
  https = Net::HTTP.new(uri.host,uri.port)
  https.use_ssl = true
  req = Net::HTTP::Post.new(uri.path, initheader = {
    'Content-Type' =>'application/json',
    'X-Ra-Application' => @appkey
  })
  toSend = {
    "accessRules" => [
        {'method'=> 'GET', 'path'=> '/*'},
        {'method'=> 'POST', 'path'=> '/*'},
        {'method'=> 'PUT', 'path'=> '/*'},
        {'method'=> 'DELETE', 'path'=> '/*'}
    ]
  }.to_json
  req.body = "#{toSend}"
  req = https.request(req)
  @consumerkey = JSON.parse(req.body)["consumerKey"]
  JSON.parse(req.body)
end
loadObjects() click to toggle source
# File lib/runabove.rb, line 24
def loadObjects
  @me = RunaboveMe.new @appkey, @secret, @consumerkey
  @flavor = RunaboveFlavor.new @appkey, @secret, @consumerkey
  @image = RunaboveImage.new @appkey, @secret, @consumerkey
  @instance = RunaboveInstance.new @appkey, @secret, @consumerkey
  @labs = RunaboveLabs.new @appkey, @secret, @consumerkey
  @price = RunabovePrice.new @appkey, @secret, @consumerkey
  @project = RunaboveProject.new @appkey, @secret, @consumerkey
  @region = RunaboveRegion.new @appkey, @secret, @consumerkey
  @ssh = RunaboveSsh.new @appkey, @secret, @consumerkey
  @storage = RunaboveStorage.new @appkey, @secret, @consumerkey
  @time = RunaboveTime.new @appkey, @secret, @consumerkey
  @token = RunaboveToken.new @appkey, @secret, @consumerkey
  @stackMysql = RunaboveStackMysql.new @appkey, @secret, @consumerkey
end
raw_call(method, path, data = nil) click to toggle source
# File lib/runabove.rb, line 71
def raw_call(method, path, data = nil)
  time = Time.now.to_i + @delta_time
  body = data.nil? ? "" : data.to_json
  
  sign = "$1$" + Digest::SHA1.hexdigest([ 
      @secret, @consumerkey, method.upcase, @baseurl + path, body, time 
    ].join("+"))
 
  uri = URI.parse("#{@baseurl}#{path}")
  https = Net::HTTP.new(uri.host,uri.port)
  https.use_ssl = true
  headers = {
    'X-Ra-Timestamp' => (Time.now.to_i + @delta_time).to_s,
    'X-Ra-Application' => @appkey,
    'X-Ra-Signature' => sign,
    'X-Ra-Consumer' => @consumerkey
  }
  if(method.upcase == "GET") 
    req = Net::HTTP::Get.new(uri.path, initheader = headers)   
  end
  if(method.upcase == "POST") 
    req = Net::HTTP::Post.new(uri.path, initheader = headers)   
  end
  if(method.upcase == "PUT") 
    req = Net::HTTP::Put.new(uri.path, initheader = headers)   
  end
  if(method.upcase == "DELETE") 
    req = Net::HTTP::Delete.new(uri.path, initheader = headers)   
  end
  req.body = body
  JSON.parse(https.request(req).body) rescue https.request(req).body
end
timeServer() click to toggle source
# File lib/runabove.rb, line 63
def timeServer
  uri = URI.parse("https://api.runabove.com/1.0/auth/time")
  http = Net::HTTP.new(uri.host, uri.port)
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  http.get(uri.request_uri).body
end