active_zuora 1.3.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. data/README.rdoc +22 -1
  2. data/Rakefile +0 -9
  3. data/VERSION +1 -1
  4. data/active_zuora.gemspec +43 -13
  5. data/lib/active_zuora.rb +5 -10
  6. data/lib/active_zuora/account.rb +27 -0
  7. data/lib/active_zuora/amendment.rb +7 -0
  8. data/lib/active_zuora/bill_run.rb +4 -0
  9. data/lib/active_zuora/contact.rb +7 -0
  10. data/lib/active_zuora/invoice.rb +46 -0
  11. data/lib/active_zuora/invoice_item.rb +26 -0
  12. data/lib/active_zuora/invoice_item_adjustment.rb +4 -0
  13. data/lib/active_zuora/invoice_payment.rb +11 -0
  14. data/lib/active_zuora/payment.rb +18 -0
  15. data/lib/active_zuora/payment_method.rb +10 -0
  16. data/lib/active_zuora/product.rb +4 -0
  17. data/lib/active_zuora/product_rate_plan.rb +9 -0
  18. data/lib/active_zuora/product_rate_plan_charge.rb +11 -0
  19. data/lib/active_zuora/product_rate_plan_charge_tier.rb +7 -0
  20. data/lib/active_zuora/product_rate_plan_charge_tier_data.rb +4 -0
  21. data/lib/active_zuora/rate_plan.rb +16 -0
  22. data/lib/active_zuora/rate_plan_charge.rb +44 -0
  23. data/lib/active_zuora/rate_plan_charge_data.rb +4 -0
  24. data/lib/active_zuora/rate_plan_charge_tier.rb +4 -0
  25. data/lib/{zuora → active_zuora}/rate_plan_data.rb +0 -0
  26. data/lib/active_zuora/refund.rb +4 -0
  27. data/lib/{zuora → active_zuora}/subscribe_options.rb +0 -0
  28. data/lib/active_zuora/subscribe_request.rb +13 -0
  29. data/lib/{zuora → active_zuora}/subscribe_with_existing_account_request.rb +0 -0
  30. data/lib/active_zuora/subscription.rb +17 -0
  31. data/lib/{zuora → active_zuora}/subscription_data.rb +0 -0
  32. data/lib/active_zuora/usage.rb +4 -0
  33. data/lib/active_zuora/zobject.rb +156 -0
  34. data/lib/zuora/ZUORA.rb +180 -27
  35. data/lib/zuora/ZUORADriver.rb +17 -0
  36. data/lib/zuora/ZUORAMappingRegistry.rb +236 -23
  37. data/lib/zuora_client.rb +28 -24
  38. data/lib/zuora_interface.rb +21 -5
  39. metadata +112 -17
  40. data/lib/zuora/account.rb +0 -4
  41. data/lib/zuora/contact.rb +0 -4
  42. data/lib/zuora/rate_plan.rb +0 -4
  43. data/lib/zuora/subscribe_request.rb +0 -4
  44. data/lib/zuora/subscription.rb +0 -4
  45. data/lib/zuora/zobject.rb +0 -52
