invoiced 2.0.0 → 2.1.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.
Files changed (76) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +35 -0
  3. data/Gemfile +2 -2
  4. data/README.md +11 -2
  5. data/lib/invoiced/bank_account.rb +0 -1
  6. data/lib/invoiced/card.rb +0 -1
  7. data/lib/invoiced/custom_field.rb +10 -0
  8. data/lib/invoiced/customer_chasing_cadence.rb +10 -0
  9. data/lib/invoiced/email_template.rb +10 -0
  10. data/lib/invoiced/gl_account.rb +10 -0
  11. data/lib/invoiced/inbox.rb +7 -0
  12. data/lib/invoiced/invoice_chasing_cadence.rb +10 -0
  13. data/lib/invoiced/late_fee_schedule.rb +10 -0
  14. data/lib/invoiced/member.rb +10 -0
  15. data/lib/invoiced/merchant_account.rb +10 -0
  16. data/lib/invoiced/object.rb +5 -1
  17. data/lib/invoiced/payment_method.rb +8 -0
  18. data/lib/invoiced/pdf_template.rb +10 -0
  19. data/lib/invoiced/report.rb +7 -0
  20. data/lib/invoiced/role.rb +10 -0
  21. data/lib/invoiced/sign_up_page.rb +10 -0
  22. data/lib/invoiced/sms_template.rb +10 -0
  23. data/lib/invoiced/tax_rule.rb +10 -0
  24. data/lib/invoiced/theme.rb +10 -0
  25. data/lib/invoiced/version.rb +1 -1
  26. data/lib/invoiced/webhook.rb +10 -0
  27. data/lib/invoiced.rb +39 -2
  28. data/test/invoiced/charge_test.rb +8 -6
  29. data/test/invoiced/contact_test.rb +10 -86
  30. data/test/invoiced/coupon_test.rb +10 -83
  31. data/test/invoiced/credit_balance_adjustment_test.rb +17 -0
  32. data/test/invoiced/credit_note_test.rb +10 -83
  33. data/test/invoiced/custom_field_test.rb +17 -0
  34. data/test/invoiced/customer_chasing_cadence_test.rb +17 -0
  35. data/test/invoiced/customer_test.rb +10 -83
  36. data/test/invoiced/email_template_test.rb +17 -0
  37. data/test/invoiced/estimate_test.rb +10 -83
  38. data/test/invoiced/event_test.rb +6 -21
  39. data/test/invoiced/file_test.rb +8 -47
  40. data/test/invoiced/gl_account_test.rb +17 -0
  41. data/test/invoiced/inbox_test.rb +13 -0
  42. data/test/invoiced/invoice_chasing_cadence_test.rb +17 -0
  43. data/test/invoiced/invoice_test.rb +10 -83
  44. data/test/invoiced/item_test.rb +10 -83
  45. data/test/invoiced/late_fee_schedule_test.rb +17 -0
  46. data/test/invoiced/line_item_test.rb +10 -86
  47. data/test/invoiced/member_test.rb +17 -0
  48. data/test/invoiced/merchant_account_test.rb +17 -0
  49. data/test/invoiced/note_test.rb +10 -83
  50. data/test/invoiced/operations/create_test.rb +22 -0
  51. data/test/invoiced/operations/delete_test.rb +20 -0
  52. data/test/invoiced/operations/endpoint_test.rb +13 -0
  53. data/test/invoiced/operations/list_test.rb +26 -0
  54. data/test/invoiced/operations/operations.rb +0 -0
  55. data/test/invoiced/operations/retrieve_test.rb +22 -0
  56. data/test/invoiced/operations/update_test.rb +29 -0
  57. data/test/invoiced/payment_method_test.rb +15 -0
  58. data/test/invoiced/payment_plan_test.rb +7 -0
  59. data/test/invoiced/payment_test.rb +10 -83
  60. data/test/invoiced/pdf_template_test.rb +17 -0
  61. data/test/invoiced/plan_test.rb +10 -83
  62. data/test/invoiced/refund_test.rb +5 -3
  63. data/test/invoiced/report_test.rb +14 -0
  64. data/test/invoiced/role_test.rb +17 -0
  65. data/test/invoiced/sign_up_page_test.rb +17 -0
  66. data/test/invoiced/sms_template_test.rb +17 -0
  67. data/test/invoiced/subscription_test.rb +10 -71
  68. data/test/invoiced/task_test.rb +10 -83
  69. data/test/invoiced/tax_rate_test.rb +10 -83
  70. data/test/invoiced/tax_rule_test.rb +17 -0
  71. data/test/invoiced/theme_test.rb +17 -0
  72. data/test/invoiced/webhook_test.rb +17 -0
  73. data/test/test_helper.rb +6 -0
  74. metadata +76 -8
  75. data/.travis.yml +0 -15
  76. data/test/invoiced/credit_balance_adjustment.rb +0 -90
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ae182e66a354b88c600800a9f0ef40ff695c44671c8b3bf2bd24100c61be2cdf
4
- data.tar.gz: 3e0897128ea15e9086098560b4beac41e61a97e44a8ec8db542be023e7486e75
3
+ metadata.gz: 2a4b7176ca132f8c23b695c9f5ab7461400495c89370a953daef96b0e3d72ab6
4
+ data.tar.gz: 542389f7ff24edf9037fd6b380491b0a9431d8447e0f66a072f4dd2e64e0494a
5
5
  SHA512:
