synapse_pay 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -0
- data/.travis.yml +16 -0
- data/Gemfile +8 -0
- data/LICENSE +21 -0
- data/README.md +54 -0
- data/Rakefile +8 -0
- data/VERSION +1 -0
- data/bin/synapse_pay-console +7 -0
- data/gemfiles/default-with-activesupport.gemfile +10 -0
- data/gemfiles/json.gemfile +12 -0
- data/gemfiles/yajl.gemfile +12 -0
- data/lib/synapse_pay.rb +78 -0
- data/lib/synapse_pay/apibits/api_client.rb +29 -0
- data/lib/synapse_pay/apibits/api_endpoint.rb +9 -0
- data/lib/synapse_pay/apibits/api_list.rb +88 -0
- data/lib/synapse_pay/apibits/api_method.rb +97 -0
- data/lib/synapse_pay/apibits/api_object.rb +52 -0
- data/lib/synapse_pay/apibits/api_resource.rb +127 -0
- data/lib/synapse_pay/apibits/headers_builder.rb +47 -0
- data/lib/synapse_pay/apibits/params_builder.rb +30 -0
- data/lib/synapse_pay/apibits/path_builder.rb +38 -0
- data/lib/synapse_pay/apibits/requester.rb +104 -0
- data/lib/synapse_pay/apibits/util.rb +51 -0
- data/lib/synapse_pay/client.rb +89 -0
- data/lib/synapse_pay/endpoints/bank_endpoint.rb +47 -0
- data/lib/synapse_pay/endpoints/bank_mfa_device_endpoint.rb +5 -0
- data/lib/synapse_pay/endpoints/bank_mfa_questions_endpoint.rb +5 -0
- data/lib/synapse_pay/endpoints/bank_status_endpoint.rb +11 -0
- data/lib/synapse_pay/endpoints/card_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/deposit_endpoint.rb +23 -0
- data/lib/synapse_pay/endpoints/mass_pay_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/order_endpoint.rb +44 -0
- data/lib/synapse_pay/endpoints/user_endpoint.rb +26 -0
- data/lib/synapse_pay/endpoints/wire_endpoint.rb +29 -0
- data/lib/synapse_pay/endpoints/withdrawal_endpoint.rb +17 -0
- data/lib/synapse_pay/errors/api_connection_error.rb +4 -0
- data/lib/synapse_pay/errors/api_error.rb +32 -0
- data/lib/synapse_pay/errors/authentication_error.rb +4 -0
- data/lib/synapse_pay/errors/synapse_pay_error.rb +13 -0
- data/lib/synapse_pay/nested_list.rb +32 -0
- data/lib/synapse_pay/resources/bank.rb +46 -0
- data/lib/synapse_pay/resources/bank_mfa_device.rb +32 -0
- data/lib/synapse_pay/resources/bank_mfa_questions.rb +28 -0
- data/lib/synapse_pay/resources/bank_status.rb +21 -0
- data/lib/synapse_pay/resources/card.rb +32 -0
- data/lib/synapse_pay/resources/deposit.rb +25 -0
- data/lib/synapse_pay/resources/mass_pay.rb +38 -0
- data/lib/synapse_pay/resources/order.rb +63 -0
- data/lib/synapse_pay/resources/user.rb +80 -0
- data/lib/synapse_pay/resources/wire.rb +31 -0
- data/lib/synapse_pay/resources/withdrawal.rb +29 -0
- data/lib/synapse_pay/version.rb +3 -0
- data/synapse_pay.gemspec +29 -0
- data/test/synapse_pay/api_list_test.rb +23 -0
- data/test/synapse_pay/api_method_test.rb +89 -0
- data/test/synapse_pay/headers_builder_test.rb +39 -0
- data/test/synapse_pay/params_builder_test.rb +57 -0
- data/test/synapse_pay/path_builder_test.rb +50 -0
- data/test/synapse_pay/requester_test.rb +86 -0
- data/test/synapse_pay/util_test.rb +51 -0
- data/test/test_data.rb +72 -0
- data/test/test_helper.rb +41 -0
- metadata +220 -0
@@ -0,0 +1,89 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class Client < APIClient
|
3
|
+
attr_reader :oauth_consumer_key,
|
4
|
+
:refresh_token,
|
5
|
+
:expires_in,
|
6
|
+
:username,
|
7
|
+
:user_id,
|
8
|
+
:json
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(oauth_consumer_key=nil, refresh_token=nil)
|
12
|
+
self.refresh_from({
|
13
|
+
:oauth_consumer_key => oauth_consumer_key,
|
14
|
+
:refresh_token => refresh_token
|
15
|
+
})
|
16
|
+
end
|
17
|
+
|
18
|
+
def refresh_from(json)
|
19
|
+
@json = Util.symbolize_keys(json)
|
20
|
+
|
21
|
+
@oauth_consumer_key = @json[:oauth_consumer_key]
|
22
|
+
@refresh_token = @json[:refresh_token]
|
23
|
+
@expires_in = @json[:expires_in]
|
24
|
+
@username = @json[:username]
|
25
|
+
@user_id = @json[:user_id]
|
26
|
+
|
27
|
+
super({}, { :oauth_consumer_key => oauth_consumer_key })
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.login(username, password)
|
31
|
+
method = APIMethod.new(
|
32
|
+
:post,
|
33
|
+
"/user/login",
|
34
|
+
{ :username => username, :password => password }, {}, self)
|
35
|
+
self.new.refresh_from(method.execute)
|
36
|
+
end
|
37
|
+
|
38
|
+
|
39
|
+
def self.refresh_access(refresh_token)
|
40
|
+
c = Client.new(nil, refresh_token)
|
41
|
+
c.refresh_access
|
42
|
+
end
|
43
|
+
|
44
|
+
def refresh_access(refresh_token=nil)
|
45
|
+
method = APIMethod.new(
|
46
|
+
:post,
|
47
|
+
"/user/refresh",
|
48
|
+
{ :refresh_token => refresh_token || @refresh_token }, {}, self)
|
49
|
+
self.refresh_from(method.execute)
|
50
|
+
end
|
51
|
+
|
52
|
+
def user
|
53
|
+
@user ||= UserEndpoint.new(self)
|
54
|
+
end
|
55
|
+
|
56
|
+
def banks
|
57
|
+
@banks ||= BankEndpoint.new(self)
|
58
|
+
end
|
59
|
+
|
60
|
+
def orders
|
61
|
+
@orders ||= OrderEndpoint.new(self)
|
62
|
+
end
|
63
|
+
|
64
|
+
def deposits
|
65
|
+
@deposits ||= DepositEndpoint.new(self)
|
66
|
+
end
|
67
|
+
|
68
|
+
def withdrawals
|
69
|
+
@withdrawals ||= WithdrawalEndpoint.new(self)
|
70
|
+
end
|
71
|
+
|
72
|
+
def cards
|
73
|
+
@cards ||= CardEndpoint.new(self)
|
74
|
+
end
|
75
|
+
|
76
|
+
def mass_pays
|
77
|
+
@mass_pays ||= MassPayEndpoint.new(self)
|
78
|
+
end
|
79
|
+
|
80
|
+
def bank_statuses
|
81
|
+
@bank_statuses ||= BankStatusEndpoint.new(self)
|
82
|
+
end
|
83
|
+
|
84
|
+
def wires
|
85
|
+
@wires ||= WireEndpoint.new(self)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class BankEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def add(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/bank/add", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
Bank.new(json[:bank], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def all(params={}, headers={})
|
11
|
+
method = APIMethod.new(:post, "/bank/show", params, headers, self)
|
12
|
+
json = @client.execute(method)
|
13
|
+
APIList.new(:Bank, json[:banks], method, @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def link(params={}, headers={})
|
17
|
+
method = APIMethod.new(:post, "/bank/login", params, headers, self)
|
18
|
+
json = @client.execute(method)
|
19
|
+
if(json[:is_mfa] && json[:response][:type] == "questions")
|
20
|
+
BankMfaQuestions.new(json[:response], method, @client)
|
21
|
+
elsif(json[:is_mfa] && json[:response][:type] == "device")
|
22
|
+
BankMfaDevice.new(json[:response], method, @client)
|
23
|
+
else
|
24
|
+
APIList.new(:Bank, json[:banks], method, @client)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def remove(bank_id, params={}, headers={})
|
29
|
+
params = ParamsBuilder.merge({
|
30
|
+
:bank_id => bank_id,
|
31
|
+
}, params)
|
32
|
+
method = APIMethod.new(:post, "/bank/delete", params, headers, self)
|
33
|
+
json = @client.execute(method)
|
34
|
+
json
|
35
|
+
end
|
36
|
+
|
37
|
+
def retrieve(id, params={}, headers={})
|
38
|
+
params = ParamsBuilder.merge({
|
39
|
+
:id => id,
|
40
|
+
}, params)
|
41
|
+
method = APIMethod.new(:post, "/bank/refresh", params, headers, self)
|
42
|
+
json = @client.execute(method)
|
43
|
+
APIList.new(:Bank, json[:banks], method, @client)
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class BankStatusEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/bankstatus/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:BankStatus, json[:banks], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class CardEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/card/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:Card, json[:cards], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(params={}, headers={})
|
11
|
+
method = APIMethod.new(:post, "/card/add", params, headers, self)
|
12
|
+
json = @client.execute(method)
|
13
|
+
Card.new(json[:card], method, @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def update(id, params={}, headers={})
|
17
|
+
params = ParamsBuilder.merge({
|
18
|
+
:id => id,
|
19
|
+
}, params)
|
20
|
+
method = APIMethod.new(:post, "/card/edit", params, headers, self)
|
21
|
+
json = @client.execute(method)
|
22
|
+
Card.new(json[:card], method, @client)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class DepositEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/deposit/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:Deposit, json[:deposits], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(params={}, headers={})
|
11
|
+
method = APIMethod.new(:post, "/deposit/add", params, headers, self)
|
12
|
+
json = @client.execute(method)
|
13
|
+
Deposit.new(json[:deposit], method, @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def micro(params={}, headers={})
|
17
|
+
method = APIMethod.new(:post, "/deposit/micro", params, headers, self)
|
18
|
+
json = @client.execute(method)
|
19
|
+
APIList.new(:Deposit, json[:deposits], method, @client)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class MassPayEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/masspay/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:MassPay, json[:mass_pays], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def cancel(id, params={}, headers={})
|
11
|
+
params = ParamsBuilder.merge({
|
12
|
+
:id => id,
|
13
|
+
}, params)
|
14
|
+
method = APIMethod.new(:post, "/masspay/cancel", params, headers, self)
|
15
|
+
json = @client.execute(method)
|
16
|
+
APIList.new(:MassPay, json[:mass_pays], method, @client)
|
17
|
+
end
|
18
|
+
|
19
|
+
def create(params={}, headers={})
|
20
|
+
method = APIMethod.new(:post, "/masspay/add", params, headers, self)
|
21
|
+
json = @client.execute(method)
|
22
|
+
APIList.new(:MassPay, json[:mass_pays], method, @client)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class OrderEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def create(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/order/add", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
Order.new(json[:order], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def poll(order_id, params={}, headers={})
|
11
|
+
params = ParamsBuilder.merge({
|
12
|
+
:order_id => order_id,
|
13
|
+
}, params)
|
14
|
+
method = APIMethod.new(:post, "/order/poll", params, headers, self)
|
15
|
+
json = @client.execute(method)
|
16
|
+
Order.new(json[:order], method, @client)
|
17
|
+
end
|
18
|
+
|
19
|
+
def recent(params={}, headers={})
|
20
|
+
method = APIMethod.new(:post, "/order/recent", params, headers, self)
|
21
|
+
json = @client.execute(method)
|
22
|
+
APIList.new(:Order, json[:orders], method, @client)
|
23
|
+
end
|
24
|
+
|
25
|
+
def update(order_id, params={}, headers={})
|
26
|
+
params = ParamsBuilder.merge({
|
27
|
+
:order_id => order_id,
|
28
|
+
}, params)
|
29
|
+
method = APIMethod.new(:post, "/order/update", params, headers, self)
|
30
|
+
json = @client.execute(method)
|
31
|
+
Order.new(json[:order], method, @client)
|
32
|
+
end
|
33
|
+
|
34
|
+
def void(order_id, params={}, headers={})
|
35
|
+
params = ParamsBuilder.merge({
|
36
|
+
:order_id => order_id,
|
37
|
+
}, params)
|
38
|
+
method = APIMethod.new(:post, "/order/void", params, headers, self)
|
39
|
+
json = @client.execute(method)
|
40
|
+
Order.new(json[:order], method, @client)
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class UserEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def retrieve(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/user/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
User.new(json[:user], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def search(query, params={}, headers={})
|
11
|
+
params = ParamsBuilder.merge({
|
12
|
+
:query => query,
|
13
|
+
}, params)
|
14
|
+
method = APIMethod.new(:post, "/user/customers", params, headers, self)
|
15
|
+
json = @client.execute(method)
|
16
|
+
APIList.new(:User, json[:customers], method, @client)
|
17
|
+
end
|
18
|
+
|
19
|
+
def update(params={}, headers={})
|
20
|
+
method = APIMethod.new(:post, "/user/edit", params, headers, self)
|
21
|
+
json = @client.execute(method)
|
22
|
+
User.new(json[:user], method, @client)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class WireEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all_incoming(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/wirein/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:Wire, json[:wires], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def all_outgoing(params={}, headers={})
|
11
|
+
method = APIMethod.new(:post, "/wireout/show", params, headers, self)
|
12
|
+
json = @client.execute(method)
|
13
|
+
APIList.new(:Wire, json[:wires], method, @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
def create_incoming(params={}, headers={})
|
17
|
+
method = APIMethod.new(:post, "/wirein/add", params, headers, self)
|
18
|
+
json = @client.execute(method)
|
19
|
+
Wire.new(json[:wire], method, @client)
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_outgoing(params={}, headers={})
|
23
|
+
method = APIMethod.new(:post, "/wireout/add", params, headers, self)
|
24
|
+
json = @client.execute(method)
|
25
|
+
Wire.new(json[:wire], method, @client)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class WithdrawalEndpoint < APIEndpoint
|
3
|
+
|
4
|
+
def all(params={}, headers={})
|
5
|
+
method = APIMethod.new(:post, "/withdraw/show", params, headers, self)
|
6
|
+
json = @client.execute(method)
|
7
|
+
APIList.new(:Withdrawal, json[:withdraws], method, @client)
|
8
|
+
end
|
9
|
+
|
10
|
+
def create(params={}, headers={})
|
11
|
+
method = APIMethod.new(:post, "/withdraw/add", params, headers, self)
|
12
|
+
json = @client.execute(method)
|
13
|
+
Withdrawal.new(json[:withdrawal], method, @client)
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class APIError < SynapsePayError
|
3
|
+
attr_reader :api_method
|
4
|
+
|
5
|
+
def initialize(message=nil, api_method=nil)
|
6
|
+
@message = message
|
7
|
+
@api_method = api_method
|
8
|
+
end
|
9
|
+
|
10
|
+
def code
|
11
|
+
@api_method.response_code if @api_method
|
12
|
+
end
|
13
|
+
|
14
|
+
def body
|
15
|
+
@api_method.response_body if @api_method
|
16
|
+
end
|
17
|
+
|
18
|
+
def json
|
19
|
+
begin
|
20
|
+
@api_method.response_json if @api_method
|
21
|
+
rescue APIError
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
prefix = code.nil? ? "" : "(Status #{code}) "
|
28
|
+
"#{prefix}#{@message}"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
module SynapsePay
|
2
|
+
class RunTestList < APIList
|
3
|
+
attr_accessor :parent_id
|
4
|
+
|
5
|
+
def initialize(json={}, api_method=nil, parent_id=nil)
|
6
|
+
refresh_from(json, api_method, parent_id)
|
7
|
+
end
|
8
|
+
|
9
|
+
def refresh_from(json={}, api_method=nil, parent_id=nil)
|
10
|
+
@klass = Util.constantize(:Test)
|
11
|
+
@parent_id = parent_id || @parent_id
|
12
|
+
super(json, api_method)
|
13
|
+
end
|
14
|
+
|
15
|
+
def all(params={}, headers={})
|
16
|
+
method = APIMethod.new(:get, "/runs/:parent_id/tests", params, headers, self)
|
17
|
+
self.refresh_from(method.execute, method, parent_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
def retrieve(id, params={}, headers={})
|
21
|
+
params = ParamsBuilder.merge(params, {
|
22
|
+
:id => id,
|
23
|
+
})
|
24
|
+
method = APIMethod.new(:get, "/runs/:parent_id/tests/:id", params, headers, self)
|
25
|
+
Util.constantize(:Test).new(method.execute, method)
|
26
|
+
end
|
27
|
+
|
28
|
+
@api_attributes = {
|
29
|
+
:data => { :readonly => true }
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|