Class: RightScaleCLI::Client
- Inherits:
-
Object
- Object
- RightScaleCLI::Client
- Defined in:
- lib/rightscale_cli/client.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
-
#render(data, root_element) ⇒ Object
Returns the value of attribute render.
Instance Method Summary collapse
- #create(resource, params) ⇒ Object
- #destroy(resource, resource_id) ⇒ Object
- #get(resource) ⇒ Object
-
#initialize(options) ⇒ Client
constructor
A new instance of Client.
- #show(resource, resource_id, *args) ⇒ Object
Constructor Details
#initialize(options) ⇒ Client
Returns a new instance of Client.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/rightscale_cli/client.rb', line 27 def initialize() config = RightScaleCLI::Config.new.local config[:account_id] = ['account'] if [:account] config[:email] = ['user'] if [:user] config[:api_version] = ['api'] if [:api] if ['password'] || (!config[:password] && !config[:password_base64]) config[:password] = ask_pass config[:password_base64] = nil # set this to nil so it is not used by precedence end @options = @client = RightApi::Client.new(config) @logger = RightScaleCLI::Logger.new() end |
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
24 25 26 |
# File 'lib/rightscale_cli/client.rb', line 24 def client @client end |
#render(data, root_element) ⇒ Object
Returns the value of attribute render.
25 26 27 |
# File 'lib/rightscale_cli/client.rb', line 25 def render @render end |
Instance Method Details
#create(resource, params) ⇒ Object
65 66 67 68 |
# File 'lib/rightscale_cli/client.rb', line 65 def create(resource, params) resource = @client.send("#{resource}s").create(resource => params) @logger.info("Created #{resource.href}.") end |
#destroy(resource, resource_id) ⇒ Object
70 71 72 73 74 |
# File 'lib/rightscale_cli/client.rb', line 70 def destroy(resource, resource_id) resource = @client.send("#{resource}s").index({ :id => resource_id }) resource.destroy @logger.info("Deleted #{resource.href}.") end |
#get(resource) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/rightscale_cli/client.rb', line 43 def get(resource) result = [] @client.send(resource).index.each { |record| result.push(record.raw) } return result end |
#show(resource, resource_id, *args) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rightscale_cli/client.rb', line 51 def show(resource, resource_id, *args) if args.count > 0 result = [] records = @client.send(resource).index({ :id => resource_id }).show.send(args[0]).index records.each { |record| result.push(record.raw) } @logger.info("Resource count: #{result.count}.") else result = @client.send(resource).index({ :id => resource_id }).show.raw end return result end |