/
client.rb
36 lines (33 loc) · 1.09 KB
/
client.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
require 'rubykassa/configuration'
module Rubykassa
class ConfigurationError < StandardError
ENV_MESSAGE =
'Invalid mode: only :test or :production are allowed'.freeze
HTTP_METHOD_MESSAGE =
'Invalid http method: only :get or :post are allowed'.freeze
HASH_ALGORITHM_MESSAGE = <<-MESSAGE.squish.freeze
Invalid hash algorithm: only
#{Configuration::HASH_ALGORITHMS.map(&:upcase).join ', '} are allowed
MESSAGE
def self.raise_errors_for(configuration)
if !configuration.correct_mode?
raise ConfigurationError, ENV_MESSAGE
end
if !configuration.correct_http_method? ||
!configuration.correct_xml_http_method?
raise ConfigurationError, HTTP_METHOD_MESSAGE
end
if !configuration.correct_hash_algorithm?
raise ConfigurationError, HASH_ALGORITHM_MESSAGE
end
end
end
class Client
cattr_accessor :configuration
def self.configure
self.configuration = Rubykassa::Configuration.new
yield self.configuration
ConfigurationError.raise_errors_for(self.configuration)
end
end
end