data/README.rdoc CHANGED
@@ -1,4 +1,8 @@
1
- == ActiveZoura
1
+ == Active Zuora Version 2
2
+ * This fork has been moved from its {original location}[https://github.com/anfleene/active_zuora] to its {current location}[https://github.com/tstmedia/active_zuora_v1]
3
+ * The Active Zuora Version 2 gem can be found at https://github.com/tstmedia/active_zuora.
4
+
5
+ == Active Zoura Version 1
2
6
 
3
7
  Client for Zuora API
4
8
 
@@ -9,7 +13,24 @@ The fork is adding a new interface to the gem along with removing parts deemed u
9
13
  The underlying implementation of the zuora4r gem is still in place but that is going to change in the future.
10
14
 
11
15
 
16
+
12
17
  == Installing the Gem
13
18
  $ sudo gem sources -a http://gemcutter.org
14
19
  $ sudo gem install active_zuora
15
20
 
21
+ == Future Releases
22
+
23
+ In the short term this gem will hold on to most of the existing zuora api code with more active recordy style additions to its interface
24
+ In the long term the underlying implementation will be refactored and condensed into something smaller and more idiomatic
25
+
26
+ === Important Missing Features
27
+
28
+ Completion of active zuora's CRUD actions on instance methods
29
+ Support for Zuora's queryMore api call
30
+
31
+ Remove weird error handling Anti Pattern that rescues and prints all Exceptions
32
+
33
+ BUG:
34
+ Auto quote where calls
35
+
36
+
data/Rakefile CHANGED
@@ -45,12 +45,3 @@ task :test => :check_dependencies
45
45
 
46
46
  task :default => :test
47
47
 
48
- require 'rake/rdoctask'
49
- Rake::RDocTask.new do |rdoc|
50
- version = File.exist?('VERSION') ? File.read('VERSION') : ""
51
-
52
- rdoc.rdoc_dir = 'rdoc'
53
- rdoc.title = "active_zuora #{version}"
54
- rdoc.rdoc_files.include('README*')
55
- rdoc.rdoc_files.include('lib/**/*.rb')
56
- end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.3.0
1
+ 1.4.0
data/active_zuora.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "active_zuora"
8
- s.version = "1.3.0"
8
+ s.version = "1.4.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["anfleene"]
12
- s.date = "2012-01-20"
12
+ s.date = "2013-02-18"
13
13
  s.description = "A client for Zuora API"
14
14
  s.email = "anfleene@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -22,41 +22,71 @@ Gem::Specification.new do |s|
22
22
  "active_zuora.gemspec",
23
23
  "custom_fields.yml",
24
24
  "lib/active_zuora.rb",
25
+ "lib/active_zuora/account.rb",
26
+ "lib/active_zuora/amendment.rb",
27
+ "lib/active_zuora/bill_run.rb",
28
+ "lib/active_zuora/contact.rb",
29
+ "lib/active_zuora/invoice.rb",
30
+ "lib/active_zuora/invoice_item.rb",
31
+ "lib/active_zuora/invoice_item_adjustment.rb",
32
+ "lib/active_zuora/invoice_payment.rb",
33
+ "lib/active_zuora/payment.rb",
34
+ "lib/active_zuora/payment_method.rb",
35
+ "lib/active_zuora/product.rb",
36
+ "lib/active_zuora/product_rate_plan.rb",
37
+ "lib/active_zuora/product_rate_plan_charge.rb",
38
+ "lib/active_zuora/product_rate_plan_charge_tier.rb",
39
+ "lib/active_zuora/product_rate_plan_charge_tier_data.rb",
40
+ "lib/active_zuora/rate_plan.rb",
41
+ "lib/active_zuora/rate_plan_charge.rb",
42
+ "lib/active_zuora/rate_plan_charge_data.rb",
43
+ "lib/active_zuora/rate_plan_charge_tier.rb",
44
+ "lib/active_zuora/rate_plan_data.rb",
45
+ "lib/active_zuora/refund.rb",
46
+ "lib/active_zuora/subscribe_options.rb",
47
+ "lib/active_zuora/subscribe_request.rb",
48
+ "lib/active_zuora/subscribe_with_existing_account_request.rb",
49
+ "lib/active_zuora/subscription.rb",
50
+ "lib/active_zuora/subscription_data.rb",
51
+ "lib/active_zuora/usage.rb",
52
+ "lib/active_zuora/zobject.rb",
25
53
  "lib/zuora/ZUORA.rb",
26
54
  "lib/zuora/ZUORADriver.rb",
27
55
  "lib/zuora/ZUORAMappingRegistry.rb",
28
56
  "lib/zuora/ZuoraServiceClient.rb",
29
- "lib/zuora/account.rb",
30
57
  "lib/zuora/api.rb",
31
- "lib/zuora/contact.rb",
32
- "lib/zuora/rate_plan.rb",
33
- "lib/zuora/rate_plan_data.rb",
34
- "lib/zuora/subscribe_options.rb",
35
- "lib/zuora/subscribe_request.rb",
36
- "lib/zuora/subscribe_with_existing_account_request.rb",
37
- "lib/zuora/subscription.rb",
38
- "lib/zuora/subscription_data.rb",
39
- "lib/zuora/zobject.rb",
40
58
  "lib/zuora_client.rb",
41
59
  "lib/zuora_interface.rb"
42
60
  ]
43
61
  s.homepage = "http://github.com/anfleene/active_zuora"
44
62
  s.require_paths = ["lib"]
45
63
  s.requirements = ["none"]
46
- s.rubygems_version = "1.8.10"
64
+ s.rubygems_version = "1.8.24"
47
65
  s.summary = "Active Zuora"
48
66
 
49
67
  if s.respond_to? :specification_version then
50
68
  s.specification_version = 3
51
69
 
52
70
  if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
71
+ s.add_runtime_dependency(%q<soap4r>, ["~> 1.5"])
72
+ s.add_runtime_dependency(%q<json_pure>, ["~> 1.4"])
73
+ s.add_development_dependency(%q<rake>, [">= 0"])
74
+ s.add_development_dependency(%q<jeweler>, [">= 0"])
53
75
  s.add_runtime_dependency(%q<soap4r>, [">= 1.5.8"])
54
76
  s.add_runtime_dependency(%q<json_pure>, [">= 1.4.6"])
55
77
  else
