Class: EY::Enzyme::API::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ey_enzyme/api/client.rb

Constant Summary collapse

REST_TIMEOUT_SECONDS =
60
TOTAL_TIMEOUT_SECONDS =
600
RETRY_TIMEOUT_SECONDS =
30

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(api_url, instance_id, token, logger) ⇒ Client

Returns a new instance of Client.



15
16
17
18
19
20
# File 'lib/ey_enzyme/api/client.rb', line 15

def initialize(api_url, instance_id, token, logger)
  @api_url     = api_url
  @instance_id = instance_id
  @token       = token
  @logger      = logger
end

Instance Attribute Details

#api_urlObject (readonly)

Returns the value of attribute api_url.



13
14
15
# File 'lib/ey_enzyme/api/client.rb', line 13

def api_url
  @api_url
end

#instance_idObject (readonly)

Returns the value of attribute instance_id.



13
14
15
# File 'lib/ey_enzyme/api/client.rb', line 13

def instance_id
  @instance_id
end

#loggerObject (readonly)

Returns the value of attribute logger.



13
14
15
# File 'lib/ey_enzyme/api/client.rb', line 13

def logger
  @logger
end

#tokenObject (readonly)

Returns the value of attribute token.



13
14
15
# File 'lib/ey_enzyme/api/client.rb', line 13

def token
  @token
end

Instance Method Details

#custom_recipe_urlObject



49
50
51
52
53
# File 'lib/ey_enzyme/api/client.rb', line 49

def custom_recipe_url
  if response = retry_api("custom-recipe")
    response["url"]
  end
end

#dnaObject



45
46
47
# File 'lib/ey_enzyme/api/client.rb', line 45

def dna
  retry_api("dna")
end

#notify_error(type, error) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/ey_enzyme/api/client.rb', line 37

def notify_error(type, error)
  log :exception, "Notifying #{type} error", error
  call_api("error", params_for(type, error))
rescue RestClient::Exception
  log :exception, "Failed to notify of #{type} error", $!
  raise
end

#notify_successObject



33
34
35
# File 'lib/ey_enzyme/api/client.rb', line 33

def notify_success
  retry_api("completed", :status => 'true')
end

#report(message) ⇒ Object



29
30
31
# File 'lib/ey_enzyme/api/client.rb', line 29

def report(message)
  safe_api("report", :message => message)
end

#restObject



22
23
24
25
26
27
# File 'lib/ey_enzyme/api/client.rb', line 22

def rest
  @rest ||= RestClient::Resource.new(
    api_url,
    :timeout => REST_TIMEOUT_SECONDS
  )
end

#upload(type, file) ⇒ Object

upload, as in, upload the log file output of the chef run



56
57
58
59
60
61
62
63
64
# File 'lib/ey_enzyme/api/client.rb', line 56

def upload(type, file)
  retry_api("store_gzip", :type => type, :file => file)
rescue => e
  #blanket rescue feels dangerous, but we're at least logging it
  #we don't have all the information we'd like to include in the exception message here anyway
  #caller (CookbookSet#upload) should check return value and notify failure
  api_error("store_gzip", e)
  false
end