Class: Iyzi::Request
- Inherits:
-
Object
show all
- Defined in:
- lib/iyzi/request.rb
Constant Summary
collapse
'Authorization'.freeze
- RANDOM_HEADER_NAME =
'x-iyzi-rnd'.freeze
'IYZWS %s:%s'.freeze
- DEFAULT_LOCALE =
'tr'.freeze
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(method, path, options = {}) ⇒ Request
Returns a new instance of Request.
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/iyzi/request.rb', line 13
def initialize(method, path, options = {})
@method = method
@path = path
@config = options.delete(:config) || Iyzi.configuration
@options = options
@options[:locale] = options[:locale] || DEFAULT_LOCALE
@options[:currency] = Currency.find(options[:currency]) if options[:currency].present?
@options.delete_if { |key, value| value.is_a?(String) && value.empty? }
@pki = to_pki
@random_string = secure_random_string
config.validate if has_pki?
end
|
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def config
@config
end
|
#method ⇒ Object
Returns the value of attribute method.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def method
@method
end
|
#options ⇒ Object
Returns the value of attribute options.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def options
@options
end
|
#path ⇒ Object
Returns the value of attribute path.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def path
@path
end
|
#pki ⇒ Object
Returns the value of attribute pki.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def pki
@pki
end
|
#random_string ⇒ Object
Returns the value of attribute random_string.
11
12
13
|
# File 'lib/iyzi/request.rb', line 11
def random_string
@random_string
end
|
Instance Method Details
#call ⇒ Object
47
48
49
50
51
52
53
54
55
|
# File 'lib/iyzi/request.rb', line 47
def call
connection.send(method) do |req|
req.url path
req.['Accept'] = 'application/json'
req.['Content-Type'] = 'application/json'
req..merge!() if has_pki?
req.body = iyzi_options
end
end
|
#connection ⇒ Object
38
39
40
41
42
43
44
45
|
# File 'lib/iyzi/request.rb', line 38
def connection
@conn ||= Faraday.new(url: config.base_url) do |faraday|
faraday.request :json
faraday.response :logger if ENV['DEBUG']
faraday.response :json, content_type: /\bjson$/
faraday.adapter Faraday.default_adapter end
end
|
#has_pki? ⇒ Boolean
85
86
87
|
# File 'lib/iyzi/request.rb', line 85
def has_pki?
!pki.nil? && !pki.to_s.empty?
end
|
#params_will_be_hashed ⇒ Object
77
78
79
|
# File 'lib/iyzi/request.rb', line 77
def params_will_be_hashed
config.api_key + random_string + config.secret + pki
end
|
#request_hash_digest ⇒ Object
73
74
75
|
# File 'lib/iyzi/request.rb', line 73
def request_hash_digest
Digest::SHA1.base64digest(params_will_be_hashed)
end
|
#response ⇒ Object
57
58
59
60
|
# File 'lib/iyzi/request.rb', line 57
def response
@response ||= Utils.properties_to_hash(call.body)
block_given? ? yield(@response) : @response
end
|
#secure_random_string ⇒ Object
81
82
83
|
# File 'lib/iyzi/request.rb', line 81
def secure_random_string
SecureRandom.urlsafe_base64(6, false)
end
|
#to_pki ⇒ Object
90
91
92
|
# File 'lib/iyzi/request.rb', line 90
def to_pki
''
end
|