Class: Nuncium::Configuration

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

Constant Summary collapse

ALLOWED_PRODUCTION_SYNTAX =
[:production, 'production'].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



9
10
11
12
13
14
15
16
17
# File 'lib/nuncium/configuration.rb', line 9

def initialize
  @username = nil
  @password = nil
  @data_box = nil
  @env = nil
  @cert_file = nil
  @key_file = nil
  @pass_phrase = nil
end

Instance Attribute Details

#api_url=(value) ⇒ Object (writeonly)

Sets the attribute api_url

Parameters:

  • value

    the value to set the attribute api_url to.



3
4
5
# File 'lib/nuncium/configuration.rb', line 3

def api_url=(value)
  @api_url = value
end

#cert_fileObject



34
35
36
37
38
39
40
# File 'lib/nuncium/configuration.rb', line 34

def cert_file
  if @cert_file && (!@key_file && !@pass_phrase)
    raise ConfigNotSet, 'pass_phrase and key_file'
  end
  return unless @cert_file
  OpenSSL::X509::Certificate.new(File.read(@cert_file))
end

#data_boxObject

Raises:



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

def data_box
  raise ConfigNotSet, 'data_box' unless @data_box
  @data_box
end

#envObject

env values:

:development (default)
:production


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

def env
  return :development unless @env
  @env
end

#key_fileObject



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

def key_file
  return nil unless @key_file
  File.read(@key_file)
end

#pass_phraseObject

Returns the value of attribute pass_phrase.



5
6
7
# File 'lib/nuncium/configuration.rb', line 5

def pass_phrase
  @pass_phrase
end

#passwordObject

Raises:



29
30
31
32
# File 'lib/nuncium/configuration.rb', line 29

def password
  raise ConfigNotSet, 'password' unless @password
  @password
end

#usernameObject

Raises:



24
25
26
27
# File 'lib/nuncium/configuration.rb', line 24

def username
  raise ConfigNotSet, 'username' unless @username
  @username
end

Instance Method Details

#api_domainObject



63
64
65
66
67
68
69
70
71
# File 'lib/nuncium/configuration.rb', line 63

def api_domain
  if production?
    return 'https://ws1c.mojedatovaschranka.cz/cert' if @cert_file
    'https://ws1.mojedatovaschranka.cz'
  else
    return 'https://ws1c.czebox.cz/hspis' if @cert_file
    'https://ws1.czebox.cz'
  end
end

#private_keyObject

Raises:



47
48
49
50
51
# File 'lib/nuncium/configuration.rb', line 47

def private_key
  raise ConfigNotSet, 'pass_phrase' if @key_file && !@pass_phrase
  raise ConfigNotSet, 'key_file' if !@key_file && @pass_phrase
  OpenSSL::PKey::RSA.new(File.read(@key_file), @pass_phrase)
end

#production?Boolean

Returns:

  • (Boolean)


78
79
80
# File 'lib/nuncium/configuration.rb', line 78

def production?
  ALLOWED_PRODUCTION_SYNTAX.include?(@env)
end

#xml_urlObject



73
74
75
76
# File 'lib/nuncium/configuration.rb', line 73

def xml_url
  return 'mojedatovaschranka.cz' if production?
  'czechpoint.cz'
end