-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthorize.rb
60 lines (47 loc) · 2.58 KB
/
authorize.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
require 'optparse'
require_relative "account_information_access_authorization"
options = {}
command = ARGV[0]
case command
when "account-information-access"
OptionParser.new do |parser|
parser.banner = "Usage: account-information-access [arguments]"
parser.on("-h", "--help", "Show this help message") do ||
puts parser
exit
end
parser.on("-f", "--financial-institution-id FINANCIAL_INSTITUTION_ID", "UUID of the financial institution holding the account to be authorized") do |v|
options[:financial_institution_id] = v
end
parser.on("-l", "--user-login USER_LOGIN", "Financial institutiton user's login") do |v|
options[:user_login] = v
end
parser.on("-p", "--user-password USER_PASSWORD", "Financial institutiton user's password") do |v|
options[:user_password] = v
end
parser.on("-a", "--account-references ACCOUNT_REFERENCE,ACCOUNT_REFERENCE_2,ACCOUNT_REFERENCE_3", "Comma-separated list of reference values for the financial institution accounts to be authorized (not their UUIDs)") do |v|
options[:account_references] = v
end
parser.on("-r", "--account-information-access-request-redirect-link ACCOUNT_INFORMATION_ACCESS_REQUEST_REDIRECT_LINK", "Redirect URI from the created account information access request") do |v|
options[:account_information_access_request_redirect_link] = v
end
options[:host] = "sandbox-authorization.ibanity.com"
parser.on("-o", "--host HOST", "[OPTIONAL] Custom Sandbox Authorization host (default: sandbox-authorization.ibanity.com)") do |v|
options[:host] = v
end
end.parse!
else
abort("Usage: command [arguments]
Available commands are:
account-information-access : authorizes a created account information access request
See 'COMMAND --help' for more information on a specific command.")
end
[:financial_institution_id, :user_login, :user_password, :account_references, :account_information_access_request_redirect_link].each do |argument|
raise OptionParser::MissingArgument.new(argument) if options[argument].nil?
end
account_references =
options[:account_references]
.split(",")
.map{|reference| reference.include?("#") ? reference : "#{reference}#EUR" }
AccountInformationAccessAuthorization.new(financial_institution_id: options[:financial_institution_id], user_login: options[:user_login], user_password: options[:user_password], account_references: account_references, account_information_access_request_redirect_link: options[:account_information_access_request_redirect_link], host: options[:host]).execute
puts "Your authorization has been submitted."