78
+ s.add_dependency(%q<soap4r>, ["~> 1.5"])
79
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
80
+ s.add_dependency(%q<rake>, [">= 0"])
81
+ s.add_dependency(%q<jeweler>, [">= 0"])
56
82
  s.add_dependency(%q<soap4r>, [">= 1.5.8"])
57
83
  s.add_dependency(%q<json_pure>, [">= 1.4.6"])
58
84
  end
59
85
  else
86
+ s.add_dependency(%q<soap4r>, ["~> 1.5"])
87
+ s.add_dependency(%q<json_pure>, ["~> 1.4"])
88
+ s.add_dependency(%q<rake>, [">= 0"])
89
+ s.add_dependency(%q<jeweler>, [">= 0"])
60
90
  s.add_dependency(%q<soap4r>, [">= 1.5.8"])
61
91
  s.add_dependency(%q<json_pure>, [">= 1.4.6"])
62
92
  end
data/lib/active_zuora.rb CHANGED
@@ -1,13 +1,8 @@
1
1
  require 'delegate'
2
2
  require 'zuora_client'
3
- require 'zuora/zobject'
4
- require 'zuora/account'
5
- require 'zuora/contact'
6
- require 'zuora/rate_plan'
7
- require 'zuora/rate_plan_data'
8
- require 'zuora/subscribe_options'
9
- require 'zuora/subscribe_request'
10
- require 'zuora/subscribe_with_existing_account_request'
11
- require 'zuora/subscription'
12
- require 'zuora/subscription_data'
3
+ require 'active_zuora/zobject.rb'
4
+ Dir[File.join(File.dirname(__FILE__),"active_zuora","*.rb")].each do |file|
5
+ require file
6
+ end
7
+
13
8
 
