Class: EY::CLI::API

Inherits:
Object
  • Object
show all
Defined in:
lib/engineyard/cli/api.rb

Constant Summary collapse

USER_AGENT =
"EngineYard/#{EY::VERSION}"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(endpoint, ui, token = nil) ⇒ API

Returns a new instance of API.



12
13
14
15
16
17
18
19
20
21
# File 'lib/engineyard/cli/api.rb', line 12

def initialize(endpoint, ui, token = nil)
  @client = EY::CloudClient.new(endpoint: endpoint, output: ui.out, user_agent: USER_AGENT)
  @ui = ui
  @eyrc = EY::EYRC.load
  token_from('--api-token') { token } ||
    token_from('$ENGINEYARD_API_TOKEN') { ENV['ENGINEYARD_API_TOKEN'] } ||
    token_from(@eyrc.path, false) { @eyrc.api_token } ||
    authenticate ||
    token_not_loaded
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(meth, *args, &block) ⇒ Object (protected)



29
30
31
32
33
34
35
# File 'lib/engineyard/cli/api.rb', line 29

def method_missing(meth, *args, &block)
  if @client.respond_to?(meth)
    with_reauthentication { @client.send(meth, *args, &block) }
  else
    super
  end
end

Instance Attribute Details

#tokenObject (readonly)

Returns the value of attribute token.



10
11
12
# File 'lib/engineyard/cli/api.rb', line 10

def token
  @token
end

Instance Method Details

#respond_to?(*a) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/engineyard/cli/api.rb', line 23

def respond_to?(*a)
  super or @client.respond_to?(*a)
end