Class: Cdek::Configuration

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

Overview

Конфигурация гема.

Cdek.configure do |config|

config.         = ENV["CDEK_ACCOUNT"]
config.secure_password = ENV["CDEK_SECURE_PASSWORD"]
config.production_mode!

end

Constant Summary collapse

PRODUCTION_URL =
"https://api.cdek.ru/v2"
TEST_URL =
"https://api.edu.cdek.ru/v2"
SANDBOX_ACCOUNT =

Тестовые учётные данные CDEK для песочницы публикуются в их документации. Указываются здесь только как ссылка для удобства, ничего не предзаполняется.

"EMscd6r9JnFiQ3bLoyjJY6eM78JrJceI"
SANDBOX_SECURE_PASSWORD =
"PjLZkKBHEiLK3YsHzqYDqQYj1pSwOaNB"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



28
29
30
31
32
33
34
35
36
# File 'lib/cdek/configuration.rb', line 28

def initialize
  @account         = nil
  @secure_password = nil
  @base_url        = TEST_URL
  @timeout         = 15
  @open_timeout    = 5
  @logger          = nil
  @user_agent      = "cdek-ruby/#{Cdek::VERSION}"
end

Instance Attribute Details

#accountObject

Returns the value of attribute account.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def 
  @account
end

#base_urlObject

Returns the value of attribute base_url.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def base_url
  @base_url
end

#loggerObject

Returns the value of attribute logger.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def logger
  @logger
end

#open_timeoutObject

Returns the value of attribute open_timeout.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def open_timeout
  @open_timeout
end

#secure_passwordObject

Returns the value of attribute secure_password.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def secure_password
  @secure_password
end

#timeoutObject

Returns the value of attribute timeout.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def timeout
  @timeout
end

#user_agentObject

Returns the value of attribute user_agent.



20
21
22
# File 'lib/cdek/configuration.rb', line 20

def user_agent
  @user_agent
end

Instance Method Details

#credentials_present?Boolean

Returns:

  • (Boolean)


52
53
54
# File 'lib/cdek/configuration.rb', line 52

def credentials_present?
  .to_s.strip.length.positive? && secure_password.to_s.strip.length.positive?
end

#production_mode!Object



42
43
44
# File 'lib/cdek/configuration.rb', line 42

def production_mode!
  @base_url = PRODUCTION_URL
end

#test_mode!Object



38
39
40
# File 'lib/cdek/configuration.rb', line 38

def test_mode!
  @base_url = TEST_URL
end

#use_sandbox_credentials!Object



46
47
48
49
50
# File 'lib/cdek/configuration.rb', line 46

def use_sandbox_credentials!
  @account         = SANDBOX_ACCOUNT
  @secure_password = SANDBOX_SECURE_PASSWORD
  test_mode!
end