zuora-ruby 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (48) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.rubocop.yml +11 -1
  4. data/README.md +101 -172
  5. data/bin/console +2 -2
  6. data/lib/utils/schema_model.rb +194 -0
  7. data/lib/zuora.rb +30 -72
  8. data/lib/zuora/calls/amend.rb +68 -0
  9. data/lib/zuora/calls/create.rb +9 -0
  10. data/lib/zuora/calls/delete.rb +20 -0
  11. data/lib/zuora/calls/generate.rb +22 -0
  12. data/lib/zuora/calls/login.rb +21 -0
  13. data/lib/zuora/calls/query.rb +15 -0
  14. data/lib/zuora/calls/subscribe.rb +75 -0
  15. data/lib/zuora/calls/update.rb +9 -0
  16. data/lib/zuora/calls/upsert.rb +29 -0
  17. data/lib/zuora/client.rb +84 -94
  18. data/lib/zuora/dispatcher.rb +45 -0
  19. data/lib/zuora/object.rb +5 -0
  20. data/lib/zuora/response.rb +50 -0
  21. data/lib/zuora/utils/envelope.rb +98 -0
  22. data/lib/zuora/version.rb +1 -4
  23. data/zuora_ruby.gemspec +10 -11
  24. metadata +57 -67
  25. data/lib/zuora/models.rb +0 -11
  26. data/lib/zuora/models/account.rb +0 -64
  27. data/lib/zuora/models/card_holder.rb +0 -54
  28. data/lib/zuora/models/contact.rb +0 -71
  29. data/lib/zuora/models/dirty.rb +0 -192
  30. data/lib/zuora/models/payment_method.rb +0 -1
  31. data/lib/zuora/models/payment_methods/credit_card.rb +0 -37
  32. data/lib/zuora/models/rate_plan.rb +0 -17
  33. data/lib/zuora/models/rate_plan_charge.rb +0 -119
  34. data/lib/zuora/models/subscription.rb +0 -80
  35. data/lib/zuora/models/tier.rb +0 -27
  36. data/lib/zuora/models/validation_predicates.rb +0 -29
  37. data/lib/zuora/resources.rb +0 -6
  38. data/lib/zuora/resources/accounts.rb +0 -20
  39. data/lib/zuora/resources/payment_methods.rb +0 -1
  40. data/lib/zuora/resources/payment_methods/credit_card.rb +0 -24
  41. data/lib/zuora/resources/subscriptions.rb +0 -17
  42. data/lib/zuora/serializers.rb +0 -1
  43. data/lib/zuora/serializers/attribute.rb +0 -35
  44. data/lib/zuora/serializers/noop.rb +0 -18
  45. data/zuora/fixtures/vcr_cassettes/account_create_.yml +0 -111
  46. data/zuora/fixtures/vcr_cassettes/account_update_.yml +0 -113
  47. data/zuora/fixtures/vcr_cassettes/subscription_create_.yml +0 -114
  48. data/zuora/fixtures/vcr_cassettes/subscription_update_.yml +0 -114