6
- metadata.gz: 4039ccc2d285ddfcdd0c0aa97aae3c02330fdfdbcfddd1e4c559d0f08b101ec698f396baba1f33a075ac11e805318bad24dac55cbabaafd675e7654e33549424
7
- data.tar.gz: e2d7415d9b996f6ef9b1a63e80f4b14ebbdf411a1fccff21f07803a53048f4922d3eb015162b7f606b7d7a37e471ad8ef40943a4628e7d8c459b819d65c1ec07
6
+ metadata.gz: 05a9da20d885430266a929bd26320ff50691e14be9ba3e09bea0209645cd9196fa96a7f7867f5de36fbb7ee4e1abfda28a9912911f0330b34ea86841df4dce49
7
+ data.tar.gz: d716a1e9dfc4256469abb4ca963278f47583a8322ad9a4c0a6c00a66d6ad6b8fd84f718ce0461c7e54d90408eae947ac8941421914df8a4ef6b336762241c60a
@@ -0,0 +1,35 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: ["master"]
6
+ pull_request:
7
+ branches: ["master"]
8
+
9
+ jobs:
10
+ tests:
11
+ runs-on: ubuntu-latest
12
+ strategy:
13
+ matrix:
14
+ ruby-version:
15
+ - '2.1'
16
+ - '2.2'
17
+ - '2.3'
18
+ - '2.4'
19
+ - '2.5'
20
+ - '2.6'
21
+ - '2.7'
22
+ steps:
23
+ - uses: actions/checkout@v2
24
+
25
+ - name: Setup Ruby
26
+ uses: ruby/setup-ruby@v1
27
+ with:
28
+ ruby-version: ${{ matrix.ruby-version }}
29
+ bundler-cache: true
30
+
31
+ - name: Tests
32
+ env:
33
+ COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
34
+ run: |
35
+ bundle exec rake
data/Gemfile CHANGED
@@ -9,7 +9,7 @@ gem 'shoulda', '~> 3.4.0', :require => false, :group => :test
9
9
  gem 'test-unit', :require => false, :group => :test
10
10
  gem 'rake', :require => false, :group => :test
11
11
  gem 'coveralls', :require => false, :group => :test
12
- gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
13
- gem 'simplecov-console', '~> 0.3.1', :require => false, :group => :test
12
+ gem 'simplecov', '~> 0.10', :require => false, :group => :test
13
+ gem 'simplecov-console', '~> 0.3', :require => false, :group => :test
14
14
  gem 'term-ansicolor', '~> 1.3.2', :require => false, :group => :test
15
15
  gem 'tins', '~> 1.6.0', :require => false, :group => :test
data/README.md CHANGED
@@ -3,7 +3,7 @@ invoiced-ruby
3
3
 
