Class: IletiMerkezi::Configuration

Inherits:
Module
  • Object
show all
Defined in:
lib/ileti_merkezi/utils/configuration.rb

Overview

Configuration :reek:TooManyInstanceVariables { max_instance_variables: 8 }

Constant Summary collapse

ENDPOINT =
'http://api.iletimerkezi.com/v1'
SENDER =
'APITEST'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

rubocop:disable Lint/MissingSuper



21
22
23
24
25
26
27
28
29
# File 'lib/ileti_merkezi/utils/configuration.rb', line 21

def initialize # rubocop:disable Lint/MissingSuper
  @endpoint          = ENV['IM_ENDPOINT'] || ENDPOINT
  @username          = ENV['IM_USERNAME']
  @password          = ENV['IM_PASSWORD']
  @public_key        = ENV['IM_PUBLIC_KEY']
  @secret_key        = ENV['IM_SECRET_KEY']
  @sender            = ENV['IM_SENDER'] || SENDER
  @request_overrides = {}
end

Instance Attribute Details

#endpointObject

:reek:Attribute



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

def endpoint
  @endpoint
end

#passwordObject

:reek:Attribute



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

def password
  @password
end

#public_keyObject

:reek:Attribute



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

def public_key
  @public_key
end

#request_overridesObject

:reek:Attribute



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

def request_overrides
  @request_overrides
end

#secret_keyObject

:reek:Attribute



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

def secret_key
  @secret_key
end

#senderObject

:reek:Attribute



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

def sender
  @sender
end

#usernameObject

:reek:Attribute



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

def username
  @username
end

Instance Method Details

#auth_methodObject



31
32
33
34
35
36
37
38
39
# File 'lib/ileti_merkezi/utils/configuration.rb', line 31

def auth_method
  if public_key && secret_key
    :auth_token
  elsif username && password
    :auth_basic
  else
    raise CredentialMissingError, 'Credentials missing'
  end
end

#default_configObject

set default config



48
49
50
51
52
53
54
# File 'lib/ileti_merkezi/utils/configuration.rb', line 48

def default_config
  self.username   = ENV['IM_USERNAME']
  self.password   = ENV['IM_PASSWORD']
  self.public_key = ENV['IM_PUBLIC_KEY']
  self.secret_key = ENV['IM_SECRET_KEY']
  true
end

#hmacObject



41
42
43
44
45
# File 'lib/ileti_merkezi/utils/configuration.rb', line 41

def hmac
  OpenSSL::HMAC.hexdigest(
    OpenSSL::Digest.new('sha256'), secret_key.to_s, public_key.to_s
  )
end

#resetObject

config resets



57
58
59
60
61
62
63
# File 'lib/ileti_merkezi/utils/configuration.rb', line 57

def reset
  self.username   = nil
  self.password   = nil
  self.public_key = nil
  self.secret_key = nil
  true
end