mollie-api-ruby 2.2.1 → 3.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +7 -0
- data/README.md +37 -8
- data/examples/apis/api_docs.rb +1 -1
- data/examples/apis/chargebacks.rb +17 -0
- data/examples/apis/connect.rb +1 -1
- data/examples/apis/customers.rb +7 -6
- data/examples/apis/invoices.rb +2 -2
- data/examples/apis/issuers.rb +2 -2
- data/examples/apis/mandates.rb +5 -5
- data/examples/apis/methods.rb +2 -2
- data/examples/apis/organizations.rb +1 -1
- data/examples/apis/payments.rb +43 -9
- data/examples/apis/permissions.rb +2 -2
- data/examples/apis/profiles.rb +7 -7
- data/examples/apis/refunds.rb +1 -1
- data/examples/apis/settlements.rb +5 -5
- data/examples/apis/subscriptions.rb +7 -7
- data/examples/config.ru +6 -7
- data/lib/{mollie/api/cacert.pem → cacert.pem} +0 -0
- data/lib/mollie-api-ruby.rb +1 -0
- data/lib/mollie.rb +39 -0
- data/lib/mollie/base.rb +91 -0
- data/lib/mollie/chargeback.rb +36 -0
- data/lib/mollie/client.rb +125 -0
- data/lib/mollie/customer.rb +36 -0
- data/lib/mollie/customer/mandate.rb +33 -0
- data/lib/mollie/customer/payment.rb +6 -0
- data/lib/mollie/customer/subscription.rb +65 -0
- data/lib/mollie/exception.rb +8 -0
- data/lib/mollie/invoice.rb +66 -0
- data/lib/mollie/issuer.rb +5 -0
- data/lib/mollie/list.rb +40 -0
- data/lib/mollie/method.rb +38 -0
- data/lib/mollie/organization.rb +24 -0
- data/lib/mollie/payment.rb +142 -0
- data/lib/mollie/payment/chargeback.rb +6 -0
- data/lib/mollie/payment/refund.rb +6 -0
- data/lib/mollie/permission.rb +26 -0
- data/lib/mollie/profile.rb +78 -0
- data/lib/mollie/profile/api_key.rb +19 -0
- data/lib/mollie/refund.rb +42 -0
- data/lib/mollie/relation.rb +36 -0
- data/lib/mollie/settlement.rb +36 -0
- data/lib/mollie/settlement/chargeback.rb +6 -0
- data/lib/mollie/settlement/payment.rb +6 -0
- data/lib/mollie/settlement/refund.rb +6 -0
- data/lib/mollie/util.rb +57 -0
- data/lib/mollie/version.rb +3 -0
- data/mollie.gemspec +2 -2
- data/test/helper.rb +5 -1
- data/test/mollie/base_test.rb +182 -0
- data/test/mollie/chargeback_test.rb +35 -0
- data/test/mollie/client_test.rb +122 -0
- data/test/mollie/customer/mandate_test.rb +43 -0
- data/test/mollie/customer/payment_test.rb +23 -0
- data/test/mollie/customer/subscription_test.rb +66 -0
- data/test/mollie/customer_test.rb +128 -0
- data/test/mollie/invoice_test.rb +55 -0
- data/test/mollie/issuer_test.rb +19 -0
- data/test/mollie/list_test.rb +40 -0
- data/test/mollie/method_test.rb +29 -0
- data/test/mollie/organization_test.rb +41 -0
- data/test/mollie/payment/chargeback_test.rb +22 -0
- data/test/mollie/payment/refund_test.rb +22 -0
- data/test/mollie/payment_test.rb +161 -0
- data/test/mollie/permission_test.rb +21 -0
- data/test/mollie/profile/apikey_test.rb +31 -0
- data/test/mollie/profile_test.rb +98 -0
- data/test/mollie/refund_test.rb +40 -0
- data/test/mollie/settlement/chargeback_test.rb +22 -0
- data/test/mollie/settlement/payment_test.rb +22 -0
- data/test/mollie/settlement/refund_test.rb +22 -0
- data/test/mollie/settlement_test.rb +156 -0
- data/website-docs/chargebacks/list-all.rb +12 -0
- data/website-docs/connect/authorize.rb +15 -0
- data/website-docs/connect/tokens.rb +14 -0
- data/website-docs/customers/create-payment.rb +13 -0
- data/website-docs/customers/create.rb +12 -0
- data/website-docs/customers/delete.rb +10 -0
- data/website-docs/customers/get.rb +10 -0
- data/website-docs/customers/list-payments.rb +10 -0
- data/website-docs/customers/list.rb +12 -0
- data/website-docs/customers/update.rb +11 -0
- data/website-docs/invoices/get.rb +10 -0
- data/website-docs/invoices/list.rb +12 -0
- data/website-docs/issuers/get.rb +10 -0
- data/website-docs/issuers/list.rb +12 -0
- data/website-docs/mandates/create.rb +16 -0
- data/website-docs/mandates/delete.rb +10 -0
- data/website-docs/mandates/get.rb +10 -0
- data/website-docs/mandates/list.rb +12 -0
- data/website-docs/methods/get.rb +10 -0
- data/website-docs/methods/list.rb +12 -0
- data/website-docs/organisations/get.rb +10 -0
- data/website-docs/payments/create-refund.rb +14 -0
- data/website-docs/payments/create.rb +16 -0
- data/website-docs/payments/delete-refund.rb +13 -0
- data/website-docs/payments/delete.rb +12 -0
- data/website-docs/payments/get-chargeback.rb +11 -0
- data/website-docs/payments/get-refund.rb +11 -0
- data/website-docs/payments/get.rb +10 -0
- data/website-docs/payments/list-chargeback.rb +13 -0
- data/website-docs/payments/list-refunds.rb +13 -0
- data/website-docs/payments/list.rb +12 -0
- data/website-docs/payments/payment-webhook.rb +21 -0
- data/website-docs/permissions/get.rb +10 -0
- data/website-docs/permissions/list.rb +12 -0
- data/website-docs/profiles/create.rb +15 -0
- data/website-docs/profiles/delete.rb +10 -0
- data/website-docs/profiles/get-key.rb +11 -0
- data/website-docs/profiles/get.rb +10 -0
- data/website-docs/profiles/list-keys.rb +13 -0
- data/website-docs/profiles/list.rb +12 -0
- data/website-docs/profiles/reset-key.rb +13 -0
- data/website-docs/profiles/update.rb +12 -0
- data/website-docs/refunds/list.rb +12 -0
- data/website-docs/settlements/get.rb +10 -0
- data/website-docs/settlements/list-chargebacks.rb +13 -0
- data/website-docs/settlements/list-payments.rb +13 -0
- data/website-docs/settlements/list-refunds.rb +13 -0
- data/website-docs/settlements/list.rb +12 -0
- data/website-docs/settlements/next.rb +9 -0
- data/website-docs/settlements/open.rb +9 -0
- data/website-docs/subscriptions/create.rb +14 -0
- data/website-docs/subscriptions/delete.rb +10 -0
- data/website-docs/subscriptions/get.rb +10 -0
- data/website-docs/subscriptions/list.rb +12 -0
- metadata +134 -104
- data/lib/mollie/api/client.rb +0 -161
- data/lib/mollie/api/client/version.rb +0 -7
- data/lib/mollie/api/exception.rb +0 -10
- data/lib/mollie/api/object/base.rb +0 -18
- data/lib/mollie/api/object/customer.rb +0 -28
- data/lib/mollie/api/object/customer/mandate.rb +0 -37
- data/lib/mollie/api/object/customer/subscription.rb +0 -69
- data/lib/mollie/api/object/invoice.rb +0 -70
- data/lib/mollie/api/object/issuer.rb +0 -9
- data/lib/mollie/api/object/list.rb +0 -44
- data/lib/mollie/api/object/method.rb +0 -42
- data/lib/mollie/api/object/organization.rb +0 -28
- data/lib/mollie/api/object/payment.rb +0 -137
- data/lib/mollie/api/object/payment/refund.rb +0 -47
- data/lib/mollie/api/object/permission.rb +0 -12
- data/lib/mollie/api/object/profile.rb +0 -78
- data/lib/mollie/api/object/profile/apikey.rb +0 -23
- data/lib/mollie/api/object/settlement.rb +0 -32
- data/lib/mollie/api/resource/base.rb +0 -53
- data/lib/mollie/api/resource/customers.rb +0 -11
- data/lib/mollie/api/resource/customers/mandates.rb +0 -27
- data/lib/mollie/api/resource/customers/payments.rb +0 -27
- data/lib/mollie/api/resource/customers/subscriptions.rb +0 -27
- data/lib/mollie/api/resource/invoices.rb +0 -11
- data/lib/mollie/api/resource/issuers.rb +0 -11
- data/lib/mollie/api/resource/methods.rb +0 -11
- data/lib/mollie/api/resource/organizations.rb +0 -11
- data/lib/mollie/api/resource/payments.rb +0 -11
- data/lib/mollie/api/resource/payments/refunds.rb +0 -27
- data/lib/mollie/api/resource/permissions.rb +0 -31
- data/lib/mollie/api/resource/profiles.rb +0 -11
- data/lib/mollie/api/resource/profiles/apikeys.rb +0 -33
- data/lib/mollie/api/resource/refunds.rb +0 -11
- data/lib/mollie/api/resource/settlements.rb +0 -19
- data/lib/mollie/api/resource/settlements/payments.rb +0 -27
- data/lib/mollie/api/util.rb +0 -53
- data/test/mollie/api/client_test.rb +0 -111
- data/test/mollie/api/object/base_test.rb +0 -21
- data/test/mollie/api/object/customer/mandate_test.rb +0 -47
- data/test/mollie/api/object/customer/subscription_test.rb +0 -70
- data/test/mollie/api/object/customer_test.rb +0 -35
- data/test/mollie/api/object/invoice_test.rb +0 -59
- data/test/mollie/api/object/issuer_test.rb +0 -23
- data/test/mollie/api/object/list_test.rb +0 -44
- data/test/mollie/api/object/method_test.rb +0 -33
- data/test/mollie/api/object/organization_test.rb +0 -45
- data/test/mollie/api/object/payment/refund_test.rb +0 -46
- data/test/mollie/api/object/payment_test.rb +0 -106
- data/test/mollie/api/object/permission_test.rb +0 -25
- data/test/mollie/api/object/profile/apikey_test.rb +0 -35
- data/test/mollie/api/object/profile_test.rb +0 -72
- data/test/mollie/api/object/settlement_test.rb +0 -140
- data/test/mollie/api/resource/base_test.rb +0 -83
- data/test/mollie/api/resource/customers/mandates_test.rb +0 -23
- data/test/mollie/api/resource/customers/payments_test.rb +0 -23
- data/test/mollie/api/resource/customers/subscriptions_test.rb +0 -23
- data/test/mollie/api/resource/customers_test.rb +0 -13
- data/test/mollie/api/resource/invoices_test.rb +0 -13
- data/test/mollie/api/resource/issuers_test.rb +0 -13
- data/test/mollie/api/resource/methods_test.rb +0 -13
- data/test/mollie/api/resource/organizations_test.rb +0 -13
- data/test/mollie/api/resource/payments/refunds_test.rb +0 -23
- data/test/mollie/api/resource/payments_test.rb +0 -13
- data/test/mollie/api/resource/permissions_test.rb +0 -13
- data/test/mollie/api/resource/profiles/apikeys_test.rb +0 -23
- data/test/mollie/api/resource/profiles_test.rb +0 -13
- data/test/mollie/api/resource/settlements_test.rb +0 -13
- data/test/mollie/api/util_test.rb +0 -47
@@ -0,0 +1,26 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Permission < Base
|
3
|
+
AVAILABLE = %w(
|
4
|
+
payments.read
|
5
|
+
payments.write
|
6
|
+
refunds.read
|
7
|
+
refunds.write
|
8
|
+
customers.read
|
9
|
+
customers.write
|
10
|
+
mandates.read
|
11
|
+
mandates.write
|
12
|
+
subscriptions.read
|
13
|
+
subscriptions.write
|
14
|
+
profiles.read
|
15
|
+
profiles.write
|
16
|
+
invoices.read
|
17
|
+
settlements.read
|
18
|
+
organizations.read
|
19
|
+
organizations.write)
|
20
|
+
|
21
|
+
attr_accessor :id,
|
22
|
+
:description,
|
23
|
+
:warning,
|
24
|
+
:granted
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Profile < Base
|
3
|
+
CATEGORY_CODE_GENERAL_MERCHANDISE = 5399
|
4
|
+
CATEGORY_CODE_ELECTRONICS_COMPUTERS_AND_SOFTWARE = 5732
|
5
|
+
CATEGORY_CODE_TRAVEL_RENTAL_AND_TRANSPORTATION = 4121
|
6
|
+
CATEGORY_CODE_FINANCIAL_SERVICES = 6012
|
7
|
+
CATEGORY_CODE_FOOD_AND_DRINKS = 5499
|
8
|
+
CATEGORY_CODE_EVENTS_FESTIVALS_AND_RECREATION = 7999
|
9
|
+
CATEGORY_CODE_BOOKS_MAGAZINES_AND_NEWSPAPERS = 5192
|
10
|
+
CATEGORY_CODE_PERSONAL_SERVICES = 7299
|
11
|
+
CATEGORY_CODE_CHARITY_AND_DONATIONS = 8398
|
12
|
+
CATEGORY_CODE_OTHER = 0
|
13
|
+
|
14
|
+
STATUS_UNVERIFIED = "unverified"
|
15
|
+
STATUS_VERIFIED = "verified"
|
16
|
+
STATUS_BLOCKED = "blocked"
|
17
|
+
|
18
|
+
REVIEW_STATUS_PENDING = "pending"
|
19
|
+
REVIEW_STATUS_REJECTED = "rejected"
|
20
|
+
|
21
|
+
attr_accessor :id,
|
22
|
+
:mode,
|
23
|
+
:name,
|
24
|
+
:website,
|
25
|
+
:email,
|
26
|
+
:phone,
|
27
|
+
:category_code,
|
28
|
+
:status,
|
29
|
+
:review,
|
30
|
+
:created_datetime,
|
31
|
+
:updated_datetime,
|
32
|
+
:links
|
33
|
+
|
34
|
+
def unverified?
|
35
|
+
status == STATUS_UNVERIFIED
|
36
|
+
end
|
37
|
+
|
38
|
+
def verified?
|
39
|
+
status == STATUS_VERIFIED
|
40
|
+
end
|
41
|
+
|
42
|
+
def blocked?
|
43
|
+
status == STATUS_BLOCKED
|
44
|
+
end
|
45
|
+
|
46
|
+
def review=(review)
|
47
|
+
@review = OpenStruct.new(review) if review.is_a?(Hash)
|
48
|
+
end
|
49
|
+
|
50
|
+
def review_pending?
|
51
|
+
@review && @review.status == REVIEW_STATUS_PENDING
|
52
|
+
end
|
53
|
+
|
54
|
+
def review_rejected?
|
55
|
+
@review && @review.status == REVIEW_STATUS_REJECTED
|
56
|
+
end
|
57
|
+
|
58
|
+
def created_datetime=(created_datetime)
|
59
|
+
@created_datetime = Time.parse(created_datetime.to_s) rescue nil
|
60
|
+
end
|
61
|
+
|
62
|
+
def updated_datetime=(updated_datetime)
|
63
|
+
@updated_datetime = Time.parse(updated_datetime.to_s) rescue nil
|
64
|
+
end
|
65
|
+
|
66
|
+
def apikeys_url
|
67
|
+
links && links['apikeys']
|
68
|
+
end
|
69
|
+
|
70
|
+
def checkout_preview_url
|
71
|
+
links && links['checkout_preview_url']
|
72
|
+
end
|
73
|
+
|
74
|
+
def apikeys
|
75
|
+
Relation.new(self, Profile::ApiKey)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Profile
|
3
|
+
class ApiKey < Base
|
4
|
+
attr_accessor :id, :key, :created_datetime
|
5
|
+
|
6
|
+
def testmode?
|
7
|
+
id == Mollie::Client::MODE_TEST
|
8
|
+
end
|
9
|
+
|
10
|
+
def livemode?
|
11
|
+
id == Mollie::Client::MODE_LIVE
|
12
|
+
end
|
13
|
+
|
14
|
+
def created_datetime=(created_datetime)
|
15
|
+
@created_datetime = Time.parse(created_datetime)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Refund < Base
|
3
|
+
STATUS_QUEUED = "queued"
|
4
|
+
STATUS_PENDING = "pending"
|
5
|
+
STATUS_PROCESSING = "processing"
|
6
|
+
STATUS_REFUNDED = "refunded"
|
7
|
+
|
8
|
+
attr_accessor :id,
|
9
|
+
:payment,
|
10
|
+
:amount,
|
11
|
+
:status,
|
12
|
+
:refunded_datetime
|
13
|
+
|
14
|
+
def queued?
|
15
|
+
status == STATUS_QUEUED
|
16
|
+
end
|
17
|
+
|
18
|
+
def pending?
|
19
|
+
status == STATUS_PENDING
|
20
|
+
end
|
21
|
+
|
22
|
+
def processing?
|
23
|
+
status == STATUS_PROCESSING
|
24
|
+
end
|
25
|
+
|
26
|
+
def refunded?
|
27
|
+
status == STATUS_REFUNDED
|
28
|
+
end
|
29
|
+
|
30
|
+
def refunded_datetime=(refunded_datetime)
|
31
|
+
@refunded_datetime = Time.parse(refunded_datetime) rescue nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def amount=(amount)
|
35
|
+
@amount = BigDecimal.new(amount.to_s) if amount
|
36
|
+
end
|
37
|
+
|
38
|
+
def payment=(payment)
|
39
|
+
@payment = Payment.new(payment)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Relation
|
3
|
+
def initialize(parent, klass)
|
4
|
+
@parent = parent
|
5
|
+
@klass = klass
|
6
|
+
end
|
7
|
+
|
8
|
+
def all(*args)
|
9
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
10
|
+
args.push(enhance(options))
|
11
|
+
@klass.all(*args)
|
12
|
+
end
|
13
|
+
|
14
|
+
def get(id, options = {})
|
15
|
+
@klass.get(id, enhance(options))
|
16
|
+
end
|
17
|
+
|
18
|
+
def update(id, data = {})
|
19
|
+
@klass.update(id, enhance(data))
|
20
|
+
end
|
21
|
+
|
22
|
+
def create(data = {})
|
23
|
+
@klass.create(enhance(data))
|
24
|
+
end
|
25
|
+
|
26
|
+
def delete(id, options = {})
|
27
|
+
@klass.delete(id, enhance(options))
|
28
|
+
end
|
29
|
+
|
30
|
+
private
|
31
|
+
|
32
|
+
def enhance(data = {})
|
33
|
+
data.merge(@parent.class.id_param => @parent.id)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Mollie
|
2
|
+
class Settlement < Base
|
3
|
+
attr_accessor :id,
|
4
|
+
:reference,
|
5
|
+
:settled_datetime,
|
6
|
+
:amount,
|
7
|
+
:periods,
|
8
|
+
:payment_ids,
|
9
|
+
:refund_ids,
|
10
|
+
:links
|
11
|
+
|
12
|
+
def self.open(options = {})
|
13
|
+
get("open", options)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.next(options = {})
|
17
|
+
get("next", options)
|
18
|
+
end
|
19
|
+
|
20
|
+
def settled_datetime=(settled_datetime)
|
21
|
+
@settled_datetime = Time.parse(settled_datetime.to_s) rescue nil
|
22
|
+
end
|
23
|
+
|
24
|
+
def amount=(amount)
|
25
|
+
@amount = BigDecimal.new(amount.to_s) if amount
|
26
|
+
end
|
27
|
+
|
28
|
+
def periods=(periods)
|
29
|
+
@periods = Util.nested_openstruct(periods) if periods.is_a?(Hash)
|
30
|
+
end
|
31
|
+
|
32
|
+
def payments
|
33
|
+
links && links['payments']
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/lib/mollie/util.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Mollie
|
2
|
+
module Util
|
3
|
+
extend self
|
4
|
+
|
5
|
+
def nested_underscore_keys(obj)
|
6
|
+
if obj.is_a?(Hash)
|
7
|
+
obj.each_with_object({}) do |(key, value), underscored|
|
8
|
+
underscored[underscore(key)] = nested_underscore_keys(value)
|
9
|
+
end
|
10
|
+
elsif obj.is_a?(Array)
|
11
|
+
obj.map { |v| nested_underscore_keys(v) }
|
12
|
+
else
|
13
|
+
obj
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def camelize_keys(hash)
|
18
|
+
hash.each_with_object({}) do |(key, value), camelized|
|
19
|
+
camelized[camelize(key)] = value
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def underscore(string)
|
24
|
+
string.to_s.gsub(/::/, '/').
|
25
|
+
gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2').
|
26
|
+
gsub(/([a-z\d])([A-Z])/, '\1_\2').
|
27
|
+
tr("-", "_").
|
28
|
+
downcase.to_s
|
29
|
+
end
|
30
|
+
|
31
|
+
# Dirty pluralize function, but currently holds for all required plurals
|
32
|
+
# Not worth to include another library like ActiveSupport
|
33
|
+
def pluralize(string)
|
34
|
+
"#{string}s"
|
35
|
+
end
|
36
|
+
|
37
|
+
def camelize(term)
|
38
|
+
string = term.to_s
|
39
|
+
string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { |match| match.downcase }
|
40
|
+
string.gsub!(/(?:_|(\/))([a-z\d]*)/i) { "#{$1}#{$2.capitalize}" }
|
41
|
+
string.gsub!('/'.freeze, '::'.freeze)
|
42
|
+
string
|
43
|
+
end
|
44
|
+
|
45
|
+
def nested_openstruct(obj)
|
46
|
+
if obj.is_a?(Hash)
|
47
|
+
obj.each_with_object(OpenStruct.new) do |(key, value), openstructed|
|
48
|
+
openstructed[key] = nested_openstruct(value)
|
49
|
+
end
|
50
|
+
elsif obj.is_a?(Array)
|
51
|
+
obj.map { |v| nested_openstruct(v) }
|
52
|
+
else
|
53
|
+
obj
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
data/mollie.gemspec
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
$:.push File.expand_path('../lib', __FILE__)
|
2
2
|
|
3
|
-
require 'mollie/
|
3
|
+
require 'mollie/version'
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'mollie-api-ruby'
|
7
|
-
s.version = Mollie::
|
7
|
+
s.version = Mollie::VERSION
|
8
8
|
s.summary = 'Official Mollie API Client for Ruby'
|
9
9
|
s.description = %(Accepting iDEAL, Bancontact/Mister Cash, SOFORT Banking,
|
10
10
|
Creditcard, SEPA Bank transfer, SEPA Direct debit, Bitcoin,
|
data/test/helper.rb
CHANGED
@@ -0,0 +1,182 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
module Mollie
|
4
|
+
class TestObject < Base
|
5
|
+
attr_accessor :id, :amount, :my_field
|
6
|
+
|
7
|
+
class NestedObject < Base
|
8
|
+
attr_accessor :id, :testobject_id, :amount
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
class BaseTest < Test::Unit::TestCase
|
13
|
+
def test_resource_name
|
14
|
+
assert_equal "testobjects", TestObject.resource_name
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_nested_resource_name
|
18
|
+
assert_equal "testobjects/object-id/nestedobjects", TestObject::NestedObject.resource_name("object-id")
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_setting_attributes
|
22
|
+
attributes = { my_field: "my value", extra_field: "extra" }
|
23
|
+
object = TestObject.new(attributes)
|
24
|
+
|
25
|
+
assert_equal "my value", object.my_field
|
26
|
+
assert_equal attributes, object.attributes
|
27
|
+
end
|
28
|
+
|
29
|
+
def test_get
|
30
|
+
stub_request(:get, "https://api.mollie.nl/v1/testobjects/my-id")
|
31
|
+
.to_return(:status => 200, :body => %{{"id":"my-id"}}, :headers => {})
|
32
|
+
|
33
|
+
resource = TestObject.get("my-id")
|
34
|
+
|
35
|
+
assert_equal "my-id", resource.id
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_nested_get
|
39
|
+
stub_request(:get, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects/my-id")
|
40
|
+
.to_return(:status => 200, :body => %{{"id":"my-id", "testobject_id":"object-id"}}, :headers => {})
|
41
|
+
|
42
|
+
resource = TestObject::NestedObject.get("my-id", testobject_id: 'object-id')
|
43
|
+
|
44
|
+
assert_equal "my-id", resource.id
|
45
|
+
assert_equal "object-id", resource.testobject_id
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_create
|
49
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects")
|
50
|
+
.with(body: %{{"amount":1.95}})
|
51
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.00}}, :headers => {})
|
52
|
+
|
53
|
+
resource = TestObject.create(amount: 1.95)
|
54
|
+
|
55
|
+
assert_equal "my-id", resource.id
|
56
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_nested_create
|
60
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects")
|
61
|
+
.with(body: %{{"amount":1.95}})
|
62
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "testobject_id":"object-id", "amount":1.00}}, :headers => {})
|
63
|
+
|
64
|
+
resource = TestObject::NestedObject.create(amount: 1.95, testobject_id: "object-id")
|
65
|
+
|
66
|
+
assert_equal "my-id", resource.id
|
67
|
+
assert_equal "object-id", resource.testobject_id
|
68
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_update
|
72
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects/my-id")
|
73
|
+
.with(body: %{{"amount":1.95}})
|
74
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.00}}, :headers => {})
|
75
|
+
|
76
|
+
resource = TestObject.update("my-id", amount: 1.95)
|
77
|
+
|
78
|
+
assert_equal "my-id", resource.id
|
79
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_update_instance
|
83
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects/my-id")
|
84
|
+
.with(body: %{{"amount":1.95}})
|
85
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "amount":1.00}}, :headers => {})
|
86
|
+
|
87
|
+
resource = TestObject.new(id: "my-id")
|
88
|
+
resource.update(amount: 1.95)
|
89
|
+
|
90
|
+
assert_equal "my-id", resource.id
|
91
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
92
|
+
end
|
93
|
+
|
94
|
+
def test_nested_update
|
95
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects/my-id")
|
96
|
+
.with(body: %{{"amount":1.95}})
|
97
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "testobject_id":"object-id", "amount":1.00}}, :headers => {})
|
98
|
+
|
99
|
+
resource = TestObject::NestedObject.update("my-id", amount: 1.95, testobject_id: "object-id")
|
100
|
+
|
101
|
+
assert_equal "my-id", resource.id
|
102
|
+
assert_equal "object-id", resource.testobject_id
|
103
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_nested_update_instance
|
107
|
+
stub_request(:post, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects/my-id")
|
108
|
+
.with(body: %{{"amount":1.95}})
|
109
|
+
.to_return(:status => 201, :body => %{{"id":"my-id", "testobject_id":"object-id", "amount":1.00}}, :headers => {})
|
110
|
+
|
111
|
+
resource = TestObject::NestedObject.new(id: "my-id", testobject_id: "object-id")
|
112
|
+
resource.update(amount: 1.95)
|
113
|
+
|
114
|
+
assert_equal "my-id", resource.id
|
115
|
+
assert_equal "object-id", resource.testobject_id
|
116
|
+
assert_equal BigDecimal.new("1.00"), resource.amount
|
117
|
+
end
|
118
|
+
|
119
|
+
def test_delete
|
120
|
+
stub_request(:delete, "https://api.mollie.nl/v1/testobjects/my-id")
|
121
|
+
.to_return(:status => 204, :headers => {})
|
122
|
+
|
123
|
+
resource = TestObject.delete("my-id")
|
124
|
+
|
125
|
+
assert_equal nil, resource
|
126
|
+
end
|
127
|
+
|
128
|
+
def test_delete_instance
|
129
|
+
stub_request(:delete, "https://api.mollie.nl/v1/testobjects/my-id")
|
130
|
+
.to_return(:status => 204, :headers => {})
|
131
|
+
|
132
|
+
resource = TestObject.new(id: "my-id")
|
133
|
+
|
134
|
+
assert_equal nil, resource.delete
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_nested_delete
|
138
|
+
stub_request(:delete, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects/my-id")
|
139
|
+
.to_return(:status => 204, :headers => {})
|
140
|
+
|
141
|
+
resource = TestObject::NestedObject.delete("my-id", testobject_id: "object-id")
|
142
|
+
|
143
|
+
assert_equal nil, resource
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_nested_delete_instance
|
147
|
+
stub_request(:delete, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects/my-id")
|
148
|
+
.to_return(:status => 204, :headers => {})
|
149
|
+
|
150
|
+
resource = TestObject::NestedObject.new(id: "my-id", testobject_id: "object-id")
|
151
|
+
|
152
|
+
assert_equal nil, resource.delete
|
153
|
+
end
|
154
|
+
|
155
|
+
def test_all
|
156
|
+
stub_request(:get, "https://api.mollie.nl/v1/testobjects?count=50&offset=0")
|
157
|
+
.to_return(:status => 200, :body => %{{"data":[{"id":"my-id"}]}}, :headers => {})
|
158
|
+
|
159
|
+
resource = TestObject.all
|
160
|
+
|
161
|
+
assert_equal "my-id", resource.first.id
|
162
|
+
end
|
163
|
+
|
164
|
+
def test_nested_all
|
165
|
+
stub_request(:get, "https://api.mollie.nl/v1/nestedobjects?count=50&offset=0")
|
166
|
+
.to_return(:status => 200, :body => %{{"data":[{"id":"my-id"}]}}, :headers => {})
|
167
|
+
|
168
|
+
resource = TestObject::NestedObject.all
|
169
|
+
|
170
|
+
assert_equal "my-id", resource.first.id
|
171
|
+
end
|
172
|
+
|
173
|
+
def test_nested_all_scoped
|
174
|
+
stub_request(:get, "https://api.mollie.nl/v1/testobjects/object-id/nestedobjects?count=50&offset=0")
|
175
|
+
.to_return(:status => 200, :body => %{{"data":[{"id":"my-id"}]}}, :headers => {})
|
176
|
+
|
177
|
+
resource = TestObject::NestedObject.all(testobject_id: 'object-id')
|
178
|
+
|
179
|
+
assert_equal "my-id", resource.first.id
|
180
|
+
end
|
181
|
+
end
|
182
|
+
end
|