4
4
  This repository contains the Ruby client library for the [Invoiced](https://invoiced.com) API.
5
5
 
6
- [![Build Status](https://travis-ci.com/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.com/Invoiced/invoiced-ruby)
6
+ [![CI](https://github.com/Invoiced/invoiced-php/actions/workflows/ci.yml/badge.svg)](https://github.com/Invoiced/invoiced-php/actions/workflows/ci.yml)
7
7
  [![Coverage Status](https://coveralls.io/repos/Invoiced/invoiced-ruby/badge.svg?branch=master&service=github)](https://coveralls.io/github/Invoiced/invoiced-ruby?branch=master)
8
8
  [![Gem Version](https://badge.fury.io/rb/invoiced.svg)](https://badge.fury.io/rb/invoiced)
9
9
 
@@ -73,4 +73,13 @@ The gem can be built with:
73
73
  gem build invoiced.gemspec
74
74
  ```
75
75
 
76
- The test suite can be ran with `rake test`
76
+ The test suite can be ran with `rake test`
77
+
78
+ ## Deploying
79
+
80
+ The package can be uploaded to pypi with the following commands:
81
+
82
+ ```
83
+ gem build invoiced.gemspec
84
+ gem push invoiced-X.Y.Z.gem
85
+ ```
@@ -1,6 +1,5 @@
1
1
  module Invoiced
2
2
  class BankAccount < PaymentSourceObject
3
-
4
3
  OBJECT_NAME = 'bank_account'
5
4
  end
6
5
  end
data/lib/invoiced/card.rb CHANGED
@@ -1,6 +1,5 @@
1
1
  module Invoiced
2
2
  class Card < PaymentSourceObject
3
-
4
3
  OBJECT_NAME = 'card'
5
4
  end
6
5
  end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class CustomField < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'custom_field'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class CustomerChasingCadence < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'customer_chasing_cadence'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class EmailTemplate < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'email_template'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class GlAccount < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'gl_account'
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Invoiced
2
+ class Inbox < Object
3
+ include Invoiced::Operations::List
4
+
5
+ OBJECT_NAME = 'inbox'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class InvoiceChasingCadence < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'invoice_chasing_cadence'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class LateFeeSchedule < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'late_fee_schedule'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Member < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'member'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class MerchantAccount < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'merchant_account'
9
+ end
10
+ end
@@ -35,7 +35,11 @@ module Invoiced
35
35
 
36
36
  def build_endpoint
37
37
  if self.class.const_defined? "OBJECT_NAME"
38
- '/' + self.class::OBJECT_NAME + 's'
38
+ if self.class::OBJECT_NAME == 'inbox'
39
+ '/inboxes'
40
+ else
41
+ '/' + self.class::OBJECT_NAME + 's'
42
+ end
39
43
  else
40
44
  '/objects'
41
45
  end
@@ -0,0 +1,8 @@
1
+ module Invoiced
2
+ class PaymentMethod < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Update
5
+
6
+ OBJECT_NAME = 'payment_method'
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class PdfTemplate < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'pdf_template'
9
+ end
10
+ end
@@ -0,0 +1,7 @@
1
+ module Invoiced
2
+ class Report < Object
3
+ include Invoiced::Operations::Create
4
+
5
+ OBJECT_NAME = 'report'
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Role < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'role'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class SignUpPage < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'sign_up_page'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class SmsTemplate < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'sms_template'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class TaxRule < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'tax_rule'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Theme < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'theme'
9
+ end
10
+ end
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '2.0.0'
2
+ VERSION = '2.1.0'
3
3
  end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Webhook < Object
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
+
8
+ OBJECT_NAME = 'webhook'
9
+ end
10
+ end
data/lib/invoiced.rb CHANGED
@@ -19,6 +19,7 @@ require 'invoiced/operations/update'
19
19
 
20
20
  require 'invoiced/object'
21
21
  require 'invoiced/payment_source_object'
22
+
22
23
  require 'invoiced/attachment'
23
24
  require 'invoiced/bank_account'
24
25
  require 'invoiced/card'
@@ -27,25 +28,43 @@ require 'invoiced/contact'
27
28
  require 'invoiced/coupon'
28
29
  require 'invoiced/credit_balance_adjustment'
29
30
  require 'invoiced/credit_note'
31
+ require 'invoiced/custom_field'
30
32
  require 'invoiced/customer'
33
+ require 'invoiced/customer_chasing_cadence'
31
34
  require 'invoiced/email'
35
+ require 'invoiced/email_template'
32
36
  require 'invoiced/estimate'
33
37
  require 'invoiced/event'
34
38
  require 'invoiced/file'
39
+ require 'invoiced/gl_account'
40
+ require 'invoiced/inbox'
35
41
  require 'invoiced/invoice'
42
+ require 'invoiced/invoice_chasing_cadence'
36
43
  require 'invoiced/item'
44
+ require 'invoiced/late_fee_schedule'
37
45
  require 'invoiced/letter'
38
46
  require 'invoiced/line_item'
47
+ require 'invoiced/member'
48
+ require 'invoiced/merchant_account'
39
49
  require 'invoiced/note'
40
50
  require 'invoiced/payment'
51
+ require 'invoiced/payment_method'
41
52
  require 'invoiced/payment_plan'
42
53
  require 'invoiced/payment_source'
54
+ require 'invoiced/pdf_template'
43
55
  require 'invoiced/plan'
44
56
  require 'invoiced/refund'
57
+ require 'invoiced/report'
58
+ require 'invoiced/role'
59
+ require 'invoiced/sign_up_page'
60
+ require 'invoiced/sms_template'
45
61
  require 'invoiced/subscription'
46
62
  require 'invoiced/task'
47
63
  require 'invoiced/tax_rate'
64
+ require 'invoiced/tax_rule'
48
65
  require 'invoiced/text_message'
66
+ require 'invoiced/theme'
67
+ require 'invoiced/webhook'
49
68
 
50
69
  module Invoiced
51
70
  class Client
@@ -56,7 +75,7 @@ module Invoiced
56
75
  ReadTimeout = 80
57
76
 
58
77
  attr_reader :api_key, :api_url, :sandbox, :sso_key
59
- attr_reader :Item, :Charge, :Coupon, :CreditBalanceAdjustment, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate
78
+ attr_reader :Charge, :Coupon, :CreditBalanceAdjustment, :CreditNote, :CustomField, :Customer, :CustomerChasingCadence, :EmailTemplate, :Estimate, :Event, :File, :GlAccount, :Inbox, :Invoice, :InvoiceChasingCadence, :Item, :LateFeeSchedule, :Member, :MerchantAccount, :Note, :Payment, :PaymentMethod, :PdfTemplate, :Plan, :Refund, :Report, :Role, :SignUpPage, :SmsTemplate, :Subscription, :Task, :TaxRate, :TaxRule, :Theme, :Webhook
60
79
 
61
80
  def initialize(api_key, sandbox=false, sso_key=false)
62
81
  @api_key = api_key
@@ -65,23 +84,41 @@ module Invoiced
65
84
  @sso_key = sso_key
66
85
 
67
86
  # Object endpoints
68
- @Item = Invoiced::Item.new(self)
69
87
  @Charge = Invoiced::Charge.new(self)
70
88
  @Coupon = Invoiced::Coupon.new(self)
71
89
  @CreditBalanceAdjustment = Invoiced::CreditBalanceAdjustment.new(self)
72
90
  @CreditNote = Invoiced::CreditNote.new(self)
91
+ @CustomField = Invoiced::CustomField.new(self)
73
92
  @Customer = Invoiced::Customer.new(self)
93
+ @CustomerChasingCadence = Invoiced::CustomerChasingCadence.new(self)
94
+ @EmailTemplate = Invoiced::EmailTemplate.new(self)
74
95
  @Estimate = Invoiced::Estimate.new(self)
75
96
  @Event = Invoiced::Event.new(self)
76
97
  @File = Invoiced::File.new(self)
98
+ @GlAccount = Invoiced::GlAccount.new(self)
99
+ @Inbox = Invoiced::Inbox.new(self)
77
100
  @Invoice = Invoiced::Invoice.new(self)
101
+ @InvoiceChasingCadence = Invoiced::InvoiceChasingCadence.new(self)
102
+ @Item = Invoiced::Item.new(self)
103
+ @LateFeeSchedule = Invoiced::LateFeeSchedule.new(self)
104
+ @Member = Invoiced::Member.new(self)
105
+ @MerchantAccount = Invoiced::MerchantAccount.new(self)
78
106
  @Note = Invoiced::Note.new(self)
79
107
  @Payment = Invoiced::Payment.new(self)
108
+ @PaymentMethod = Invoiced::PaymentMethod.new(self)
109
+ @PdfTemplate = Invoiced::PdfTemplate.new(self)
80
110
  @Plan = Invoiced::Plan.new(self)
81
111
  @Refund = Invoiced::Refund.new(self)
112
+ @Report = Invoiced::Report.new(self)
113
+ @Role = Invoiced::Role.new(self)
114
+ @SignUpPage = Invoiced::SignUpPage.new(self)
115
+ @SmsTemplate = Invoiced::SmsTemplate.new(self)
82
116
  @Subscription = Invoiced::Subscription.new(self)
83
117
  @Task = Invoiced::Task.new(self)
84
118
  @TaxRate = Invoiced::TaxRate.new(self)
119
+ @TaxRule = Invoiced::TaxRule.new(self)
120
+ @Theme = Invoiced::Theme.new(self)
121
+ @Webhook = Invoiced::Webhook.new(self)
85
122
  end
86
123
 
87
124
  def request(method, endpoint, params={}, opts={})
@@ -2,9 +2,11 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class ChargeTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- charge = Charge.new(@client, 123)
7
- assert_equal('/charges/123', charge.endpoint())
5
+ include Invoiced::Operations::EndpointTest
6
+
7
+ setup do
8
+ @objectClass = Charge
9
+ @endpoint = '/charges'
8
10
  end
9
11
 
10
12
  should "create a charge" do
@@ -16,10 +18,10 @@ module Invoiced
16
18
  RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
19
 
18
20
  charge = Charge.new(@client, 1234)
19
- charge = charge.create(:amount => 100, :payment_source_type => "card")
21
+ payment = charge.create(:amount => 100, :payment_source_type => "card")
20
22
 
21
- assert_instance_of(Invoiced::Payment, charge)
22
- assert_equal(charge.id, "a1b2c3")
23
+ assert_instance_of(Invoiced::Payment, payment)
24
+ assert_equal(payment.id, "a1b2c3")
23
25
  end
24
26
  end
25
27
  end
@@ -2,92 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class ContactTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- contact = Contact.new(@client, 123)
7
- assert_equal('/contacts/123', contact.endpoint())
8
- end
9
-
10
- should "create a contact" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- contact = Contact.new(@client)
19
- contact = contact.create({:name => "Nancy"})
20
-
21
- assert_instance_of(Invoiced::Contact, contact)
22
- assert_equal(123, contact.id)
23
- assert_equal("Nancy", contact.name)
24
- end
25
-
26
- should "retrieve a contact" do
27
- mockResponse = mock('RestClient::Response')
28
- mockResponse.stubs(:code).returns(200)
29
- mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy"}')
30
- mockResponse.stubs(:headers).returns({})
31
-
32
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
33
-
34
- contact = Contact.new(@client)
35
- contact = contact.retrieve(123)
36
-
37
- assert_instance_of(Invoiced::Contact, contact)
38
- assert_equal(123, contact.id)
39
- assert_equal("Nancy", contact.name)
40
- end
41
-
42
- should "not update a contact when no params" do
43
- contact = Contact.new(@client, 123)
44
- assert_false(contact.save)
45
- end
46
-
47
- should "update a contact" do
48
- mockResponse = mock('RestClient::Response')
49
- mockResponse.stubs(:code).returns(200)
50
- mockResponse.stubs(:body).returns('{"id":123,"name":"Nancy Drew"}')
51
- mockResponse.stubs(:headers).returns({})
52
-
53
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
54
-
55
- contact = Contact.new(@client, 123)
56
- contact.name = "Nancy Drew"
57
- assert_true(contact.save)
58
-
59
- assert_equal("Nancy Drew", contact.name)
60
- end
61
-
62
- should "list all contacts" do
63
- mockResponse = mock('RestClient::Response')
64
- mockResponse.stubs(:code).returns(200)
65
- mockResponse.stubs(:body).returns('[{"id":123,"name":"Nancy"}]')
66
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/contacts?per_page=25&page=1>; rel="self", <https://api.invoiced.com/contacts?per_page=25&page=1>; rel="first", <https://api.invoiced.com/contacts?per_page=25&page=1>; rel="last"')
67
-
68
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
69
-
70
- contact = Contact.new(@client)
71
- contacts, metadata = contact.list
72
-
73
- assert_instance_of(Array, contacts)
74
- assert_equal(1, contacts.length)
75
- assert_equal(123, contacts[0].id)
76
-
77
- assert_instance_of(Invoiced::List, metadata)
78
- assert_equal(15, metadata.total_count)
79
- end
80
-
81
- should "delete a contact" do
82
- mockResponse = mock('RestClient::Response')
83
- mockResponse.stubs(:code).returns(204)
84
- mockResponse.stubs(:body).returns('')
85
- mockResponse.stubs(:headers).returns({})
86
-
87
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
88
-
89
- contact = Contact.new(@client, 123)
90
- assert_true(contact.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Contact
14
+ @endpoint = '/contacts'
91
15
  end
92
16
  end
93
17
  end
@@ -2,89 +2,16 @@ require File.expand_path('../../test_helper', __FILE__)
2
2
 
3
3
  module Invoiced
4
4
  class CouponTest < Test::Unit::TestCase
5
- should "return the api endpoint" do
6
- coupon = Coupon.new(@client, "test")
7
- assert_equal('/coupons/test', coupon.endpoint())
8
- end
9
-
10
- should "create a coupon" do
11
- mockResponse = mock('RestClient::Response')
12
- mockResponse.stubs(:code).returns(201)
13
- mockResponse.stubs(:body).returns('{"id":"test","name":"Test Coupon"}')
14
- mockResponse.stubs(:headers).returns({})
15
-
16
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
-
18
- coupon = @client.Coupon.create({:name => "Test Coupon"})
19
-
20
- assert_instance_of(Invoiced::Coupon, coupon)
21
- assert_equal("test", coupon.id)
22
- assert_equal('Test Coupon', coupon.name)
23
- end
24
-
25
- should "retrieve a coupon" do
26
- mockResponse = mock('RestClient::Response')
27
- mockResponse.stubs(:code).returns(200)
28
- mockResponse.stubs(:body).returns('{"id":"test","name":"Test Coupon"}')
29
- mockResponse.stubs(:headers).returns({})
30
-
31
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
-
33
- coupon = @client.Coupon.retrieve("test")
34
-
35
- assert_instance_of(Invoiced::Coupon, coupon)
36
- assert_equal("test", coupon.id)
37
- assert_equal('Test Coupon', coupon.name)
38
- end
39
-
40
- should "not update a coupon when no params" do
41
- coupon = Coupon.new(@client, "test")
42
- assert_false(coupon.save)
43
- end
44
-
45
- should "update a coupon" do
46
- mockResponse = mock('RestClient::Response')
47
- mockResponse.stubs(:code).returns(200)
48
- mockResponse.stubs(:body).returns('{"id":"test","name":"Testing Coupon"}')
49
- mockResponse.stubs(:headers).returns({})
50
-
51
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
-
53
- coupon = Coupon.new(@client, "test")
54
- coupon.name = "Testing Coupon"
55
- assert_true(coupon.save)
56
-
57
- assert_equal(coupon.name, "Testing Coupon")
58
- end
59
-
60
- should "list all coupons" do
61
- mockResponse = mock('RestClient::Response')
62
- mockResponse.stubs(:code).returns(200)
63
- mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Coupon"}]')
64
- mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="self", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="first", <https://api.invoiced.com/catalog_items?per_page=25&page=1>; rel="last"')
65
-
66
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
-
68
- coupons, metadata = @client.Coupon.list
69
-
70
- assert_instance_of(Array, coupons)
71
- assert_equal(1, coupons.length)
72
- assert_equal("test", coupons[0].id)
73
-
74
- assert_instance_of(Invoiced::List, metadata)
75
- assert_equal(15, metadata.total_count)
76
- end
77
-
78
- should "delete a coupon" do
79
- mockResponse = mock('RestClient::Response')
80
- mockResponse.stubs(:code).returns(204)
81
- mockResponse.stubs(:body).returns('')
82
- mockResponse.stubs(:headers).returns({})
83
-
84
- RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
85
-
86
- coupon = Coupon.new(@client, "test")
87
- assert_true(coupon.delete)
5
+ include Invoiced::Operations::EndpointTest
6
+ include Invoiced::Operations::CreateTest
7
+ include Invoiced::Operations::RetrieveTest
8
+ include Invoiced::Operations::UpdateTest
9
+ include Invoiced::Operations::DeleteTest
10
+ include Invoiced::Operations::ListTest
11
+
12
+ setup do
13
+ @objectClass = Coupon
14
+ @endpoint = '/coupons'
88
15
  end
89
16
  end
90
17
  end