Class: Justifi::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/justifi/configuration.rb

Constant Summary collapse

API_BASE_URL =
"https://api.justifi.ai"

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



22
23
24
# File 'lib/justifi/configuration.rb', line 22

def initialize
  @max_attempts = 3
end

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



11
12
13
# File 'lib/justifi/configuration.rb', line 11

def access_token
  @access_token
end

#cacheObject

Returns the value of attribute cache.



14
15
16
# File 'lib/justifi/configuration.rb', line 14

def cache
  @cache
end

#client_idObject

Returns the value of attribute client_id.



9
10
11
# File 'lib/justifi/configuration.rb', line 9

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



10
11
12
# File 'lib/justifi/configuration.rb', line 10

def client_secret
  @client_secret
end

#environmentObject

Returns the value of attribute environment.



12
13
14
# File 'lib/justifi/configuration.rb', line 12

def environment
  @environment
end

#max_attemptsObject

Returns the value of attribute max_attempts.



13
14
15
# File 'lib/justifi/configuration.rb', line 13

def max_attempts
  @max_attempts
end

Class Method Details

.setupObject



16
17
18
19
20
# File 'lib/justifi/configuration.rb', line 16

def self.setup
  new.tap do |instance|
    yield(instance) if block_given?
  end
end

Instance Method Details

#api_urlObject



45
46
47
48
49
50
51
52
# File 'lib/justifi/configuration.rb', line 45

def api_url
  case environment
  when "staging"
    ENV["API_STAGING_BASE_URL"]
  else
    API_BASE_URL
  end
end

#bad_credentials?Boolean

Returns:

  • (Boolean)


35
36
37
38
# File 'lib/justifi/configuration.rb', line 35

def bad_credentials?
  # TODO: improve this
  return true if client_id.nil? || client_secret.nil?
end

#clear_credentialsObject



40
41
42
43
# File 'lib/justifi/configuration.rb', line 40

def clear_credentials
  @client_id = nil
  @client_secret = nil
end

#credentialsObject



26
27
28
29
30
31
32
33
# File 'lib/justifi/configuration.rb', line 26

def credentials
  raise Justifi::BadCredentialsError, "credentials not set" if bad_credentials?

  {
    client_id: client_id,
    client_secret: client_secret
  }
end

#use_productionObject



54
55
56
# File 'lib/justifi/configuration.rb', line 54

def use_production
  @environment = "production"
end

#use_stagingObject



58
59
60
# File 'lib/justifi/configuration.rb', line 58

def use_staging
  @environment = "staging"
end