Module: Skytapify::SkytapApi

Included in:
ActsAsSkytapConfig, ActsAsSkytapUser
Defined in:
lib/skytapify/skytap_api.rb

Instance Method Summary collapse

Instance Method Details

#api_call(organization, action, global_options = [], command_options = {}, &invoker) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/skytapify/skytap_api.rb', line 6

def api_call(organization, action, global_options = [], command_options = {}, &invoker)
  if ['test', 'development'].include? Rails.env
    env_options = {:param => global_options, :'log-level' => 'verbose', :'base-url' => 'https://test.skytap.com', :'verify-certs' => false}
  else
    env_options = {:param => global_options, :'log-level' => 'verbose'}
  end

  # currently the gem has the global and command options switched,
  # so we make our call here make sense, and send what the gem needs, swapping the
  # global and command hashes.  The gem needs fixed to have them named the right thing
  response = begin
    Skytap::invoke(
      organization., 
      organization.skytap_api_key, 
      action,
      command_options,
      env_options,
      &invoker
    )
  rescue SystemExit => e # I just threw up in my mouth a little
  end

  # TODO: jong to add error handling to these calls
  if response.payload.is_a?(Hash) && response.payload['errors']
    raise response.payload['errors'].join(', ')  
  else
    response.payload
  end
end