Class: Envirobly::Api

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

Constant Summary collapse

HOST =
ENV["ENVIROBLY_API_HOST"] || "envirobly.com"
USER_AGENT =
"Envirobly CLI v#{Envirobly::VERSION}"
CONTENT_TYPE =
"application/json"
RETRY_INTERVAL_SECONDS =
3
MAX_RETRIES =
5

Instance Method Summary collapse

Constructor Details

#initializeApi

Returns a new instance of Api.



11
12
13
# File 'lib/envirobly/api.rb', line 11

def initialize
  @access_token = Envirobly::AccessToken.new
end

Instance Method Details

#create_deployment(params) ⇒ Object



15
16
17
18
19
20
21
22
# File 'lib/envirobly/api.rb', line 15

def create_deployment(params)
  post_as_json(api_v1_deployments_url, params:, headers: authorization_headers).tap do |response|
    unless response.code.to_i == 200
      $stderr.puts "Deployment creation request responded with #{response.code}. Aborting."
      exit 1
    end
  end
end

#get_deployment_with_delay_and_retry(url, tries = 1) ⇒ Object



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

def get_deployment_with_delay_and_retry(url, tries = 1)
  sleep RETRY_INTERVAL_SECONDS * tries
  response = get_as_json URI(url)

  if response.code.to_i == 200
    return response
  elsif MAX_RETRIES <= tries
    $stderr.puts "Max retries exhausted while waiting for deployment credentials. Aborting."
    exit 1
  else
    sleep RETRY_INTERVAL_SECONDS * tries
    get_deployment_with_delay_and_retry(url, tries + 1)
  end
end