Class: EY::Enzyme::API::Client
- Inherits:
-
Object
- Object
- EY::Enzyme::API::Client
- 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
-
#api_url ⇒ Object
readonly
Returns the value of attribute api_url.
-
#instance_id ⇒ Object
readonly
Returns the value of attribute instance_id.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#token ⇒ Object
readonly
Returns the value of attribute token.
Instance Method Summary collapse
- #custom_recipe_url ⇒ Object
- #dna ⇒ Object
-
#initialize(api_url, instance_id, token, logger) ⇒ Client
constructor
A new instance of Client.
- #notify_error(type, error) ⇒ Object
- #notify_success ⇒ Object
- #report(message) ⇒ Object
- #rest ⇒ Object
-
#upload(type, file) ⇒ Object
upload, as in, upload the log file output of the chef run.
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_url ⇒ Object (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_id ⇒ Object (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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
13 14 15 |
# File 'lib/ey_enzyme/api/client.rb', line 13 def logger @logger end |
#token ⇒ Object (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_url ⇒ Object
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 |
#dna ⇒ Object
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_success ⇒ Object
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() safe_api("report", :message => ) end |
#rest ⇒ Object
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 |