Class: Stackify::Authorizable::AuthorizationClient

Inherits:
HttpClient show all
Defined in:
lib/stackify/authorization/authorization_client.rb

Constant Summary collapse

BASE_URI =
URI("#{Stackify.configuration.base_api_url}/Metrics/IdentifyApp")

Constants inherited from HttpClient

HttpClient::HEADERS

Instance Attribute Summary

Attributes inherited from HttpClient

#errors, #response

Instance Method Summary collapse

Constructor Details

#initializeAuthorizationClient

Returns a new instance of AuthorizationClient.



6
7
8
9
# File 'lib/stackify/authorization/authorization_client.rb', line 6

def initialize
  super
  @worker = Stackify::AuthWorker.new
end

Instance Method Details

#auth(attempts, delay_time = Stackify::ScheduleDelay.new) ⇒ Object



11
12
13
14
# File 'lib/stackify/authorization/authorization_client.rb', line 11

def auth attempts, delay_time= Stackify::ScheduleDelay.new
  task = auth_task attempts
  @worker.perform delay_time, task
end

#auth_task(attempts) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/stackify/authorization/authorization_client.rb', line 16

def auth_task attempts
  properties = {
    limit: 1,
    attempts: attempts,
    success_condition: lambda do |result|
      result.try(:status) == 200
    end
  }
  Stackify::ScheduleTask.new properties do
    Stackify.internal_log :debug, 'AthorizationClient: trying to authorize...'
    send_request BASE_URI, Stackify::EnvDetails.instance.auth_info.to_json
  end
end