mangopay 3.0.0 → 3.0.1

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.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +26 -24
  3. data/.rspec +2 -2
  4. data/Gemfile +2 -2
  5. data/LICENSE +20 -20
  6. data/README.md +67 -67
  7. data/bin/mangopay +9 -9
  8. data/lib/generators/mangopay/install_generator.rb +60 -60
  9. data/lib/generators/templates/mangopay.rb +5 -5
  10. data/lib/mangopay.rb +118 -115
  11. data/lib/mangopay/bank_account.rb +21 -21
  12. data/lib/mangopay/card.rb +5 -0
  13. data/lib/mangopay/card_registration.rb +7 -0
  14. data/lib/mangopay/client.rb +17 -17
  15. data/lib/mangopay/errors.rb +4 -4
  16. data/lib/mangopay/http_calls.rb +53 -53
  17. data/lib/mangopay/json.rb +21 -21
  18. data/lib/mangopay/legal_user.rb +14 -14
  19. data/lib/mangopay/natural_user.rb +14 -14
  20. data/lib/mangopay/payin.rb +27 -17
  21. data/lib/mangopay/payout.rb +15 -15
  22. data/lib/mangopay/resource.rb +22 -22
  23. data/lib/mangopay/transaction.rb +11 -11
  24. data/lib/mangopay/transfer.rb +7 -7
  25. data/lib/mangopay/user.rb +7 -7
  26. data/lib/mangopay/version.rb +3 -3
  27. data/lib/mangopay/wallet.rb +7 -7
  28. data/mangopay.gemspec +33 -33
  29. data/spec/lib/mangopay/bank_account_spec.rb +26 -26
  30. data/spec/lib/mangopay/card_registration_spec.rb +40 -0
  31. data/spec/lib/mangopay/card_spec.rb +35 -0
  32. data/spec/lib/mangopay/client_spec.rb +28 -27
  33. data/spec/lib/mangopay/payin_spec.rb +34 -31
  34. data/spec/lib/mangopay/payout_spec.rb +34 -24
  35. data/spec/lib/mangopay/shared_resources.rb +193 -183
  36. data/spec/lib/mangopay/transaction_spec.rb +14 -14
  37. data/spec/lib/mangopay/transfer_spec.rb +35 -32
  38. data/spec/lib/mangopay/user_spec.rb +58 -58
  39. data/spec/lib/mangopay/wallet_spec.rb +32 -32
  40. data/spec/spec_helper.rb +13 -13
  41. metadata +8 -2
