recurly 3.0.0.beta.5 → 3.0.0
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.
- checksums.yaml +5 -5
- data/.bumpversion.cfg +12 -0
- data/.travis.yml +2 -2
- data/.yardopts +3 -0
- data/CONTRIBUTING.md +102 -0
- data/GETTING_STARTED.md +266 -0
- data/README.md +12 -194
- data/benchmark.rb +16 -0
- data/lib/recurly.rb +4 -7
- data/lib/recurly/client.rb +60 -60
- data/lib/recurly/client/operations.rb +498 -340
- data/lib/recurly/errors.rb +4 -0
- data/lib/recurly/http.rb +43 -0
- data/lib/recurly/pager.rb +4 -10
- data/lib/recurly/request.rb +6 -6
- data/lib/recurly/requests.rb +8 -0
- data/lib/recurly/requests/account_acquisition_updatable.rb +2 -2
- data/lib/recurly/requests/billing_info_create.rb +4 -0
- data/lib/recurly/requests/custom_field.rb +18 -0
- data/lib/recurly/requests/invoice_create.rb +0 -4
- data/lib/recurly/requests/invoice_refund.rb +2 -2
- data/lib/recurly/requests/line_item_create.rb +4 -0
- data/lib/recurly/requests/purchase_create.rb +3 -7
- data/lib/recurly/requests/shipping_fee_create.rb +22 -0
- data/lib/recurly/requests/shipping_purchase.rb +22 -0
- data/lib/recurly/requests/subscription_add_on_create.rb +2 -6
- data/lib/recurly/requests/subscription_add_on_update.rb +26 -0
- data/lib/recurly/requests/subscription_change_create.rb +7 -3
- data/lib/recurly/requests/subscription_change_shipping_create.rb +22 -0
- data/lib/recurly/requests/subscription_create.rb +4 -8
- data/lib/recurly/requests/subscription_shipping_create.rb +30 -0
- data/lib/recurly/requests/subscription_shipping_update.rb +22 -0
- data/lib/recurly/requests/subscription_update.rb +3 -7
- data/lib/recurly/resource.rb +14 -1
- data/lib/recurly/resources.rb +17 -0
- data/lib/recurly/resources/account_acquisition.rb +2 -2
- data/lib/recurly/resources/add_on.rb +1 -1
- data/lib/recurly/resources/billing_info.rb +6 -6
- data/lib/recurly/resources/coupon.rb +1 -1
- data/lib/recurly/resources/coupon_discount.rb +2 -2
- data/lib/recurly/resources/coupon_redemption.rb +2 -2
- data/lib/recurly/resources/coupon_redemption_mini.rb +2 -2
- data/lib/recurly/resources/error_may_have_transaction.rb +2 -2
- data/lib/recurly/resources/invoice.rb +4 -0
- data/lib/recurly/resources/line_item.rb +1 -1
- data/lib/recurly/resources/{billing_info_payment_method.rb → payment_method.rb} +18 -2
- data/lib/recurly/resources/plan.rb +1 -1
- data/lib/recurly/resources/shipping_method.rb +42 -0
- data/lib/recurly/resources/shipping_method_mini.rb +26 -0
- data/lib/recurly/resources/subscription.rb +3 -3
- data/lib/recurly/resources/subscription_change.rb +4 -0
- data/lib/recurly/resources/subscription_shipping.rb +26 -0
- data/lib/recurly/resources/transaction.rb +4 -4
- data/lib/recurly/resources/transaction_error.rb +30 -0
- data/lib/recurly/schema.rb +85 -49
- data/lib/recurly/schema/json_parser.rb +16 -8
- data/lib/recurly/schema/request_caster.rb +10 -16
- data/lib/recurly/schema/resource_caster.rb +48 -0
- data/lib/recurly/schema/schema_factory.rb +0 -2
- data/lib/recurly/schema/schema_validator.rb +11 -14
- data/lib/recurly/version.rb +1 -1
- data/recurly.gemspec +6 -6
- data/scripts/build +1 -0
- data/scripts/bump +4 -0
- data/scripts/format +2 -0
- data/scripts/release +11 -0
- data/scripts/test +1 -0
- metadata +38 -20
- data/.ruby-version +0 -1
- data/lib/recurly/resources/transaction_payment_method.rb +0 -34
- data/lib/recurly/schema/json_deserializer.rb +0 -56
data/lib/recurly/resource.rb
CHANGED
@@ -5,7 +5,7 @@ module Recurly
|
|
5
5
|
# and get a new Resource.
|
6
6
|
class Resource
|
7
7
|
extend Schema::SchemaFactory
|
8
|
-
extend Schema::
|
8
|
+
extend Schema::ResourceCaster
|
9
9
|
include Schema::SchemaValidator
|
10
10
|
|
11
11
|
attr_reader :attributes
|
@@ -18,10 +18,23 @@ module Recurly
|
|
18
18
|
self.attributes == other_resource.attributes
|
19
19
|
end
|
20
20
|
|
21
|
+
# Hide instance variables to keep from accidental logging
|
22
|
+
def inspect
|
23
|
+
"#<#{self.class.name}:#{object_id}} @attributes=#{attributes}>"
|
24
|
+
end
|
25
|
+
|
21
26
|
def to_s
|
22
27
|
self.inspect
|
23
28
|
end
|
24
29
|
|
30
|
+
def to_json
|
31
|
+
raise NoMethodError, "to_json is not implemented for Resources. Please use Resource#attributes"
|
32
|
+
end
|
33
|
+
|
34
|
+
def get_response
|
35
|
+
@response
|
36
|
+
end
|
37
|
+
|
25
38
|
protected
|
26
39
|
|
27
40
|
def schema
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# Include all resource files
|
2
|
+
resources = File.join(File.dirname(__FILE__), "resources", "*.rb")
|
3
|
+
Dir.glob(resources, &method(:require))
|
4
|
+
|
5
|
+
module Recurly
|
6
|
+
module Resources
|
7
|
+
class Empty < Resource
|
8
|
+
end
|
9
|
+
|
10
|
+
class Page < Resource
|
11
|
+
# leave data untyped
|
12
|
+
define_attribute :data, Array, item_type: Hash
|
13
|
+
define_attribute :has_more, :Boolean
|
14
|
+
define_attribute :next, String
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -19,8 +19,8 @@ module Recurly
|
|
19
19
|
define_attribute :channel, String
|
20
20
|
|
21
21
|
# @!attribute cost
|
22
|
-
# @return [
|
23
|
-
define_attribute :cost,
|
22
|
+
# @return [AccountAcquisitionCost]
|
23
|
+
define_attribute :cost, :AccountAcquisitionCost
|
24
24
|
|
25
25
|
# @!attribute created_at
|
26
26
|
# @return [DateTime] When the account acquisition data was created.
|
@@ -55,7 +55,7 @@ module Recurly
|
|
55
55
|
define_attribute :state, String
|
56
56
|
|
57
57
|
# @!attribute tax_code
|
58
|
-
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature
|
58
|
+
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature you can use `unknown`, `physical`, or `digital`.
|
59
59
|
define_attribute :tax_code, String
|
60
60
|
|
61
61
|
# @!attribute updated_at
|
@@ -27,8 +27,8 @@ module Recurly
|
|
27
27
|
define_attribute :first_name, String
|
28
28
|
|
29
29
|
# @!attribute fraud
|
30
|
-
# @return [
|
31
|
-
define_attribute :fraud,
|
30
|
+
# @return [FraudInfo] Most recent fraud result.
|
31
|
+
define_attribute :fraud, :FraudInfo
|
32
32
|
|
33
33
|
# @!attribute id
|
34
34
|
# @return [String]
|
@@ -43,16 +43,16 @@ module Recurly
|
|
43
43
|
define_attribute :object, String
|
44
44
|
|
45
45
|
# @!attribute payment_method
|
46
|
-
# @return [
|
47
|
-
define_attribute :payment_method,
|
46
|
+
# @return [PaymentMethod]
|
47
|
+
define_attribute :payment_method, :PaymentMethod
|
48
48
|
|
49
49
|
# @!attribute updated_at
|
50
50
|
# @return [DateTime] When the billing information was last changed.
|
51
51
|
define_attribute :updated_at, DateTime
|
52
52
|
|
53
53
|
# @!attribute updated_by
|
54
|
-
# @return [
|
55
|
-
define_attribute :updated_by,
|
54
|
+
# @return [BillingInfoUpdatedBy]
|
55
|
+
define_attribute :updated_by, :BillingInfoUpdatedBy
|
56
56
|
|
57
57
|
# @!attribute valid
|
58
58
|
# @return [Boolean]
|
@@ -75,7 +75,7 @@ module Recurly
|
|
75
75
|
define_attribute :object, String
|
76
76
|
|
77
77
|
# @!attribute plans
|
78
|
-
# @return [Array[PlanMini]]
|
78
|
+
# @return [Array[PlanMini]] A list of plans for which this coupon applies. This will be `null` if `applies_to_all_plans=true`.
|
79
79
|
define_attribute :plans, Array, { :item_type => :PlanMini }
|
80
80
|
|
81
81
|
# @!attribute plans_names
|
@@ -15,8 +15,8 @@ module Recurly
|
|
15
15
|
define_attribute :percent, Integer
|
16
16
|
|
17
17
|
# @!attribute trial
|
18
|
-
# @return [
|
19
|
-
define_attribute :trial,
|
18
|
+
# @return [CouponDiscountTrial] This is only present when `type=free_trial`.
|
19
|
+
define_attribute :trial, :CouponDiscountTrial
|
20
20
|
|
21
21
|
# @!attribute type
|
22
22
|
# @return [String]
|
@@ -23,8 +23,8 @@ module Recurly
|
|
23
23
|
define_attribute :currency, String
|
24
24
|
|
25
25
|
# @!attribute discounted
|
26
|
-
# @return [
|
27
|
-
define_attribute :discounted,
|
26
|
+
# @return [Float] The amount that was discounted upon the application of the coupon, formatted with the currency.
|
27
|
+
define_attribute :discounted, Float
|
28
28
|
|
29
29
|
# @!attribute id
|
30
30
|
# @return [String] Coupon Redemption ID
|
@@ -15,8 +15,8 @@ module Recurly
|
|
15
15
|
define_attribute :created_at, DateTime
|
16
16
|
|
17
17
|
# @!attribute discounted
|
18
|
-
# @return [
|
19
|
-
define_attribute :discounted,
|
18
|
+
# @return [Float] The amount that was discounted upon the application of the coupon, formatted with the currency.
|
19
|
+
define_attribute :discounted, Float
|
20
20
|
|
21
21
|
# @!attribute id
|
22
22
|
# @return [String] Coupon Redemption ID
|
@@ -15,8 +15,8 @@ module Recurly
|
|
15
15
|
define_attribute :params, Array, { :item_type => Hash }
|
16
16
|
|
17
17
|
# @!attribute transaction_error
|
18
|
-
# @return [
|
19
|
-
define_attribute :transaction_error,
|
18
|
+
# @return [TransactionError] This is only included on errors with `type=transaction`.
|
19
|
+
define_attribute :transaction_error, :TransactionError
|
20
20
|
|
21
21
|
# @!attribute type
|
22
22
|
# @return [String] Type
|
@@ -90,6 +90,10 @@ module Recurly
|
|
90
90
|
# @return [Float] The refundable amount on a charge invoice. It will be null for all other invoices.
|
91
91
|
define_attribute :refundable_amount, Float
|
92
92
|
|
93
|
+
# @!attribute shipping_address
|
94
|
+
# @return [ShippingAddress]
|
95
|
+
define_attribute :shipping_address, :ShippingAddress
|
96
|
+
|
93
97
|
# @!attribute state
|
94
98
|
# @return [String] Invoice state
|
95
99
|
define_attribute :state, String
|
@@ -139,7 +139,7 @@ module Recurly
|
|
139
139
|
define_attribute :tax, Float
|
140
140
|
|
141
141
|
# @!attribute tax_code
|
142
|
-
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature
|
142
|
+
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature you can use `unknown`, `physical`, or `digital`.
|
143
143
|
define_attribute :tax_code, String
|
144
144
|
|
145
145
|
# @!attribute tax_exempt
|
@@ -4,7 +4,15 @@
|
|
4
4
|
# need and we will usher them to the appropriate places.
|
5
5
|
module Recurly
|
6
6
|
module Resources
|
7
|
-
class
|
7
|
+
class PaymentMethod < Resource
|
8
|
+
|
9
|
+
# @!attribute account_type
|
10
|
+
# @return [String] The bank account type. Only present for ACH payment methods.
|
11
|
+
define_attribute :account_type, String
|
12
|
+
|
13
|
+
# @!attribute billing_agreement_id
|
14
|
+
# @return [String] Billing Agreement identifier. Only present for Amazon or Paypal payment methods.
|
15
|
+
define_attribute :billing_agreement_id, String
|
8
16
|
|
9
17
|
# @!attribute card_type
|
10
18
|
# @return [String] Visa, MasterCard, American Express, Discover, JCB, etc.
|
@@ -23,12 +31,20 @@ module Recurly
|
|
23
31
|
define_attribute :first_six, String
|
24
32
|
|
25
33
|
# @!attribute last_four
|
26
|
-
# @return [String] Credit card number's last four digits.
|
34
|
+
# @return [String] Credit card number's last four digits. Will refer to bank account if payment method is ACH.
|
27
35
|
define_attribute :last_four, String
|
28
36
|
|
29
37
|
# @!attribute object
|
30
38
|
# @return [String]
|
31
39
|
define_attribute :object, String
|
40
|
+
|
41
|
+
# @!attribute routing_number
|
42
|
+
# @return [String] The bank account's routing number. Only present for ACH payment methods.
|
43
|
+
define_attribute :routing_number, String
|
44
|
+
|
45
|
+
# @!attribute routing_number_bank
|
46
|
+
# @return [String] The bank name of this routing number.
|
47
|
+
define_attribute :routing_number_bank, String
|
32
48
|
end
|
33
49
|
end
|
34
50
|
end
|
@@ -67,7 +67,7 @@ module Recurly
|
|
67
67
|
define_attribute :state, String
|
68
68
|
|
69
69
|
# @!attribute tax_code
|
70
|
-
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature
|
70
|
+
# @return [String] Used by Avalara, Vertex, and Recurly’s EU VAT tax feature. The tax code values are specific to each tax system. If you are using Recurly’s EU VAT feature you can use `unknown`, `physical`, or `digital`.
|
71
71
|
define_attribute :tax_code, String
|
72
72
|
|
73
73
|
# @!attribute tax_exempt
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# This file is automatically created by Recurly's OpenAPI generation process
|
2
|
+
# and thus any edits you make by hand will be lost. If you wish to make a
|
3
|
+
# change to this file, please create a Github issue explaining the changes you
|
4
|
+
# need and we will usher them to the appropriate places.
|
5
|
+
module Recurly
|
6
|
+
module Resources
|
7
|
+
class ShippingMethod < Resource
|
8
|
+
|
9
|
+
# @!attribute code
|
10
|
+
# @return [String] The internal name used identify the shipping method.
|
11
|
+
define_attribute :code, String
|
12
|
+
|
13
|
+
# @!attribute created_at
|
14
|
+
# @return [DateTime] Created at
|
15
|
+
define_attribute :created_at, DateTime
|
16
|
+
|
17
|
+
# @!attribute deleted_at
|
18
|
+
# @return [DateTime] Deleted at
|
19
|
+
define_attribute :deleted_at, DateTime
|
20
|
+
|
21
|
+
# @!attribute id
|
22
|
+
# @return [String] Shipping Method ID
|
23
|
+
define_attribute :id, String
|
24
|
+
|
25
|
+
# @!attribute name
|
26
|
+
# @return [String] The name of the shipping method displayed to customers.
|
27
|
+
define_attribute :name, String
|
28
|
+
|
29
|
+
# @!attribute object
|
30
|
+
# @return [String] Object type
|
31
|
+
define_attribute :object, String
|
32
|
+
|
33
|
+
# @!attribute tax_code
|
34
|
+
# @return [String] Used by Avalara, Vertex, and Recurly’s built-in tax feature. The tax code values are specific to each tax system. If you are using Recurly’s built-in taxes the values are: - `FR` – Common Carrier FOB Destination - `FR022000` – Common Carrier FOB Origin - `FR020400` – Non Common Carrier FOB Destination - `FR020500` – Non Common Carrier FOB Origin - `FR010100` – Delivery by Company Vehicle Before Passage of Title - `FR010200` – Delivery by Company Vehicle After Passage of Title - `NT` – Non-Taxable
|
35
|
+
define_attribute :tax_code, String
|
36
|
+
|
37
|
+
# @!attribute updated_at
|
38
|
+
# @return [DateTime] Last updated at
|
39
|
+
define_attribute :updated_at, DateTime
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file is automatically created by Recurly's OpenAPI generation process
|
2
|
+
# and thus any edits you make by hand will be lost. If you wish to make a
|
3
|
+
# change to this file, please create a Github issue explaining the changes you
|
4
|
+
# need and we will usher them to the appropriate places.
|
5
|
+
module Recurly
|
6
|
+
module Resources
|
7
|
+
class ShippingMethodMini < Resource
|
8
|
+
|
9
|
+
# @!attribute code
|
10
|
+
# @return [String] The internal name used identify the shipping method.
|
11
|
+
define_attribute :code, String
|
12
|
+
|
13
|
+
# @!attribute id
|
14
|
+
# @return [String] Shipping Method ID
|
15
|
+
define_attribute :id, String
|
16
|
+
|
17
|
+
# @!attribute name
|
18
|
+
# @return [String] The name of the shipping method displayed to customers.
|
19
|
+
define_attribute :name, String
|
20
|
+
|
21
|
+
# @!attribute object
|
22
|
+
# @return [String] Object type
|
23
|
+
define_attribute :object, String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -126,9 +126,9 @@ module Recurly
|
|
126
126
|
# @return [Integer] If `auto_renew=true`, when a term completes, `total_billing_cycles` takes this value as the length of subsequent terms. Defaults to the plan's `total_billing_cycles`.
|
127
127
|
define_attribute :renewal_billing_cycles, Integer
|
128
128
|
|
129
|
-
# @!attribute
|
130
|
-
# @return [
|
131
|
-
define_attribute :
|
129
|
+
# @!attribute shipping
|
130
|
+
# @return [SubscriptionShipping]
|
131
|
+
define_attribute :shipping, :SubscriptionShipping
|
132
132
|
|
133
133
|
# @!attribute state
|
134
134
|
# @return [String] State
|
@@ -42,6 +42,10 @@ module Recurly
|
|
42
42
|
# @return [Integer] Subscription quantity
|
43
43
|
define_attribute :quantity, Integer
|
44
44
|
|
45
|
+
# @!attribute shipping
|
46
|
+
# @return [SubscriptionShipping]
|
47
|
+
define_attribute :shipping, :SubscriptionShipping
|
48
|
+
|
45
49
|
# @!attribute subscription_id
|
46
50
|
# @return [String] The ID of the subscription that is going to be changed.
|
47
51
|
define_attribute :subscription_id, String
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# This file is automatically created by Recurly's OpenAPI generation process
|
2
|
+
# and thus any edits you make by hand will be lost. If you wish to make a
|
3
|
+
# change to this file, please create a Github issue explaining the changes you
|
4
|
+
# need and we will usher them to the appropriate places.
|
5
|
+
module Recurly
|
6
|
+
module Resources
|
7
|
+
class SubscriptionShipping < Resource
|
8
|
+
|
9
|
+
# @!attribute address
|
10
|
+
# @return [ShippingAddress]
|
11
|
+
define_attribute :address, :ShippingAddress
|
12
|
+
|
13
|
+
# @!attribute amount
|
14
|
+
# @return [Float] Subscription's shipping cost
|
15
|
+
define_attribute :amount, Float
|
16
|
+
|
17
|
+
# @!attribute method
|
18
|
+
# @return [ShippingMethodMini]
|
19
|
+
define_attribute :method, :ShippingMethodMini
|
20
|
+
|
21
|
+
# @!attribute object
|
22
|
+
# @return [String] Object type
|
23
|
+
define_attribute :object, String
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -103,12 +103,12 @@ module Recurly
|
|
103
103
|
define_attribute :original_transaction_id, String
|
104
104
|
|
105
105
|
# @!attribute payment_gateway
|
106
|
-
# @return [
|
107
|
-
define_attribute :payment_gateway,
|
106
|
+
# @return [TransactionPaymentGateway]
|
107
|
+
define_attribute :payment_gateway, :TransactionPaymentGateway
|
108
108
|
|
109
109
|
# @!attribute payment_method
|
110
|
-
# @return [
|
111
|
-
define_attribute :payment_method,
|
110
|
+
# @return [PaymentMethod]
|
111
|
+
define_attribute :payment_method, :PaymentMethod
|
112
112
|
|
113
113
|
# @!attribute refunded
|
114
114
|
# @return [Boolean] Indicates if part or all of this transaction was refunded.
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# This file is automatically created by Recurly's OpenAPI generation process
|
2
|
+
# and thus any edits you make by hand will be lost. If you wish to make a
|
3
|
+
# change to this file, please create a Github issue explaining the changes you
|
4
|
+
# need and we will usher them to the appropriate places.
|
5
|
+
module Recurly
|
6
|
+
module Resources
|
7
|
+
class TransactionError < Resource
|
8
|
+
|
9
|
+
# @!attribute category
|
10
|
+
# @return [String] Category
|
11
|
+
define_attribute :category, String
|
12
|
+
|
13
|
+
# @!attribute code
|
14
|
+
# @return [String] Code
|
15
|
+
define_attribute :code, String
|
16
|
+
|
17
|
+
# @!attribute merchant_advice
|
18
|
+
# @return [String] Merchant message
|
19
|
+
define_attribute :merchant_advice, String
|
20
|
+
|
21
|
+
# @!attribute message
|
22
|
+
# @return [String] Customer message
|
23
|
+
define_attribute :message, String
|
24
|
+
|
25
|
+
# @!attribute transaction_id
|
26
|
+
# @return [String] Transaction ID
|
27
|
+
define_attribute :transaction_id, String
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/recurly/schema.rb
CHANGED
@@ -3,21 +3,21 @@ module Recurly
|
|
3
3
|
# This is used for requests and resources.
|
4
4
|
class Schema
|
5
5
|
# The attributes in the schema
|
6
|
-
# @return [
|
6
|
+
# @return [Hash<String,Attribute>]
|
7
7
|
attr_reader :attributes
|
8
8
|
|
9
9
|
def initialize
|
10
|
-
@attributes =
|
10
|
+
@attributes = {}
|
11
11
|
end
|
12
12
|
|
13
13
|
# Adds an attribute to the schema definition
|
14
14
|
#
|
15
15
|
# @param name [Symbol] The name of the attribute
|
16
16
|
# @param type [Class,Symbol] The type of the attribute. Use capitalized symbol for Recurly class. Example: :Account.
|
17
|
-
# @param options [
|
17
|
+
# @param options [Schema::Attribute] The created and registered attribute object.
|
18
18
|
def add_attribute(name, type, options)
|
19
|
-
attribute = Attribute.
|
20
|
-
@attributes.
|
19
|
+
attribute = Attribute.build(type, options)
|
20
|
+
@attributes[name.to_s] = attribute
|
21
21
|
attribute
|
22
22
|
end
|
23
23
|
|
@@ -26,8 +26,7 @@ module Recurly
|
|
26
26
|
# @param name [String,Symbol] The name/key of the attribute
|
27
27
|
# @return [Attribute,nil] The found Attribute. nil if not found.
|
28
28
|
def get_attribute(name)
|
29
|
-
name
|
30
|
-
@attributes.find { |a| a.name.to_s == name }
|
29
|
+
@attributes[name.to_s]
|
31
30
|
end
|
32
31
|
|
33
32
|
# Gets a recurly class given a symbol name.
|
@@ -46,75 +45,112 @@ module Recurly
|
|
46
45
|
Resources::Address
|
47
46
|
elsif Requests.const_defined?(type)
|
48
47
|
Requests.const_get(type)
|
49
|
-
elsif Resources.const_defined?(type)
|
48
|
+
elsif Recurly::Resources.const_defined?(type)
|
50
49
|
Resources.const_get(type)
|
51
50
|
else
|
52
51
|
raise ArgumentError, "Recurly type '#{type}' is unknown"
|
53
52
|
end
|
54
53
|
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
#
|
59
|
-
#
|
60
|
-
|
55
|
+
class Attribute
|
56
|
+
# The type of the attribute. Might be a class like `DateTime`
|
57
|
+
# or could be a Recurly object. In this case a symbol should be used.
|
58
|
+
# Example: :Account. To get the Recurly type use #recurly_class
|
59
|
+
# @return [Class,Symbol]
|
60
|
+
attr_reader :type
|
61
|
+
|
62
|
+
PRIMITIVE_TYPES = [
|
63
|
+
String,
|
64
|
+
Integer,
|
65
|
+
Float,
|
66
|
+
Hash,
|
67
|
+
].freeze
|
68
|
+
|
69
|
+
def self.build(type, options = {})
|
70
|
+
if PRIMITIVE_TYPES.include? type
|
71
|
+
PrimitiveAttribute.new(type)
|
72
|
+
elsif type == :Boolean
|
73
|
+
BooleanAttribute.new
|
74
|
+
elsif type == DateTime
|
75
|
+
DateTimeAttribute.new
|
76
|
+
elsif type.is_a? Symbol
|
77
|
+
ResourceAttribute.new(type)
|
78
|
+
elsif type == Array
|
79
|
+
item_attr = build(options[:item_type])
|
80
|
+
ArrayAttribute.new(item_attr)
|
81
|
+
else
|
82
|
+
throw ArgumentError
|
83
|
+
end
|
84
|
+
end
|
61
85
|
|
62
|
-
def initialize(
|
63
|
-
@
|
86
|
+
def initialize(type = nil)
|
87
|
+
@type = type
|
64
88
|
end
|
65
89
|
|
66
|
-
def
|
67
|
-
|
90
|
+
def cast(value)
|
91
|
+
value
|
68
92
|
end
|
69
|
-
end
|
70
93
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
attr_accessor :name
|
94
|
+
def recurly_class
|
95
|
+
@recurly_class ||= Schema.get_recurly_class(type)
|
96
|
+
end
|
97
|
+
end
|
76
98
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
99
|
+
class PrimitiveAttribute < Attribute
|
100
|
+
def is_valid?(value)
|
101
|
+
value.is_a? self.type
|
102
|
+
end
|
103
|
+
end
|
82
104
|
|
83
|
-
|
84
|
-
|
85
|
-
|
105
|
+
class BooleanAttribute < Attribute
|
106
|
+
def is_valid?(value)
|
107
|
+
[true, false].include? value
|
108
|
+
end
|
109
|
+
end
|
86
110
|
|
87
|
-
|
88
|
-
|
89
|
-
|
111
|
+
class DateTimeAttribute < Attribute
|
112
|
+
def is_valid?(value)
|
113
|
+
value.is_a?(String) || value.is_a?(DateTime)
|
114
|
+
end
|
90
115
|
|
91
|
-
def
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
116
|
+
def cast(value)
|
117
|
+
if value.is_a?(DateTime)
|
118
|
+
value
|
119
|
+
else
|
120
|
+
DateTime.parse(value)
|
121
|
+
end
|
96
122
|
end
|
97
123
|
|
98
|
-
def
|
99
|
-
|
124
|
+
def type
|
125
|
+
DateTime
|
100
126
|
end
|
127
|
+
end
|
101
128
|
|
102
|
-
|
103
|
-
|
129
|
+
class ResourceAttribute < Attribute
|
130
|
+
def is_valid?(value)
|
131
|
+
value.is_a? Hash
|
104
132
|
end
|
105
133
|
|
106
|
-
def
|
107
|
-
|
108
|
-
t.is_a?(Class) || t == :Boolean
|
134
|
+
def cast(value)
|
135
|
+
self.recurly_class.cast(value)
|
109
136
|
end
|
110
137
|
end
|
111
138
|
|
112
|
-
|
113
|
-
|
139
|
+
class ArrayAttribute < Attribute
|
140
|
+
def is_valid?(value)
|
141
|
+
value.is_a? Array
|
142
|
+
end
|
143
|
+
|
144
|
+
def cast(value)
|
145
|
+
value.map do |v|
|
146
|
+
self.type.cast(v)
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
114
150
|
end
|
115
151
|
|
116
152
|
require_relative "./schema/schema_factory"
|
117
153
|
require_relative "./schema/schema_validator"
|
118
|
-
require_relative "./schema/
|
154
|
+
require_relative "./schema/resource_caster"
|
119
155
|
require_relative "./schema/request_caster"
|
120
156
|
end
|