Class: RightApiHelper::Session

Inherits:
Base
  • Object
show all
Defined in:
lib/right_api_helper/session.rb

Instance Method Summary collapse

Methods inherited from Base

#api_url, #log_level, #logger

Constructor Details

#initializeSession

Returns a new instance of Session.



21
22
23
# File 'lib/right_api_helper/session.rb', line 21

def initialize
  logger
end

Instance Method Details

#create_client(email, password, account_id, api_url = nil) ⇒ Object

Create a right_api_client session See github.com/rightscale/right_api_client/blob/master/README.md#usage-instructions

Returns: handle to right_api_client gem



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/right_api_helper/session.rb', line 30

def create_client(email, password, , api_url=nil)
  begin
    args = { :email => email, :password => password, :account_id =>  }
    args[:api_url] = api_url if api_url
    @client ||= RightApi::Client.new(args)
    setup_client_logging
    @client
  rescue Exception => e
    args.delete(:password) # don't log password
    puts "ERROR: could not connect to RightScale API.  Params: #{args.inspect}"
    puts e.message
    puts e.backtrace
    raise e
  end
end

#create_client_from_file(filename) ⇒ Object

Create a right_api_client session from YAML file See github.com/rightscale/right_api_client/blob/master/README.md#usage-instructions

Returns: handle to right_api_client gem



51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/right_api_helper/session.rb', line 51

def create_client_from_file(filename)
  begin
    @client ||= RightApi::Client.new(YAML.load_file(File.expand_path(filename, __FILE__)))
    setup_client_logging
    @client
  rescue Exception => e
    puts "ERROR: could not connect to RightScale API.  filename: '#{filename}'"
    puts e.message
    puts e.backtrace
    raise e
  end
end