@@ -1,21 +1,21 @@
1
- module MangoPay
2
- class BankAccount < Resource
3
- include MangoPay::HTTPCalls::Create
4
- include MangoPay::HTTPCalls::Fetch
5
-
6
- def self.fetch(*ids)
7
- url = ids.length == 1 ? url(ids[0]) : url(ids[0], ids[1])
8
- MangoPay.request(:get, url)
9
- end
10
-
11
- private
12
-
13
- def self.url(*id)
14
- if id.length == 1
15
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts"
16
- else
17
- "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts/#{CGI.escape(id[1])}"
18
- end
19
- end
20
- end
21
- end
1
+ module MangoPay
2
+ class BankAccount < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Fetch
5
+
6
+ def self.fetch(*ids)
7
+ url = ids.length == 1 ? url(ids[0]) : url(ids[0], ids[1])
8
+ MangoPay.request(:get, url)
9
+ end
10
+
11
+ private
12
+
13
+ def self.url(*id)
14
+ if id.length == 1
15
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts"
16
+ else
17
+ "/v2/#{MangoPay.configuration.client_id}/users/#{CGI.escape(id[0])}/bankaccounts/#{CGI.escape(id[1])}"
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,5 @@
1
+ module MangoPay
2
+ class Card < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module MangoPay
2
+ class CardRegistration < Resource
3
+ include MangoPay::HTTPCalls::Create
4
+ include MangoPay::HTTPCalls::Update
5
+ include MangoPay::HTTPCalls::Fetch
6
+ end
7
+ end
@@ -1,17 +1,17 @@
1
- module MangoPay
2
- class Client < Resource
3
-
4
- def self.create(params)
5
- uri = URI(MangoPay.configuration.root_url + '/api/clients/')
6
- res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
7
- request = Net::HTTP::Post.new(uri.request_uri, {
8
- 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
9
- 'Content-Type' => 'application/json'
10
- })
11
- request.body = MangoPay::JSON.dump(params)
12
- http.request request
13
- end
14
- MangoPay::JSON.load(res.body)
15
- end
16
- end
17
- end
1
+ module MangoPay
2
+ class Client < Resource
3
+
4
+ def self.create(params)
5
+ uri = URI(MangoPay.configuration.root_url + '/api/clients/')
6
+ res = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
7
+ request = Net::HTTP::Post.new(uri.request_uri, {
8
+ 'user_agent' => "MangoPay V1 RubyBindings/#{MangoPay::VERSION}",
9
+ 'Content-Type' => 'application/json'
10
+ })
11
+ request.body = MangoPay::JSON.dump(params)
12
+ http.request request
13
+ end
14
+ MangoPay::JSON.load(res.body)
15
+ end
16
+ end
17
+ end
@@ -1,4 +1,4 @@
1
- module MangoPay
2
- class Errors
3
- end
4
- end
1
+ module MangoPay
2
+ class Errors
3
+ end
4
+ end
@@ -1,53 +1,53 @@
1
- module MangoPay
2
- module HTTPCalls
3
- module Create
4
- module ClassMethods
5
-
6
- def create(*id, params)
7
- id = id.empty? ? nil : id[0]
8
- response = MangoPay.request(:post, url(id), params)
9
- end
10
- end
11
-
12
- def self.included(base)
13
- base.extend(ClassMethods)
14
- end
15
- end
16
-
17
- module Update
18
- module ClassMethods
19
- def update(id = nil, params = {})
20
- response = MangoPay.request(:put, url(id), params)
21
- end
22
- end
23
-
24
- def self.included(base)
25
- base.extend(ClassMethods)
26
- end
27
- end
28
-
29
- module Fetch
30
- module ClassMethods
31
- def fetch(id = nil, filters = {})
32
- response = MangoPay.request(:get, url(id), filters)
33
- end
34
- end
35
-
36
- def self.included(base)
37
- base.extend(ClassMethods)
38
- end
39
- end
40
-
41
- module Refund
42
- module ClassMethods
43
- def refund(id = nil, params = {})
44
- MangoPay.request(:post, url(id) + '/refunds', params)
45
- end
46
- end
47
-
48
- def self.included(base)
49
- base.extend(ClassMethods)
50
- end
51
- end
52
- end
53
- end
1
+ module MangoPay
2
+ module HTTPCalls
3
+ module Create
4
+ module ClassMethods
5
+
6
+ def create(*id, params)
7
+ id = id.empty? ? nil : id[0]
8
+ response = MangoPay.request(:post, url(id), params)
9
+ end
10
+ end
11
+
12
+ def self.included(base)
13
+ base.extend(ClassMethods)
14
+ end
15
+ end
16
+
17
+ module Update
18
+ module ClassMethods
19
+ def update(id = nil, params = {})
20
+ response = MangoPay.request(:put, url(id), params)
21
+ end
22
+ end
23
+
24
+ def self.included(base)
25
+ base.extend(ClassMethods)
26
+ end
27
+ end
28
+
29
+ module Fetch
30
+ module ClassMethods
31
+ def fetch(id = nil, filters = {})
32
+ response = MangoPay.request(:get, url(id), filters)
33
+ end
34
+ end
35
+
36
+ def self.included(base)
37
+ base.extend(ClassMethods)
38
+ end
39
+ end
40
+
41
+ module Refund
42
+ module ClassMethods
43
+ def refund(id = nil, params = {})
44
+ MangoPay.request(:post, url(id) + '/refunds', params)
45
+ end
46
+ end
47
+
48
+ def self.included(base)
49
+ base.extend(ClassMethods)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -1,21 +1,21 @@
1
- module MangoPay
2
- module JSON
3
- if MultiJson.respond_to?(:dump)
4
- def self.dump(*args)
5
- MultiJson.dump(*args)
6
- end
7
-
8
- def self.load(*args)
9
- MultiJson.load(*args)
10
- end
11
- else
12
- def self.dump(*args)
13
- MultiJson.encode(*args)
14
- end
15
-
16
- def self.load(*args)
17
- MultiJson.decode(*args)
18
- end
19
- end
20
- end
21
- end
1
+ module MangoPay
2
+ module JSON
3
+ if MultiJson.respond_to?(:dump)
4
+ def self.dump(*args)
5
+ MultiJson.dump(*args)
6
+ end
7
+
8
+ def self.load(*args)
9
+ MultiJson.load(*args)
10
+ end
11
+ else
12
+ def self.dump(*args)
13
+ MultiJson.encode(*args)
14
+ end
15
+
16
+ def self.load(*args)
17
+ MultiJson.decode(*args)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -1,14 +1,14 @@
1
- module MangoPay
2
- class LegalUser < User
3
-
4
- private
5
-
6
- def self.url(id = nil)
7
- if id
8
- "/v2/#{MangoPay.configuration.client_id}/users/legal/#{CGI.escape(id)}"
9
- else
10
- "/v2/#{MangoPay.configuration.client_id}/users/legal"
11
- end
12
- end
13
- end
14
- end
1
+ module MangoPay
2
+ class LegalUser < User
3
+
4
+ private
5
+
6
+ def self.url(id = nil)
7
+ if id
8
+ "/v2/#{MangoPay.configuration.client_id}/users/legal/#{CGI.escape(id)}"
9
+ else
10
+ "/v2/#{MangoPay.configuration.client_id}/users/legal"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,14 +1,14 @@
1
- module MangoPay
2
- class NaturalUser < User
3
-
4
- private
5
-
6
- def self.url(id = nil)
7
- if id
8
- "/v2/#{MangoPay.configuration.client_id}/users/natural/#{CGI.escape(id)}"
9
- else
10
- "/v2/#{MangoPay.configuration.client_id}/users/natural"
11
- end
12
- end
13
- end
14
- end
1
+ module MangoPay
2
+ class NaturalUser < User
3
+
4
+ private
5
+
6
+ def self.url(id = nil)
7
+ if id
8
+ "/v2/#{MangoPay.configuration.client_id}/users/natural/#{CGI.escape(id)}"
9
+ else
10
+ "/v2/#{MangoPay.configuration.client_id}/users/natural"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -1,17 +1,27 @@
1
- module MangoPay
2
- class PayIn < Resource
3
- include MangoPay::HTTPCalls::Fetch
4
- include MangoPay::HTTPCalls::Refund
5
- module Card
6
- class Web < Resource
7
- include MangoPay::HTTPCalls::Create
8
-
9
- private
10
-
11
- def self.url(id = nil)
12
- "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
13
- end
14
- end
15
- end
16
- end
17
- end
1
+ module MangoPay
2
+ class PayIn < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+ include MangoPay::HTTPCalls::Refund
5
+
6
+ module Card
7
+
8
+ class Web < Resource
9
+ include MangoPay::HTTPCalls::Create
10
+ private
11
+ def self.url(id = nil)
12
+ "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
13
+ end
14
+ end
15
+
16
+ class Direct < Resource
17
+ include MangoPay::HTTPCalls::Create
18
+ private
19
+ def self.url(id = nil)
20
+ "/v2/#{MangoPay.configuration.client_id}/payins/card/#{CGI.escape(class_name.downcase)}"
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
27
+ end
@@ -1,15 +1,15 @@
1
- module MangoPay
2
- class PayOut < Resource
3
- include MangoPay::HTTPCalls::Fetch
4
-
5
- class BankWire < Resource
6
- include MangoPay::HTTPCalls::Create
7
-
8
- private
9
-
10
- def self.url(id = nil)
11
- "/v2/#{MangoPay.configuration.client_id}/payouts/bankwire"
12
- end
13
- end
14
- end
15
- end
1
+ module MangoPay
2
+ class PayOut < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+
5
+ class BankWire < Resource
6
+ include MangoPay::HTTPCalls::Create
7
+
8
+ private
9
+
10
+ def self.url(id = nil)
11
+ "/v2/#{MangoPay.configuration.client_id}/payouts/bankwire"
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,22 +1,22 @@
1
- module MangoPay
2
- # @abstract
3
- class Resource
4
-
5
- protected
6
-
7
- def self.class_name
8
- self.name.split('::')[-1]
9
- end
10
-
11
- def self.url(id = nil)
12
- if self == Resource
13
- raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
14
- end
15
- if id
16
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id)}"
17
- else
18
- "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
19
- end
20
- end
21
- end
22
- end
1
+ module MangoPay
2
+ # @abstract
3
+ class Resource
4
+
5
+ protected
6
+
7
+ def self.class_name
8
+ self.name.split('::')[-1]
9
+ end
10
+
11
+ def self.url(id = nil)
12
+ if self == Resource
13
+ raise NotImplementedError.new('Resource is an abstract class. Do not use it directly.')
14
+ end
15
+ if id
16
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s/#{CGI.escape(id)}"
17
+ else
18
+ "/v2/#{MangoPay.configuration.client_id}/#{CGI.escape(class_name.downcase)}s"
19
+ end
20
+ end
21
+ end
22
+ end
@@ -1,11 +1,11 @@
1
- module MangoPay
2
- class Transaction < Resource
3
- include MangoPay::HTTPCalls::Fetch
4
-
5
- private
6
-
7
- def self.url(id)
8
- "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(id)}/transactions"
9
- end
10
- end
11
- end
1
+ module MangoPay
2
+ class Transaction < Resource
3
+ include MangoPay::HTTPCalls::Fetch
4
+
5
+ private
6
+
7
+ def self.url(id)
8
+ "/v2/#{MangoPay.configuration.client_id}/wallets/#{CGI.escape(id)}/transactions"
9
+ end
10
+ end
11
+ end