@@ -1,119 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Zuora
4
- module Models
5
- class RatePlanCharge
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!
117
- end
118
- end
119
- end
@@ -1,80 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Zuora
4
- module Models
5
- class Subscription
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!
78
- end
79
- end
80
- end
@@ -1,27 +0,0 @@
1
- module Zuora
2
- module Models
3
- class RatePlanChargeTier
4
- include DirtyValidAttr
5
-
6
- dirty_valid_attr :tier,
7
- type: Numeric,
8
- required?: true
9
-
10
- dirty_valid_attr :starting_unit,
11
- type: Numeric
12
-
13
- dirty_valid_attr :ending_unit,
14
- type: Numeric
15
-
16
- dirty_valid_attr :price,
17
- type: Numeric,
18
- required?: true
19
-
20
- dirty_valid_attr :price_format,
21
- type: String,
22
- valid?: one_of(%w(FlatFee PerUnit))
23
-
24
- alias_method :initialize, :initialize_attributes!
25
- end
26
- end
27
- end
@@ -1,29 +0,0 @@
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
@@ -1,6 +0,0 @@
1
- module Zuora
2
- end
3
-
4
- require_relative 'resources/accounts'
5
- require_relative 'resources/payment_methods'
6
- require_relative 'resources/subscriptions'
@@ -1,20 +0,0 @@
1
- module Zuora
2
- module Resources
3
- module Accounts
4
- RESOURCE_URI = '/rest/v1/accounts'
5
-
6
- def self.request!(verb, uri, args)
7
- client, model, serializer = args
8
- client.send verb, uri, serializer.serialize(model)
9
- end
10
-
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
17
- end
18
- end
19
- end
20
- end
@@ -1 +0,0 @@
1
- require_relative 'payment_methods/credit_card'
@@ -1,24 +0,0 @@
1
- # encoding: utf-8
2
- module Zuora
3
- module Resources
4
- module PaymentMethods
5
- module CreditCards
6
- RESOURCE_URI = '/rest/v1/credit_card/payment_account'
7
-
8
- # Validates a model, and throws if invalid.
9
- # Otherwise, makes an HTTP request, creating a credit card
10
- # payment account.
11
-
12
- # https://api.zuora.com/rest/v1/payment-methods/credit-cards
13
-
14
- # @param [Zuora::Client] client
15
- # @param [Zuora::Model::PaymentMethod] model: the credit card
16
- # @param [Class] serializer: any object supporting .serialze(data)
17
- # @return [Faraday::Response]
18
- def self.create!(client, model, serializer = Zuora::Serializers::Noop)
19
- client.post RESOURCE_URI, serializer.serialize(model)
20
- end
21
- end
22
- end
23
- end
24
- end
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- module Zuora
4
- module Resources
5
- module Subscriptions
6
- RESOURCE_URI = '/rest/v1/subscriptions'
7
-
8
- def self.create!(client, model, serializer = Zuora::Serializers::Noop)
9
- client.post RESOURCE_URI, serializer.serialize(model)
10
- end
11
-
12
- def self.update!(client, model, serializer = Zuora::Serializers::Noop)
13
- client.post RESOURCE_URI, serializer.serialize(model)
14
- end
15
- end
16
- end
17
- end
@@ -1 +0,0 @@
1
- require_relative 'serializers/attribute'
@@ -1,35 +0,0 @@
1
- module Zuora
2
- module Serializers
3
- module Attribute
4
- # @param [Object] model: An object responding to .attributes
5
- # for which each attr can be .send(attr)
6
- # @param [Hash] { [String]: lowerCamelCased key =>
7
- # [Any]: value }
8
- def self.serialize(model)
9
- attrs = model.changed_attributes || {}
10
- attr_pairs = attrs.map { |attr| serialize_attr model, attr }
11
- Hash[attr_pairs]
12
- end
13
-
14
- private
15
-
16
- def self.serialize_attr(object, attr)
17
- # Camelizes the stringified attribute name
18
-
19
- # Note: This specific transformation (lowerCamelCase)
20
- # could be passed in; decoupling recursive traversal
21
- # from the end-node render / transformation.
22
- key = attr.to_s.camelize(:lower)
23
-
24
- # Get current attribute's property
25
- val = object.send(attr)
26
-
27
- # Recursively serialize this attribute's
28
- # attributes, if they are defined
29
- val = serialize val if val.respond_to?(:changed_attributes)
30
-
31
- [key, val]
32
- end
33
- end
34
- end
35
- end
@@ -1,18 +0,0 @@
1
- module Zuora
2
- module Serializers
3
- module Noop
4
- def self.serialize(model)
5
- attrs = model.attributes
6
- attr_pairs = attrs.map { |attr| serialize_attr model, attr }
7
- Hash[attr_pairs]
8
- end
9
-
10
- private
11
-
12
- def self.serialize_attr(object, attr)
13
- val = object.send(attr)
14
- [attr, val]
15
- end
16
- end
17
- end
18
- end
@@ -1,111 +0,0 @@
1
- ---
2
- http_interactions:
3
- - request:
4
- method: post
5
- uri: https://apisandbox-api.zuora.com/rest/v1/connections
6
- body:
7
- encoding: UTF-8
8
- string: ''
9
- headers:
10
- User-Agent:
11
- - Faraday v0.9.2
12
- Apiaccesskeyid:
13
- - <ZUORA_SANDBOX_USERNAME>
14
- Apisecretaccesskey:
15
- - <ZUORA_SANDBOX_PASSWORD>
16
- Content-Type:
17
- - application/json
18
- Content-Length:
19
- - '0'
20
- Accept-Encoding:
21
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
22
- Accept:
23
- - "*/*"
24
- response:
25
- status:
26
- code: 200
27
- message: OK
28
- headers:
29
- Server:
30
- - Zuora App
31
- Content-Type:
32
- - application/json;charset=utf-8
33
- Content-Length:
34
- - '22'
35
- Expires:
36
- - Tue, 12 Jan 2016 16:24:48 GMT
37
- Cache-Control:
38
- - max-age=0, no-cache, no-store
39
- Pragma:
40
- - no-cache
41
- Date:
42
- - Tue, 12 Jan 2016 16:24:48 GMT
43
- Connection:
44
- - keep-alive
45
- Set-Cookie:
46
- - ZSession=dyulKCwYntJ2Ts8BHJqKuC2YTwR_ib4dNlxPXITUPpGrDQwRFQW3ZmRfgYAVfxz7_p3QQMyMSH0lULznTeiwNd2nOD7nEHTOQ-XM2nHnEKijEdsMQG303M31q_ZZqLkEISXQQlw2ynD4-ASPL6Ntihr84WUrgfCdT4-J1crQCofOWZDMpisz7v3iHfXSGEQF1mYh8voS_Xm1xSDbFqrlxYbz3n4iSZIpVPCfx-T-qWRJARzBVyqTZFiAzYd-NQ48;
47
- Path=/; Secure; HttpOnly
48
- body:
49
- encoding: UTF-8
50
- string: |-
51
- {
52
- "success" : true
53
- }
54
- http_version:
55
- recorded_at: Tue, 12 Jan 2016 16:24:48 GMT
56
- - request:
57
- method: post
58
- uri: https://apisandbox-api.zuora.com/rest/v1/accounts
59
- body:
60
- encoding: UTF-8
61
- string: '{"accountNumber":null,"autoPay":true,"billToContact":{"address1":"123
62
- Main St","address2":null,"city":"Palm Springs","country":"US","county":null,"fax":null,"firstName":"Abc","homePhone":null,"lastName":"Def","mobilePhone":null,"nickname":null,"otherPhone":null,"otherPhoneType":null,"personalEmail":null,"zipCode":"90210","state":"FL","taxRegion":null,"workEmail":null,"workPhone":null},"billCycleDay":"0","crmId":null,"currency":"USD","creditCard":{"cardType":"Visa","cardNumber":"4111111111111111","expirationMonth":"03","expirationYear":"2017","securityCode":"122"},"name":"Abc","hpmCreditCardPaymentMethodId":null,"notes":null,"invoiceTemplateId":null,"communicationProfileId":null,"paymentGateway":null,"paymentTerm":"Net
63
- 30","soldToContact":{"address1":"123 Main St","address2":null,"city":"Palm
64
- Springs","country":"US","county":null,"fax":null,"firstName":"Abc","homePhone":null,"lastName":"Def","mobilePhone":null,"nickname":null,"otherPhone":null,"otherPhoneType":null,"personalEmail":null,"zipCode":"90210","state":"FL","taxRegion":null,"workEmail":null,"workPhone":null},"subscription":null}'
65
- headers:
66
- User-Agent:
67
- - Faraday v0.9.2
68
- Content-Type:
69
- - application/json
70
- Cookie:
71
- - ZSession=dyulKCwYntJ2Ts8BHJqKuC2YTwR_ib4dNlxPXITUPpGrDQwRFQW3ZmRfgYAVfxz7_p3QQMyMSH0lULznTeiwNd2nOD7nEHTOQ-XM2nHnEKijEdsMQG303M31q_ZZqLkEISXQQlw2ynD4-ASPL6Ntihr84WUrgfCdT4-J1crQCofOWZDMpisz7v3iHfXSGEQF1mYh8voS_Xm1xSDbFqrlxYbz3n4iSZIpVPCfx-T-qWRJARzBVyqTZFiAzYd-NQ48;
72
- Accept-Encoding:
73
- - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
74
- Accept:
75
- - "*/*"
76
- response:
77
- status:
78
- code: 200
79
- message: OK
80
- headers:
81
- Server:
82
- - Zuora App
83
- Content-Type:
84
- - application/json;charset=utf-8
85
- Content-Length:
86
- - '165'
87
- Expires:
88
- - Tue, 12 Jan 2016 16:24:50 GMT
89
- Cache-Control:
90
- - max-age=0, no-cache, no-store
91
- Pragma:
92
- - no-cache
93
- Date:
94
- - Tue, 12 Jan 2016 16:24:50 GMT
95
- Connection:
96
- - keep-alive
97
- Set-Cookie:
98
- - ZSession=5MN3TBgZNC_DFsjjvc40Qdpud3-X9T7nuEFW-s5EawYiiS_bCE5_HTHzWy3ZA_XAYnP8Ug5ZBFMtIN4qdUJKJ5Zhs5YjMHux4o01CSwY8aghqxWiJ5UrpBX1fJiQRoLbGyeVnmaQ3laH4L0N9U5GEmgrFjb9xHwwd-8DSTPNwhifF1TBeEhBm8ZFVd-uGl3P3EikMO7eT8zeOgG9RIAzjQ271sY6DMs9smE-iSxfAo8nJdHZ-e7bcfngyCFGUlLA;
99
- Path=/; Secure; HttpOnly
100
- body:
101
- encoding: UTF-8
102
- string: |-
103
- {
104
- "success" : true,
105
- "accountId" : "2c92c0fb523018ef015236a76e9c4fdd",
106
- "accountNumber" : "A00000075",
107
- "paymentMethodId" : "2c92c0fb523018ef015236a7773c4fe3"
108
- }
109
- http_version:
110
- recorded_at: Tue, 12 Jan 2016 16:24:50 GMT
111
- recorded_with: VCR 3.0.1