mangopay 3.0.23 → 3.0.25.pre.alpha.pre.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.gitignore +28 -26
- data/.rspec +2 -2
- data/.travis.yml +13 -0
- data/Gemfile +2 -2
- data/LICENSE +20 -20
- data/README.md +126 -123
- data/bin/mangopay +9 -9
- data/lib/generators/mangopay/install_generator.rb +60 -60
- data/lib/generators/templates/mangopay.rb.erb +5 -5
- data/lib/mangopay.rb +225 -158
- data/lib/mangopay/authorization_token.rb +88 -88
- data/lib/mangopay/bank_account.rb +38 -38
- data/lib/mangopay/card.rb +8 -8
- data/lib/mangopay/card_registration.rb +9 -9
- data/lib/mangopay/client.rb +74 -74
- data/lib/mangopay/dispute.rb +130 -130
- data/lib/mangopay/errors.rb +61 -61
- data/lib/mangopay/event.rb +18 -18
- data/lib/mangopay/filter_parameters.rb +46 -0
- data/lib/mangopay/hook.rb +9 -9
- data/lib/mangopay/http_calls.rb +85 -85
- data/lib/mangopay/json.rb +14 -14
- data/lib/mangopay/kyc_document.rb +70 -70
- data/lib/mangopay/legal_user.rb +15 -15
- data/lib/mangopay/mandate.rb +32 -32
- data/lib/mangopay/natural_user.rb +14 -14
- data/lib/mangopay/pay_in.rb +85 -73
- data/lib/mangopay/pay_out.rb +14 -14
- data/lib/mangopay/pre_authorization.rb +13 -13
- data/lib/mangopay/refund.rb +7 -7
- data/lib/mangopay/report.rb +17 -17
- data/lib/mangopay/resource.rb +21 -21
- data/lib/mangopay/temp.rb +74 -74
- data/lib/mangopay/transaction.rb +24 -24
- data/lib/mangopay/transfer.rb +9 -9
- data/lib/mangopay/user.rb +43 -35
- data/lib/mangopay/version.rb +3 -3
- data/lib/mangopay/wallet.rb +17 -17
- data/mangopay.gemspec +31 -30
- data/spec/mangopay/authorization_token_spec.rb +70 -70
- data/spec/mangopay/bank_account_spec.rb +97 -97
- data/spec/mangopay/card_registration_spec.rb +73 -73
- data/spec/mangopay/client_spec.rb +110 -110
- data/spec/mangopay/configuration_spec.rb +95 -18
- data/spec/mangopay/dispute_spec.rb +262 -262
- data/spec/mangopay/event_spec.rb +31 -31
- data/spec/mangopay/fetch_filters_spec.rb +63 -63
- data/spec/mangopay/hook_spec.rb +37 -37
- data/spec/mangopay/idempotency_spec.rb +41 -41
- data/spec/mangopay/kyc_document_spec.rb +103 -103
- data/spec/mangopay/log_requests_filter_spec.rb +25 -0
- data/spec/mangopay/mandate_spec.rb +92 -92
- data/spec/mangopay/payin_bankwire_direct_spec.rb +74 -74
- data/spec/mangopay/payin_card_direct_spec.rb +68 -68
- data/spec/mangopay/payin_card_web_spec.rb +38 -38
- data/spec/mangopay/payin_directdebit_direct_spec.rb +37 -37
- data/spec/mangopay/payin_directdebit_web_spec.rb +38 -38
- data/spec/mangopay/payin_paypal_web_spec.rb +38 -0
- data/spec/mangopay/payin_preauthorized_direct_spec.rb +68 -68
- data/spec/mangopay/payout_bankwire_spec.rb +54 -54
- data/spec/mangopay/preauthorization_spec.rb +42 -42
- data/spec/mangopay/refund_spec.rb +21 -21
- data/spec/mangopay/report_spec.rb +39 -39
- data/spec/mangopay/shared_resources.rb +381 -365
- data/spec/mangopay/temp_paymentcard_spec.rb +31 -31
- data/spec/mangopay/transaction_spec.rb +54 -54
- data/spec/mangopay/transfer_spec.rb +69 -69
- data/spec/mangopay/user_spec.rb +137 -122
- data/spec/mangopay/wallet_spec.rb +80 -80
- data/spec/spec_helper.rb +31 -31
- metadata +11 -5
@@ -1,5 +1,5 @@
|
|
1
|
-
MangoPay.configure do |c|
|
2
|
-
c.preproduction = <%= options[:preproduction] %>
|
3
|
-
c.client_id = '<%= @client_id %>'
|
4
|
-
c.client_passphrase = '<%= @client_passphrase %>'
|
5
|
-
end
|
1
|
+
MangoPay.configure do |c|
|
2
|
+
c.preproduction = <%= options[:preproduction] %>
|
3
|
+
c.client_id = '<%= @client_id %>'
|
4
|
+
c.client_passphrase = '<%= @client_passphrase %>'
|
5
|
+
end
|
data/lib/mangopay.rb
CHANGED
@@ -1,158 +1,225 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'cgi/util'
|
3
|
-
require 'digest/md5'
|
4
|
-
require 'multi_json'
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
autoload :
|
16
|
-
autoload :
|
17
|
-
autoload :
|
18
|
-
autoload :
|
19
|
-
autoload :
|
20
|
-
autoload :
|
21
|
-
autoload :
|
22
|
-
autoload :
|
23
|
-
autoload :
|
24
|
-
autoload :
|
25
|
-
autoload :
|
26
|
-
autoload :
|
27
|
-
autoload :
|
28
|
-
autoload :
|
29
|
-
autoload :
|
30
|
-
autoload :
|
31
|
-
autoload :
|
32
|
-
autoload :
|
33
|
-
autoload :
|
34
|
-
autoload :
|
35
|
-
autoload :
|
36
|
-
autoload :
|
37
|
-
|
38
|
-
|
39
|
-
autoload :
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
end
|
70
|
-
|
71
|
-
def
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
def
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
{
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
1
|
+
require 'net/http'
|
2
|
+
require 'cgi/util'
|
3
|
+
require 'digest/md5'
|
4
|
+
require 'multi_json'
|
5
|
+
require 'benchmark'
|
6
|
+
require 'logger'
|
7
|
+
|
8
|
+
# helpers
|
9
|
+
require 'mangopay/version'
|
10
|
+
require 'mangopay/errors'
|
11
|
+
|
12
|
+
|
13
|
+
module MangoPay
|
14
|
+
|
15
|
+
autoload :HTTPCalls, 'mangopay/http_calls'
|
16
|
+
autoload :Resource, 'mangopay/resource'
|
17
|
+
autoload :Client, 'mangopay/client'
|
18
|
+
autoload :User, 'mangopay/user'
|
19
|
+
autoload :NaturalUser, 'mangopay/natural_user'
|
20
|
+
autoload :LegalUser, 'mangopay/legal_user'
|
21
|
+
autoload :PayIn, 'mangopay/pay_in'
|
22
|
+
autoload :PayOut, 'mangopay/pay_out'
|
23
|
+
autoload :Transfer, 'mangopay/transfer'
|
24
|
+
autoload :Transaction, 'mangopay/transaction'
|
25
|
+
autoload :Wallet, 'mangopay/wallet'
|
26
|
+
autoload :BankAccount, 'mangopay/bank_account'
|
27
|
+
autoload :CardRegistration, 'mangopay/card_registration'
|
28
|
+
autoload :PreAuthorization, 'mangopay/pre_authorization'
|
29
|
+
autoload :Card, 'mangopay/card'
|
30
|
+
autoload :Event, 'mangopay/event'
|
31
|
+
autoload :KycDocument, 'mangopay/kyc_document'
|
32
|
+
autoload :Hook, 'mangopay/hook'
|
33
|
+
autoload :Refund, 'mangopay/refund'
|
34
|
+
autoload :Dispute, 'mangopay/dispute'
|
35
|
+
autoload :Mandate, 'mangopay/mandate'
|
36
|
+
autoload :Report, 'mangopay/report'
|
37
|
+
autoload :JSON, 'mangopay/json'
|
38
|
+
autoload :AuthorizationToken, 'mangopay/authorization_token'
|
39
|
+
autoload :FilterParameters, 'mangopay/filter_parameters'
|
40
|
+
|
41
|
+
# temporary
|
42
|
+
autoload :Temp, 'mangopay/temp'
|
43
|
+
|
44
|
+
class Configuration
|
45
|
+
attr_accessor :preproduction, :root_url,
|
46
|
+
:client_id, :client_passphrase,
|
47
|
+
:temp_dir, :log_file
|
48
|
+
|
49
|
+
def preproduction
|
50
|
+
@preproduction || false
|
51
|
+
end
|
52
|
+
|
53
|
+
def root_url
|
54
|
+
@root_url || (@preproduction == true ? "https://api.sandbox.mangopay.com" : "https://api.mangopay.com")
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class << self
|
59
|
+
def version_code
|
60
|
+
"v2.01"
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_path
|
64
|
+
"/#{version_code}/#{MangoPay.configuration.client_id}"
|
65
|
+
end
|
66
|
+
|
67
|
+
def api_uri(url='')
|
68
|
+
URI(configuration.root_url + url)
|
69
|
+
end
|
70
|
+
|
71
|
+
def configuration=(value)
|
72
|
+
Thread.current[:mangopay_configuration] = value
|
73
|
+
@last_configuration_set = value
|
74
|
+
end
|
75
|
+
|
76
|
+
def configuration
|
77
|
+
config = Thread.current[:mangopay_configuration]
|
78
|
+
|
79
|
+
config ||
|
80
|
+
( @last_configuration_set &&
|
81
|
+
(self.configuration = @last_configuration_set.dup)) ||
|
82
|
+
(self.configuration = MangoPay::Configuration.new)
|
83
|
+
end
|
84
|
+
|
85
|
+
def configure
|
86
|
+
config = self.configuration
|
87
|
+
yield config
|
88
|
+
self.configuration = config
|
89
|
+
end
|
90
|
+
|
91
|
+
def with_configuration(config)
|
92
|
+
original_config = MangoPay.configuration
|
93
|
+
MangoPay.configuration = config
|
94
|
+
yield
|
95
|
+
ensure
|
96
|
+
MangoPay.configuration = original_config
|
97
|
+
end
|
98
|
+
|
99
|
+
#
|
100
|
+
# - +method+: HTTP method; lowercase symbol, e.g. :get, :post etc.
|
101
|
+
# - +url+: the part after Configuration#root_url
|
102
|
+
# - +params+: hash; entity data for creation, update etc.; will dump it by JSON and assign to Net::HTTPRequest#body
|
103
|
+
# - +filters+: hash; pagination params etc.; will encode it by URI and assign to URI#query
|
104
|
+
# - +headers_or_idempotency_key+: hash of headers; or replaced by request_headers if nil; or added to request_headers as idempotency key otherwise (see https://docs.mangopay.com/api-references/idempotency-support/)
|
105
|
+
# - +before_request_proc+: optional proc; will call it passing the Net::HTTPRequest instance just before Net::HTTPRequest#request
|
106
|
+
#
|
107
|
+
# Raises MangoPay::ResponseError if response code != 200.
|
108
|
+
#
|
109
|
+
def request(method, url, params={}, filters={}, headers_or_idempotency_key = nil, before_request_proc = nil)
|
110
|
+
uri = api_uri(url)
|
111
|
+
uri.query = URI.encode_www_form(filters) unless filters.empty?
|
112
|
+
|
113
|
+
if headers_or_idempotency_key.is_a?(Hash)
|
114
|
+
headers = headers_or_idempotency_key
|
115
|
+
else
|
116
|
+
headers = request_headers
|
117
|
+
headers['Idempotency-Key'] = headers_or_idempotency_key if headers_or_idempotency_key != nil
|
118
|
+
end
|
119
|
+
|
120
|
+
res = Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http|
|
121
|
+
req = Net::HTTP::const_get(method.capitalize).new(uri.request_uri, headers)
|
122
|
+
req.body = JSON.dump(params)
|
123
|
+
before_request_proc.call(req) if before_request_proc
|
124
|
+
do_request(http, req, uri)
|
125
|
+
end
|
126
|
+
|
127
|
+
# decode json data
|
128
|
+
data = res.body.to_s.empty? ? {} : JSON.load(res.body.to_s)
|
129
|
+
|
130
|
+
unless res.is_a?(Net::HTTPOK)
|
131
|
+
raise MangoPay::ResponseError.new(uri, res.code, data)
|
132
|
+
end
|
133
|
+
|
134
|
+
# copy pagination info if any
|
135
|
+
['x-number-of-pages', 'x-number-of-items'].each { |k|
|
136
|
+
filters[k.gsub('x-number-of-', 'total_')] = res[k].to_i if res[k]
|
137
|
+
}
|
138
|
+
|
139
|
+
data
|
140
|
+
end
|
141
|
+
|
142
|
+
# Retrieve a previous response by idempotency_key
|
143
|
+
# See https://docs.mangopay.com/api-references/idempotency-support/
|
144
|
+
def fetch_response(idempotency_key)
|
145
|
+
url = "#{api_path}/responses/#{idempotency_key}"
|
146
|
+
request(:get, url)
|
147
|
+
end
|
148
|
+
|
149
|
+
private
|
150
|
+
|
151
|
+
def user_agent
|
152
|
+
{
|
153
|
+
bindings_version: VERSION,
|
154
|
+
lang: 'ruby',
|
155
|
+
lang_version: "#{RUBY_VERSION} p#{RUBY_PATCHLEVEL} (#{RUBY_RELEASE_DATE})",
|
156
|
+
platform: RUBY_PLATFORM,
|
157
|
+
uname: get_uname
|
158
|
+
}
|
159
|
+
end
|
160
|
+
|
161
|
+
def get_uname
|
162
|
+
`uname -a 2>/dev/null`.strip if RUBY_PLATFORM =~ /linux|darwin/i
|
163
|
+
rescue Errno::ENOMEM
|
164
|
+
'uname lookup failed'
|
165
|
+
end
|
166
|
+
|
167
|
+
def request_headers
|
168
|
+
auth_token = AuthorizationToken::Manager.get_token
|
169
|
+
headers = {
|
170
|
+
'user_agent' => "MangoPay V2 RubyBindings/#{VERSION}",
|
171
|
+
'Authorization' => "#{auth_token['token_type']} #{auth_token['access_token']}",
|
172
|
+
'Content-Type' => 'application/json'
|
173
|
+
}
|
174
|
+
begin
|
175
|
+
headers.update('x_mangopay_client_user_agent' => JSON.dump(user_agent))
|
176
|
+
rescue => e
|
177
|
+
headers.update('x_mangopay_client_raw_user_agent' => user_agent.inspect, error: "#{e} (#{e.class})")
|
178
|
+
end
|
179
|
+
end
|
180
|
+
|
181
|
+
def do_request(http, req, uri)
|
182
|
+
if configuration.log_file.nil?
|
183
|
+
do_request_without_log(http, req)
|
184
|
+
else
|
185
|
+
do_request_with_log(http, req, uri)
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
def do_request_with_log(http, req, uri)
|
190
|
+
res, time = nil, nil
|
191
|
+
params = FilterParameters.request(req.body)
|
192
|
+
line = "[#{Time.now.iso8601}] #{req.method.upcase} \"#{uri.to_s}\" #{params}"
|
193
|
+
begin
|
194
|
+
time = Benchmark.realtime { res = do_request_without_log(http, req) }
|
195
|
+
res
|
196
|
+
ensure
|
197
|
+
params = FilterParameters.response(res.body)
|
198
|
+
line = "#{log_severity(res)} #{line}"
|
199
|
+
line += "\n [#{(time * 1000).round(1)}ms] #{res.code} #{params}\n"
|
200
|
+
logger.info { line }
|
201
|
+
end
|
202
|
+
end
|
203
|
+
|
204
|
+
def do_request_without_log(http, req)
|
205
|
+
http.request(req)
|
206
|
+
end
|
207
|
+
|
208
|
+
def log_severity(res)
|
209
|
+
errors = [Net::HTTPClientError, Net::HTTPServerError, Net::HTTPUnknownResponse]
|
210
|
+
errors.any? { |klass| res.is_a?(klass) } ? 'E' : 'I'
|
211
|
+
end
|
212
|
+
|
213
|
+
def logger
|
214
|
+
raise NotImplementedError if configuration.log_file.nil?
|
215
|
+
if @logger.nil?
|
216
|
+
@logger = Logger.new(configuration.log_file)
|
217
|
+
@logger.formatter = proc do |severity, datetime, progname, msg|
|
218
|
+
"#{msg}\n"
|
219
|
+
end
|
220
|
+
end
|
221
|
+
@logger
|
222
|
+
end
|
223
|
+
|
224
|
+
end
|
225
|
+
end
|
@@ -1,88 +1,88 @@
|
|
1
|
-
module MangoPay
|
2
|
-
module AuthorizationToken
|
3
|
-
|
4
|
-
# See http://docs.mangopay.com/api-references/authenticating/
|
5
|
-
class Manager
|
6
|
-
|
7
|
-
class << self
|
8
|
-
def storage
|
9
|
-
@@storage ||= StaticStorage.new
|
10
|
-
end
|
11
|
-
|
12
|
-
def storage= (storage)
|
13
|
-
@@storage = storage
|
14
|
-
end
|
15
|
-
|
16
|
-
def get_token
|
17
|
-
token = storage.get
|
18
|
-
env_key = get_environment_key_for_token
|
19
|
-
if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
|
20
|
-
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
|
21
|
-
cfg = MangoPay.configuration
|
22
|
-
req.basic_auth cfg.client_id, cfg.client_passphrase
|
23
|
-
req.body = 'grant_type=client_credentials'
|
24
|
-
end)
|
25
|
-
token['timestamp'] = Time.now + token['expires_in'].to_i
|
26
|
-
token['environment_key'] = env_key
|
27
|
-
storage.store token
|
28
|
-
end
|
29
|
-
token
|
30
|
-
end
|
31
|
-
|
32
|
-
def get_environment_key_for_token
|
33
|
-
cfg = MangoPay.configuration
|
34
|
-
key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_passphrase}"
|
35
|
-
key = Digest::MD5.hexdigest(key)
|
36
|
-
key
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
class StaticStorage
|
42
|
-
def get
|
43
|
-
@@token ||= nil
|
44
|
-
end
|
45
|
-
|
46
|
-
def store(token)
|
47
|
-
@@token = token
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
class FileStorage
|
52
|
-
require 'yaml'
|
53
|
-
@temp_dir
|
54
|
-
|
55
|
-
def initialize(temp_dir = nil)
|
56
|
-
@temp_dir = temp_dir || MangoPay.configuration.temp_dir
|
57
|
-
if !@temp_dir
|
58
|
-
raise "Path to temporary folder is not defined"
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
def get
|
63
|
-
begin
|
64
|
-
f = File.open(file_path, File::RDONLY)
|
65
|
-
f.flock(File::LOCK_SH)
|
66
|
-
txt = f.read
|
67
|
-
f.close
|
68
|
-
YAML.load(txt) || nil
|
69
|
-
rescue Errno::ENOENT
|
70
|
-
nil
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
def store(token)
|
75
|
-
File.open(file_path, File::RDWR|File::CREAT, 0644) do |f|
|
76
|
-
f.flock(File::LOCK_EX)
|
77
|
-
f.truncate(0)
|
78
|
-
f.rewind
|
79
|
-
f.puts(YAML.dump(token))
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
|
-
def file_path
|
84
|
-
File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp")
|
85
|
-
end
|
86
|
-
end
|
87
|
-
end
|
88
|
-
end
|
1
|
+
module MangoPay
|
2
|
+
module AuthorizationToken
|
3
|
+
|
4
|
+
# See http://docs.mangopay.com/api-references/authenticating/
|
5
|
+
class Manager
|
6
|
+
|
7
|
+
class << self
|
8
|
+
def storage
|
9
|
+
@@storage ||= StaticStorage.new
|
10
|
+
end
|
11
|
+
|
12
|
+
def storage= (storage)
|
13
|
+
@@storage = storage
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_token
|
17
|
+
token = storage.get
|
18
|
+
env_key = get_environment_key_for_token
|
19
|
+
if token.nil? || token['timestamp'].nil? || token['timestamp'] <= Time.now || token['environment_key'] != env_key
|
20
|
+
token = MangoPay.request(:post, "/#{MangoPay.version_code}/oauth/token", {}, {}, {}, Proc.new do |req|
|
21
|
+
cfg = MangoPay.configuration
|
22
|
+
req.basic_auth cfg.client_id, cfg.client_passphrase
|
23
|
+
req.body = 'grant_type=client_credentials'
|
24
|
+
end)
|
25
|
+
token['timestamp'] = Time.now + (token['expires_in'].to_i - 10)
|
26
|
+
token['environment_key'] = env_key
|
27
|
+
storage.store token
|
28
|
+
end
|
29
|
+
token
|
30
|
+
end
|
31
|
+
|
32
|
+
def get_environment_key_for_token
|
33
|
+
cfg = MangoPay.configuration
|
34
|
+
key = "#{cfg.root_url}|#{cfg.client_id}|#{cfg.client_passphrase}"
|
35
|
+
key = Digest::MD5.hexdigest(key)
|
36
|
+
key
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
class StaticStorage
|
42
|
+
def get
|
43
|
+
@@token ||= nil
|
44
|
+
end
|
45
|
+
|
46
|
+
def store(token)
|
47
|
+
@@token = token
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
class FileStorage
|
52
|
+
require 'yaml'
|
53
|
+
@temp_dir
|
54
|
+
|
55
|
+
def initialize(temp_dir = nil)
|
56
|
+
@temp_dir = temp_dir || MangoPay.configuration.temp_dir
|
57
|
+
if !@temp_dir
|
58
|
+
raise "Path to temporary folder is not defined"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def get
|
63
|
+
begin
|
64
|
+
f = File.open(file_path, File::RDONLY)
|
65
|
+
f.flock(File::LOCK_SH)
|
66
|
+
txt = f.read
|
67
|
+
f.close
|
68
|
+
YAML.load(txt) || nil
|
69
|
+
rescue Errno::ENOENT
|
70
|
+
nil
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def store(token)
|
75
|
+
File.open(file_path, File::RDWR|File::CREAT, 0644) do |f|
|
76
|
+
f.flock(File::LOCK_EX)
|
77
|
+
f.truncate(0)
|
78
|
+
f.rewind
|
79
|
+
f.puts(YAML.dump(token))
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
def file_path
|
84
|
+
File.join(@temp_dir, "MangoPay.AuthorizationToken.FileStore.tmp")
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|