zuora-ruby 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +2 -1
- data/.rubocop.yml +27 -3
- data/README.md +37 -19
- data/lib/zuora.rb +51 -0
- data/lib/zuora/client.rb +51 -25
- data/lib/zuora/models.rb +4 -3
- data/lib/zuora/models/account.rb +58 -47
- data/lib/zuora/models/card_holder.rb +46 -52
- data/lib/zuora/models/contact.rb +65 -38
- data/lib/zuora/models/dirty.rb +192 -0
- data/lib/zuora/models/payment_methods/credit_card.rb +23 -23
- data/lib/zuora/models/rate_plan.rb +6 -10
- data/lib/zuora/models/rate_plan_charge.rb +111 -49
- data/lib/zuora/models/subscription.rb +72 -42
- data/lib/zuora/models/tier.rb +16 -16
- data/lib/zuora/models/validation_predicates.rb +29 -0
- data/lib/zuora/resources.rb +0 -11
- data/lib/zuora/resources/accounts.rb +9 -8
- data/lib/zuora/resources/payment_methods/credit_card.rb +1 -3
- data/lib/zuora/resources/subscriptions.rb +2 -6
- data/lib/zuora/serializers/attribute.rb +3 -3
- data/lib/zuora/version.rb +1 -1
- data/zuora/fixtures/vcr_cassettes/account_create_.yml +111 -0
- data/zuora/fixtures/vcr_cassettes/account_update_.yml +113 -0
- data/zuora/fixtures/vcr_cassettes/subscription_create_.yml +114 -0
- data/zuora/fixtures/vcr_cassettes/subscription_update_.yml +114 -0
- data/zuora_ruby.gemspec +2 -3
- metadata +13 -8
- data/lib/zuora/models/utils.rb +0 -23
@@ -3,19 +3,15 @@
|
|
3
3
|
module Zuora
|
4
4
|
module Models
|
5
5
|
class RatePlan
|
6
|
-
include
|
6
|
+
include DirtyValidAttr
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
dirty_valid_attr :product_rate_plan_id,
|
9
|
+
type: String,
|
10
|
+
required?: true
|
10
11
|
|
11
|
-
|
12
|
+
dirty_valid_attr :charge_overrides
|
12
13
|
|
13
|
-
|
14
|
-
ATTRIBUTES
|
15
|
-
end
|
16
|
-
|
17
|
-
validates :product_rate_plan_id,
|
18
|
-
presence: true
|
14
|
+
alias_method :initialize, :initialize_attributes!
|
19
15
|
end
|
20
16
|
end
|
21
17
|
end
|
@@ -3,55 +3,117 @@
|
|
3
3
|
module Zuora
|
4
4
|
module Models
|
5
5
|
class RatePlanCharge
|
6
|
-
include
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
6
|
+
include DirtyValidAttr
|
7
|
+
|
8
|
+
dirty_valid_attr :apply_discount_to,
|
9
|
+
type: String,
|
10
|
+
valid?: one_of(Zuora::DISCOUNT_TYPES)
|
11
|
+
|
12
|
+
dirty_valid_attr :billing_period,
|
13
|
+
type: String
|
14
|
+
|
15
|
+
dirty_valid_attr :billing_period_alignment,
|
16
|
+
type: String
|
17
|
+
|
18
|
+
dirty_valid_attr :billing_timing,
|
19
|
+
type: String
|
20
|
+
|
21
|
+
dirty_valid_attr :bill_cycle_type,
|
22
|
+
type: String
|
23
|
+
|
24
|
+
dirty_valid_attr :bill_cycle_day,
|
25
|
+
type: String
|
26
|
+
|
27
|
+
dirty_valid_attr :description,
|
28
|
+
type: String,
|
29
|
+
valid?: max_length(500)
|
30
|
+
|
31
|
+
dirty_valid_attr :discount_amount,
|
32
|
+
type: Numeric
|
33
|
+
|
34
|
+
dirty_valid_attr :discount_percentage,
|
35
|
+
type: Numeric
|
36
|
+
|
37
|
+
dirty_valid_attr :discount_level,
|
38
|
+
type: String,
|
39
|
+
valid?: one_of(Zuora::DISCOUNT_LEVELS)
|
40
|
+
|
41
|
+
dirty_valid_attr :end_date_condition,
|
42
|
+
type: String,
|
43
|
+
valid?: one_of(Zuora::END_DATE_CONDITIONS)
|
44
|
+
|
45
|
+
dirty_valid_attr :included_units,
|
46
|
+
type: Numeric
|
47
|
+
|
48
|
+
dirty_valid_attr :list_price_base,
|
49
|
+
type: String,
|
50
|
+
valid?: one_of(Zuora::LIST_PRICE_BASES)
|
51
|
+
|
52
|
+
dirty_valid_attr :number,
|
53
|
+
type: String,
|
54
|
+
valid?: max_length(50)
|
55
|
+
|
56
|
+
dirty_valid_attr :number_of_periods,
|
57
|
+
type: Numeric
|
58
|
+
|
59
|
+
dirty_valid_attr :price,
|
60
|
+
type: Numeric
|
61
|
+
|
62
|
+
dirty_valid_attr :product_rate_plan_charge_id,
|
63
|
+
type: String
|
64
|
+
|
65
|
+
dirty_valid_attr :overage_price,
|
66
|
+
type: Numeric
|
67
|
+
|
68
|
+
dirty_valid_attr :overage_unused_units_credit_option,
|
69
|
+
type: String
|
70
|
+
|
71
|
+
dirty_valid_attr :price_change_option,
|
72
|
+
type: String,
|
73
|
+
valid?: one_of(Zuora::PRICE_CHANGE_OPTIONS)
|
74
|
+
|
75
|
+
dirty_valid_attr :price_increase_percentage,
|
76
|
+
type: String
|
77
|
+
|
78
|
+
dirty_valid_attr :rating_group,
|
79
|
+
type: String
|
80
|
+
|
81
|
+
dirty_valid_attr :quantity,
|
82
|
+
type: Numeric,
|
83
|
+
required?: true,
|
84
|
+
valid?: min(0)
|
85
|
+
|
86
|
+
dirty_valid_attr :specific_billing_period,
|
87
|
+
type: String
|
88
|
+
|
89
|
+
dirty_valid_attr :specific_end_date,
|
90
|
+
type: String
|
91
|
+
|
92
|
+
dirty_valid_attr :tiers
|
93
|
+
|
94
|
+
dirty_valid_attr :trigger_event,
|
95
|
+
type: String,
|
96
|
+
valid?: one_of(TRIGGER_EVENTS)
|
97
|
+
|
98
|
+
dirty_valid_attr :trigger_date,
|
99
|
+
type: Date
|
100
|
+
|
101
|
+
dirty_valid_attr :unused_units_credit_rates,
|
102
|
+
type: String
|
103
|
+
|
104
|
+
dirty_valid_attr :up_to_periods_type,
|
105
|
+
type: String,
|
106
|
+
valid?: one_of(UP_TO_PERIODS)
|
107
|
+
|
108
|
+
dirty_valid_attr :up_to_periods,
|
109
|
+
type: String,
|
110
|
+
required?: other_attr_eq(:end_date_condition,
|
111
|
+
'Fixed_Period')
|
112
|
+
|
113
|
+
dirty_valid_attr :weekly_bill_cycle_day,
|
114
|
+
type: String
|
115
|
+
|
116
|
+
alias_method :initialize, :initialize_attributes!
|
55
117
|
end
|
56
118
|
end
|
57
119
|
end
|
@@ -3,48 +3,78 @@
|
|
3
3
|
module Zuora
|
4
4
|
module Models
|
5
5
|
class Subscription
|
6
|
-
include
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
6
|
+
include DirtyValidAttr
|
7
|
+
|
8
|
+
dirty_valid_attr :auto_renew,
|
9
|
+
type: Boolean
|
10
|
+
|
11
|
+
dirty_valid_attr :apply_credit_balance,
|
12
|
+
type: String
|
13
|
+
|
14
|
+
dirty_valid_attr :account_key,
|
15
|
+
type: String,
|
16
|
+
required?: true
|
17
|
+
|
18
|
+
dirty_valid_attr :contract_effective_date,
|
19
|
+
type: Date,
|
20
|
+
required?: true
|
21
|
+
|
22
|
+
dirty_valid_attr :collect,
|
23
|
+
type: String
|
24
|
+
|
25
|
+
dirty_valid_attr :customer_acceptance_date,
|
26
|
+
type: Date
|
27
|
+
|
28
|
+
dirty_valid_attr :term_type,
|
29
|
+
type: String,
|
30
|
+
required?: true,
|
31
|
+
valid?: one_of(Zuora::SUBSCRIPTION_TERM_TYPES)
|
32
|
+
|
33
|
+
dirty_valid_attr :initial_term,
|
34
|
+
type: String,
|
35
|
+
required?: other_attr_eq(:term_type, 'EVERGREEN')
|
36
|
+
|
37
|
+
dirty_valid_attr :initial_term_period_type,
|
38
|
+
type: String
|
39
|
+
|
40
|
+
dirty_valid_attr :invoice_owner_account_key,
|
41
|
+
type: String
|
42
|
+
|
43
|
+
dirty_valid_attr :invoice_collect,
|
44
|
+
type: Boolean
|
45
|
+
|
46
|
+
dirty_valid_attr :invoice,
|
47
|
+
type: String
|
48
|
+
|
49
|
+
dirty_valid_attr :invoice_separately,
|
50
|
+
type: String
|
51
|
+
|
52
|
+
dirty_valid_attr :invoice_target_date,
|
53
|
+
type: Date
|
54
|
+
|
55
|
+
dirty_valid_attr :notes,
|
56
|
+
type: String
|
57
|
+
|
58
|
+
dirty_valid_attr :renewal_term,
|
59
|
+
type: Numeric
|
60
|
+
|
61
|
+
dirty_valid_attr :renewal_term_period_type,
|
62
|
+
type: String
|
63
|
+
|
64
|
+
dirty_valid_attr :renewal_setting,
|
65
|
+
type: String
|
66
|
+
|
67
|
+
dirty_valid_attr :service_activation_date,
|
68
|
+
type: Date
|
69
|
+
|
70
|
+
dirty_valid_attr :subscribe_to_rate_plans,
|
71
|
+
type: Array,
|
72
|
+
required?: false
|
73
|
+
|
74
|
+
dirty_valid_attr :term_start_date,
|
75
|
+
type: Date
|
76
|
+
|
77
|
+
alias_method :initialize, :initialize_attributes!
|
48
78
|
end
|
49
79
|
end
|
50
80
|
end
|
data/lib/zuora/models/tier.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module Zuora
|
2
2
|
module Models
|
3
3
|
class RatePlanChargeTier
|
4
|
-
include
|
4
|
+
include DirtyValidAttr
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
:price,
|
10
|
-
:price_format
|
6
|
+
dirty_valid_attr :tier,
|
7
|
+
type: Numeric,
|
8
|
+
required?: true
|
11
9
|
|
12
|
-
|
10
|
+
dirty_valid_attr :starting_unit,
|
11
|
+
type: Numeric
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
end
|
13
|
+
dirty_valid_attr :ending_unit,
|
14
|
+
type: Numeric
|
17
15
|
|
18
|
-
|
19
|
-
|
20
|
-
|
16
|
+
dirty_valid_attr :price,
|
17
|
+
type: Numeric,
|
18
|
+
required?: true
|
21
19
|
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
dirty_valid_attr :price_format,
|
21
|
+
type: String,
|
22
|
+
valid?: one_of(%w(FlatFee PerUnit))
|
23
|
+
|
24
|
+
alias_method :initialize, :initialize_attributes!
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module ValidationPredicates
|
2
|
+
def length(n)
|
3
|
+
-> (s) { s.length == n }
|
4
|
+
end
|
5
|
+
|
6
|
+
def min_length(n)
|
7
|
+
->(s) { s.length >= n }
|
8
|
+
end
|
9
|
+
|
10
|
+
def max_length(n)
|
11
|
+
-> (s) { s.length <= n }
|
12
|
+
end
|
13
|
+
|
14
|
+
def min(n)
|
15
|
+
-> (s) { s >= n }
|
16
|
+
end
|
17
|
+
|
18
|
+
def valid_year
|
19
|
+
->(y) { (y.to_s.length == 4) && (y.to_i > Time.now.year - 1) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def one_of(thing)
|
23
|
+
->(t) { thing.include? t }
|
24
|
+
end
|
25
|
+
|
26
|
+
def other_attr_eq(attr, val)
|
27
|
+
->(model) { model.respond_to?(attr) && model.send(attr) == val }
|
28
|
+
end
|
29
|
+
end
|
data/lib/zuora/resources.rb
CHANGED
@@ -1,15 +1,4 @@
|
|
1
1
|
module Zuora
|
2
|
-
module Resources
|
3
|
-
InvalidModel = Class.new(StandardError)
|
4
|
-
|
5
|
-
def self.with_valid(model, &block)
|
6
|
-
if model.valid?
|
7
|
-
block.call model
|
8
|
-
else
|
9
|
-
fail InvalidModel, model
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
2
|
end
|
14
3
|
|
15
4
|
require_relative 'resources/accounts'
|
@@ -3,16 +3,17 @@ module Zuora
|
|
3
3
|
module Accounts
|
4
4
|
RESOURCE_URI = '/rest/v1/accounts'
|
5
5
|
|
6
|
-
def self.
|
7
|
-
|
8
|
-
|
9
|
-
end
|
6
|
+
def self.request!(verb, uri, args)
|
7
|
+
client, model, serializer = args
|
8
|
+
client.send verb, uri, serializer.serialize(model)
|
10
9
|
end
|
11
10
|
|
12
|
-
def self.
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
def self.create!(*args)
|
12
|
+
request! :post, RESOURCE_URI, args
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.update!(*args)
|
16
|
+
request! :put, RESOURCE_URI, args
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
@@ -16,9 +16,7 @@ module Zuora
|
|
16
16
|
# @param [Class] serializer: any object supporting .serialze(data)
|
17
17
|
# @return [Faraday::Response]
|
18
18
|
def self.create!(client, model, serializer = Zuora::Serializers::Noop)
|
19
|
-
|
20
|
-
client.post RESOURCE_URI, serializer.serialize(mod)
|
21
|
-
end
|
19
|
+
client.post RESOURCE_URI, serializer.serialize(model)
|
22
20
|
end
|
23
21
|
end
|
24
22
|
end
|
@@ -6,15 +6,11 @@ module Zuora
|
|
6
6
|
RESOURCE_URI = '/rest/v1/subscriptions'
|
7
7
|
|
8
8
|
def self.create!(client, model, serializer = Zuora::Serializers::Noop)
|
9
|
-
|
10
|
-
client.post RESOURCE_URI, serializer.serialize(mod)
|
11
|
-
end
|
9
|
+
client.post RESOURCE_URI, serializer.serialize(model)
|
12
10
|
end
|
13
11
|
|
14
12
|
def self.update!(client, model, serializer = Zuora::Serializers::Noop)
|
15
|
-
|
16
|
-
client.post RESOURCE_URI, serializer.serialize(mod)
|
17
|
-
end
|
13
|
+
client.post RESOURCE_URI, serializer.serialize(model)
|
18
14
|
end
|
19
15
|
end
|
20
16
|
end
|