Class: Superset::Client

Inherits:
Happi::Client
  • Object
show all
Includes:
Superset::Credential::ApiUser
Defined in:
lib/superset/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Superset::Credential::ApiUser

#credentials

Constructor Details

#initializeClient

Returns a new instance of Client.



7
8
9
10
# File 'lib/superset/client.rb', line 7

def initialize
  @authenticator = Superset::Authenticator.new(credentials)
  super(log_level: :debug, host: superset_host)
end

Instance Attribute Details

#authenticatorObject (readonly)

Returns the value of attribute authenticator.



5
6
7
# File 'lib/superset/client.rb', line 5

def authenticator
  @authenticator
end

Instance Method Details

#access_tokenObject



12
13
14
# File 'lib/superset/client.rb', line 12

def access_token
  @access_token ||= authenticator.access_token
end

#put(resource, params = {}) ⇒ Object

TODO: Happi has not got a put method yet



21
22
23
24
# File 'lib/superset/client.rb', line 21

def put(resource, params = {})
  call(:put, url(resource), param_check(params))
    .body.with_indifferent_access
end

#raise_error(response) ⇒ Object

TODO: Happi is not surfacing the errors correctly overriding raise_error for now

Raises:

  • (errors[response.status])


27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/superset/client.rb', line 27

def raise_error(response)
  message =
  if response.body['errors']
    response.body['errors']
  else
    response.body
  end

  puts "API Error: #{message}"  # display the error message for console debugging
  # binding.pry                 # helpfull to debug the response

  raise errors[response.status].new(message, response)  # message is not being surfaced from Happi correctly, :(
end

#superset_hostObject



16
17
18
# File 'lib/superset/client.rb', line 16

def superset_host
  @superset_host ||= authenticator.superset_host
end