@@ -0,0 +1,27 @@
1
+ module Zuora
2
+ class Account < ZObject
3
+ def billTo
4
+ @billTo ||= Contact.find(self.billToId)
5
+ end
6
+
7
+ def soldTo
8
+ @soldTo ||= Contact.find(self.soldToId)
9
+ end
10
+
11
+ def subscriptions
12
+ @subscriptions ||= Subscription.where(:accountid => self.id)
13
+ end
14
+
15
+ def invoices
16
+ @invoices ||= Invoice.where(:accountid => self.id)
17
+ end
18
+
19
+ def payment_methods
20
+ @payment_methods ||= PaymentMethod.where(:accountid => self.id)
21
+ end
22
+
23
+ def contacts
24
+ @contacts ||= Contact.where(:accountid => self.id)
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,7 @@
1
+ module Zuora
2
+ class Amendment < ZObject
3
+
4
+ exclude_query_attributes :ratePlanData, :termCommitment
5
+
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module Zuora
2
+ class BillRun < ZObject
3
+ end
4
+ end
@@ -0,0 +1,7 @@
1
+ module Zuora
2
+ class Contact < ZObject
3
+ def account
4
+ @account ||= Account.find(self.accountId)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,46 @@
1
+ module Zuora
2
+ class Invoice < ZObject
3
+ def self.extra_attributes(attributes=[])
4
+ super([:body])
5
+ end
6
+
7
+ def self.create(attributes={})
8
+ self.client.generate([self.new(attributes).to_zobject]).first
9
+ end
10
+
11
+ def save
12
+ result = self.class.create(self.attributes)
13
+ if result[:success]
14
+ @errors = []
15
+ __setobj__(self.class.find(result[:id]).to_zobject)
16
+ else
17
+ @errors = result[:errors]
18
+ end
19
+ result[:success]
20
+ end
21
+
22
+ def errors
23
+ @errors || []
24
+ end
25
+
26
+ def post
27
+ return false unless self.id
28
+ result = self.class.update_attributes(:id => self.id, :status => "Posted").first
29
+ @errors = result[:errors]
30
+ result[:success]
31
+ end
32
+
33
+ def invoice_items
34
+ @invoice_items ||= InvoiceItem.where(:invoiceid => self.id)
35
+ end
36
+
37
+ def account
38
+ @account ||= Account.find(self.accountId)
39
+ end
40
+
41
+ def payments
42
+ # Payments, sorted by date.
43
+ @payments ||= InvoicePayment.where(:invoiceId => self.id).map(&:payment).sort { |a, b| a.effectiveDate <=> b.effectiveDate }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,26 @@
1
+ module Zuora
2
+ class InvoiceItem < ZObject
3
+
4
+ def invoice
5
+ @invoice ||= Invoice.find(invoiceId)
6
+ end
7
+
8
+ def rate_plan_charge
9
+ @rate_plan_charge ||= RatePlanCharge.find(ratePlanChargeId)
10
+ end
11
+
12
+ def adjustments
13
+ @adjustments ||= InvoiceItemAdjustment.where(:sourceType => 'InvoiceDetail', :sourceId => id)
14
+ end
15
+
16
+ def adjusted_charge_amount
17
+ @adjusted_charge_amount ||=
18
+ adjustments.inject(chargeAmount) do |amount, adjustment|
19
+ # Adjustment types are either Credit or Charge
20
+ # Credits will have a reducing (subtracting) effect on the invoice item charge.
21
+ adjustment.type == "Credit" ? amount - adjustment.amount : amount + adjustment.amount
22
+ end
23
+ end
24
+
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module Zuora
2
+ class InvoiceItemAdjustment < ZObject
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Zuora
2
+ class InvoicePayment < ZObject
3
+ def invoice
4
+ @invoice ||= Invoice.find(self.invoiceId)
5
+ end
6
+
7
+ def payment
8
+ @payment ||= Payment.find(self.paymentId)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,18 @@
1
+ module Zuora
2
+ class Payment < ZObject
3
+
4
+ exclude_query_attributes :appliedInvoiceAmount, :invoiceId
5
+
6
+ def account
7
+ @account ||= Account.find(self.accountId)
8
+ end
9
+
10
+ def payment_method
11
+ @payment_method ||= PaymentMethod.find(self.paymentMethodId)
12
+ end
13
+
14
+ def invoices
15
+ @invoices ||= InvoicePayment.where(:paymentId => self.id).map(&:invoice)
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,10 @@
1
+ module Zuora
2
+ class PaymentMethod < ZObject
3
+
4
+ exclude_query_attributes :achAccountNumber, :creditCardNumber, :creditCardSecurityCode
5
+
6
+ def account
7
+ @account ||= Account.find(self.accountId)
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,4 @@
1
+ module Zuora
2
+ class Product < ZObject
3
+ end
4
+ end
@@ -0,0 +1,9 @@
1
+ module Zuora
2
+ class ProductRatePlan < ZObject
3
+
4
+ def charges
5
+ @charges ||= ProductRatePlanCharge.where(:productRatePlanId => id)
6
+ end
7
+
8
+ end
9
+ end
@@ -0,0 +1,11 @@
1
+ module Zuora
2
+ class ProductRatePlanCharge < ZObject
3
+ def product_rate_plan
4
+ @product_rate_plan ||= ProductRatePlan.find(self.ProductRatePlanId)
5
+ end
6
+
7
+ def product_rate_plan_charge_tiers
8
+ @product_rate_plan_charge_tiers ||= ProductRatePlanChargeTier.where(:productRatePlanChargeId => self.id)
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,7 @@
1
+ module Zuora
2
+ class ProductRatePlanChargeTier < ZObject
3
+ def product_rate_plan_charge
4
+ @product_rate_plan_charge ||= ProductRatePlanCharge.find(self.productRatePlanChargeId)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,4 @@
1
+ module Zuora
2
+ class ProductRatePlanChargeTierData < ZObject
3
+ end
4
+ end
@@ -0,0 +1,16 @@
1
+ module Zuora
2
+ class RatePlan < ZObject
3
+ def rate_plan_charges
4
+ @rate_plan_charges ||= RatePlanCharge.where(:ratePlanId => self.id)
5
+ end
6
+
7
+ def subscription
8
+ @subscription ||= Subscription.find(self.subscriptionId)
9
+ end
10
+
11
+ def product_rate_plan
12
+ @product_rate_plan ||= ProductRatePlan.find(self.productRatePlanId)
13
+ end
14
+
15
+ end
16
+ end
@@ -0,0 +1,44 @@
1
+ module Zuora
2
+ class RatePlanCharge < ZObject
3
+
4
+ exclude_query_attributes :overagePrice, :includedUnits, :discountAmount, :discountPercentage
5
+
6
+ def rate_plan
7
+ @rate_plan ||= RatePlan.find(self.ratePlanId)
8
+ end
9
+
10
+ def product_rate_plan_charge
11
+ @product_rate_plan_charge ||= ProductRatePlanCharge.find(self.productRatePlanChargeId)
12
+ end
13
+
14
+ def usages
15
+ @usages ||= Usage.where(:chargeId => id)
16
+ end
17
+
18
+ def unload_usages
19
+ @usages = nil
20
+ self
21
+ end
22
+
23
+ def total_price
24
+ (quantity || 1) * price
25
+ end
26
+
27
+ def list_price
28
+ product_rate_plan_charge.product_rate_plan_charge_tiers.first.price
29
+ end
30
+
31
+ def total_list_price
32
+ (quantity || 1) * list_price
33
+ end
34
+
35
+ def discount?
36
+ price < list_price
37
+ end
38
+
39
+ def discount_percent
40
+ list_price.zero? ? nil : (1 - price / list_price) * 100
41
+ end
42
+
43
+ end
44
+ end