mpi_client 0.0.7 → 0.0.8
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mpi_client/account_management/request.rb +47 -0
- data/lib/mpi_client/account_management/response.rb +19 -0
- data/lib/mpi_client/account_management.rb +6 -0
- data/lib/mpi_client/base_request.rb +32 -0
- data/lib/mpi_client/verification/request.rb +4 -2
- data/lib/mpi_client.rb +2 -2
- metadata +6 -4
- data/lib/mpi_client/request.rb +0 -70
- data/lib/mpi_client/response.rb +0 -17
@@ -0,0 +1,47 @@
|
|
1
|
+
module MPIClient
|
2
|
+
module AccountManagement
|
3
|
+
class Request < MPIClient::BaseRequest
|
4
|
+
FILTERED_FIELDS = %w(Password PublicCertificate PrivateKey)
|
5
|
+
CLIENT_METHODS = %w(create_account get_account_info update_account delete_account verify)
|
6
|
+
|
7
|
+
def method_missing(method, *args)
|
8
|
+
submit_request(method, *args) if CLIENT_METHODS.include?(method.to_s)
|
9
|
+
end
|
10
|
+
|
11
|
+
private
|
12
|
+
def submit_request(request_type, *args)
|
13
|
+
parse_response(connection.post(prepare_request_data(request_type, *args)))
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare_request_data(request_type, options, transaction_attrs = {})
|
17
|
+
options = options.dup
|
18
|
+
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
19
|
+
xml.REQUEST(:type => request_type) do |xml|
|
20
|
+
xml.Transaction(transaction_attrs) do |xml|
|
21
|
+
options.each do |k,v|
|
22
|
+
xml.send(OptionTranslator.to_server(k), v)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
builder.to_xml
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_response(response_data)
|
31
|
+
doc = Nokogiri::XML(response_data)
|
32
|
+
|
33
|
+
if error = doc.xpath("//Error").first
|
34
|
+
response = {
|
35
|
+
:error_message => error.text,
|
36
|
+
:error_code => error[:code],
|
37
|
+
:errors => ErrorParser.parse(error.text, error[:code]),
|
38
|
+
}
|
39
|
+
else
|
40
|
+
response = Hash[*doc.xpath("//Transaction/*").collect{|a| [OptionTranslator.to_client(a.name.to_sym), a.text] }.flatten]
|
41
|
+
end
|
42
|
+
|
43
|
+
Response.new(response)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module MPIClient
|
2
|
+
module AccountManagement
|
3
|
+
class Response
|
4
|
+
attr_reader :data
|
5
|
+
|
6
|
+
def initialize(data = {})
|
7
|
+
@data = data
|
8
|
+
end
|
9
|
+
|
10
|
+
def success?
|
11
|
+
error_code.nil? && error_message.nil?
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(method)
|
15
|
+
data[method]
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module MPIClient
|
2
|
+
class BaseRequest
|
3
|
+
FILTERED_FIELDS = []
|
4
|
+
attr_reader :connection
|
5
|
+
|
6
|
+
def initialize
|
7
|
+
@connection = Network::Connection.new(MPIClient.server_url)
|
8
|
+
@connection.logger = MPIClient.logger if MPIClient.logger
|
9
|
+
set_logger_filters
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
def set_logger_filters
|
14
|
+
filter = lambda {|data| filter_xml_data(data, FILTERED_FIELDS) }
|
15
|
+
@connection.request_filter = @connection.response_filter = filter
|
16
|
+
end
|
17
|
+
|
18
|
+
def filter_xml_data(request, *filtered_params)
|
19
|
+
filter_data(request, filtered_params) do |data, param|
|
20
|
+
data.gsub!(%r{<(#{param})>(.*?)</#{param}>}, '<\1>[FILTERED]</\1>')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def filter_data(data, *filtered_params)
|
25
|
+
data = data.dup
|
26
|
+
filtered_params.flatten.each do |param|
|
27
|
+
yield(data, param)
|
28
|
+
end
|
29
|
+
data
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module MPIClient
|
2
2
|
module Verification
|
3
|
-
class Request
|
3
|
+
class Request < MPIClient::BaseRequest
|
4
4
|
PARAMS_MAP = {
|
5
5
|
'AccountId' => :account_id,
|
6
6
|
'Amount' => :amount, #in cents
|
@@ -14,11 +14,13 @@ module MPIClient
|
|
14
14
|
}
|
15
15
|
|
16
16
|
REQUEST_TYPE = 'vereq'
|
17
|
+
FILTERED_FIELDS = %w(Password)
|
17
18
|
|
18
19
|
attr_reader :options, :transaction_id
|
19
20
|
|
20
21
|
def initialize(options, transaction_id)
|
21
22
|
@options, @transaction_id = options, transaction_id
|
23
|
+
super()
|
22
24
|
end
|
23
25
|
|
24
26
|
def process
|
@@ -27,7 +29,7 @@ module MPIClient
|
|
27
29
|
|
28
30
|
private
|
29
31
|
def post(xml_request)
|
30
|
-
|
32
|
+
connection.post(xml_request)
|
31
33
|
end
|
32
34
|
|
33
35
|
def build_xml
|
data/lib/mpi_client.rb
CHANGED
@@ -9,8 +9,8 @@ module MPIClient
|
|
9
9
|
self.server_url = 'http://mpi.server.com/'
|
10
10
|
|
11
11
|
autoload :OptionTranslator, 'mpi_client/option_translator'
|
12
|
-
autoload :Request, 'mpi_client/request'
|
13
|
-
autoload :Response, 'mpi_client/response'
|
14
12
|
autoload :ErrorParser, 'mpi_client/error_parser'
|
13
|
+
autoload :BaseRequest, 'mpi_client/base_request'
|
15
14
|
autoload :Verification, 'mpi_client/verification'
|
15
|
+
autoload :AccountManagement, 'mpi_client/account_management'
|
16
16
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpi_client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitry Plashchynski
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-
|
13
|
+
date: 2009-11-03 00:00:00 +02:00
|
14
14
|
default_executable:
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
@@ -53,8 +53,10 @@ extra_rdoc_files: []
|
|
53
53
|
|
54
54
|
files:
|
55
55
|
- lib/mpi_client/option_translator.rb
|
56
|
-
- lib/mpi_client/
|
57
|
-
- lib/mpi_client/
|
56
|
+
- lib/mpi_client/base_request.rb
|
57
|
+
- lib/mpi_client/account_management.rb
|
58
|
+
- lib/mpi_client/account_management/request.rb
|
59
|
+
- lib/mpi_client/account_management/response.rb
|
58
60
|
- lib/mpi_client/error_parser.rb
|
59
61
|
- lib/mpi_client/verification/request.rb
|
60
62
|
- lib/mpi_client/verification/response.rb
|
data/lib/mpi_client/request.rb
DELETED
@@ -1,70 +0,0 @@
|
|
1
|
-
module MPIClient
|
2
|
-
class Request
|
3
|
-
FILTERED_FIELDS = %w(Password PublicCertificate PrivateKey)
|
4
|
-
CLIENT_METHODS = %w(create_account get_account_info update_account delete_account verify)
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@connection = Network::Connection.new(MPIClient.server_url)
|
8
|
-
@connection.logger = MPIClient.logger if MPIClient.logger
|
9
|
-
set_logger_filters
|
10
|
-
end
|
11
|
-
|
12
|
-
def method_missing(method, *args)
|
13
|
-
submit_request(method, *args) if CLIENT_METHODS.include?(method.to_s)
|
14
|
-
end
|
15
|
-
|
16
|
-
private
|
17
|
-
def set_logger_filters
|
18
|
-
filter = lambda {|data| filter_xml_data(data, FILTERED_FIELDS) }
|
19
|
-
@connection.request_filter = @connection.response_filter = filter
|
20
|
-
end
|
21
|
-
|
22
|
-
def filter_xml_data(request, *filtered_params)
|
23
|
-
filter_data(request, filtered_params) do |data, param|
|
24
|
-
data.gsub!(%r{<(#{param})>(.*?)</#{param}>}, '<\1>[FILTERED]</\1>')
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
def filter_data(data, *filtered_params)
|
29
|
-
data = data.dup
|
30
|
-
filtered_params.flatten.each do |param|
|
31
|
-
yield(data, param)
|
32
|
-
end
|
33
|
-
data
|
34
|
-
end
|
35
|
-
|
36
|
-
def submit_request(request_type, *args)
|
37
|
-
parse_response(@connection.post(prepare_request_data(request_type, *args)))
|
38
|
-
end
|
39
|
-
|
40
|
-
def prepare_request_data(request_type, options, transaction_attrs = {})
|
41
|
-
options = options.dup
|
42
|
-
builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml|
|
43
|
-
xml.REQUEST(:type => request_type) do |xml|
|
44
|
-
xml.Transaction(transaction_attrs) do |xml|
|
45
|
-
options.each do |k,v|
|
46
|
-
xml.send(OptionTranslator.to_server(k), v)
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
builder.to_xml
|
52
|
-
end
|
53
|
-
|
54
|
-
def parse_response(response_data)
|
55
|
-
doc = Nokogiri::XML(response_data)
|
56
|
-
|
57
|
-
if error = doc.xpath("//Error").first
|
58
|
-
response = {
|
59
|
-
:error_message => error.text,
|
60
|
-
:error_code => error[:code],
|
61
|
-
:errors => ErrorParser.parse(error.text, error[:code]),
|
62
|
-
}
|
63
|
-
else
|
64
|
-
response = Hash[*doc.xpath("//Transaction/*").collect{|a| [OptionTranslator.to_client(a.name.to_sym), a.text] }.flatten]
|
65
|
-
end
|
66
|
-
|
67
|
-
Response.new(response)
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
data/lib/mpi_client/response.rb
DELETED