invoiced 0.14.0 → 1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 30c5827c11d5486e3b59fe3443bb63d8674eca3c
4
- data.tar.gz: 7edd7c088f5df46d2159842c33620493ac1866b3
2
+ SHA256:
3
+ metadata.gz: 70ebd92f8b1b9caeb8ae322330450c69419c767181a9d69dcf58d780fcd61073
4
+ data.tar.gz: 682b5d3ae99ba0b0a1d9b84549e05caee01ca16e697a6b6b9359e5e6b62251c8
5
5
  SHA512:
6
- metadata.gz: 507af5506883b32332cd60a0dc2fafecc084b57fd600e267f615690bc1ba8cfc9fd4b3969e6b2387582c211b1b648470625914bf8d0da9b9cb309f00d7a961ff
7
- data.tar.gz: 4cd5f77e2feeba132dee73ab7cb34b60d9e8d3eceeea5ae437cf7121c249967468cacd5982ed0497b032d6d08968a764d4fbc5c42b4764a65ca1d0fea5446896
6
+ metadata.gz: be0b700fb8a50060abc54b3d347240919096f3040c9c2079957a436487478c384a275518c69dcf6196294d171f98d6e0811197945a6adc5d8b009fc52aca193b
7
+ data.tar.gz: b969af7e6fcc78554e592fb7859dea19741954fc36fb002232c39d4fca76242165368dce9be296ec4ac7e184e39a5e01534a6d118ac007477ee7d76693aaf056
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  Gemfile.lock
2
2
  example.rb
3
3
  /invoiced-*.gem
4
- /coverage
4
+ /coverage
5
+ .DS_Store
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Coupon < 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 = 'coupon'
9
+ end
10
+ end
@@ -35,5 +35,13 @@ module Invoiced
35
35
 
36
36
  return attachments, metadata
37
37
  end
38
+
39
+ def void()
40
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
41
+
42
+ refresh_from(response[:body].dup.merge({:id => self.id}))
43
+
44
+ return response[:code] == 200
45
+ end
38
46
  end
39
47
  end
@@ -15,6 +15,22 @@ module Invoiced
15
15
  Util.build_objects(email, response[:body])
16
16
  end
17
17
 
18
+ def send_statement_sms(params={}, opts={})
19
+ response = @client.request(:post, "#{self.endpoint()}/text_messages", params, opts)
20
+
21
+ # build text message objects
22
+ text_message = TextMessage.new(@client)
23
+ Util.build_objects(text_message, response[:body])
24
+ end
25
+
26
+ def send_statement_letter(params={}, opts={})
27
+ response = @client.request(:post, "#{self.endpoint()}/letters", params, opts)
28
+
29
+ # build letter objects
30
+ letter = Letter.new(@client)
31
+ Util.build_objects(letter, response[:body])
32
+ end
33
+
18
34
  def balance
19
35
  response = @client.request(:get, "#{self.endpoint()}/balance")
20
36
 
@@ -31,6 +47,11 @@ module Invoiced
31
47
  line.set_endpoint_base(self.endpoint())
32
48
  end
33
49
 
50
+ def list_notes()
51
+ note = Note.new(@client)
52
+ note.set_endpoint_base(self.endpoint())
53
+ end
54
+
34
55
  def invoice(params={}, opts={})
35
56
  response = @client.request(:post, "#{self.endpoint()}/invoices", params, opts)
36
57
 
@@ -38,5 +59,13 @@ module Invoiced
38
59
  invoice = Invoice.new(@client)
39
60
  Util.convert_to_object(invoice, response[:body])
40
61
  end
62
+
63
+ def consolidate_invoices(params={})
64
+ response = @client.request(:post, "#{self.endpoint()}/consolidate_invoices", params)
65
+
66
+ # build invoice object
67
+ invoice = Invoice.new(@client)
68
+ Util.convert_to_object(invoice, response[:body])
69
+ end
41
70
  end
42
71
  end
@@ -43,5 +43,13 @@ module Invoiced
43
43
 
44
44
  return attachments, metadata
45
45
  end
46
+
47
+ def void()
48
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
49
+
50
+ refresh_from(response[:body].dup.merge({:id => self.id}))
51
+
52
+ return response[:code] == 200
53
+ end
46
54
  end
47
55
  end
@@ -15,6 +15,23 @@ module Invoiced
15
15
  Util.build_objects(email, response[:body])
16
16
  end
17
17
 
18
+ def send_sms(params={}, opts={})
19
+ response = @client.request(:post, "#{self.endpoint()}/text_messages", params, opts)
20
+
21
+ # build text message objects
22
+ text_message = TextMessage.new(@client)
23
+ Util.build_objects(text_message, response[:body])
24
+ end
25
+
26
+ def send_letter(params={}, opts={})
27
+ response = @client.request(:post, "#{self.endpoint()}/letters", params, opts)
28
+
29
+ # build letter objects
30
+
31
+ letter = Letter.new(@client)
32
+ Util.build_objects(letter, response[:body])
33
+ end
34
+
18
35
  def pay(opts={})
19
36
  response = @client.request(:post, "#{self.endpoint()}/pay", {}, opts)
20
37
 
@@ -33,7 +50,7 @@ module Invoiced
33
50
  if !attachment.has_key?(:id)
34
51
  attachment[:id] = attachment[:file][:id]
35
52
  end
36
- end
53
+ end
37
54
 
38
55
  # build objects
39
56
  attachment = Attachment.new(@client)
@@ -49,5 +66,18 @@ module Invoiced
49
66
  paymentPlan = PaymentPlan.new(@client)
50
67
  paymentPlan.set_endpoint_base(self.endpoint())
51
68
  end
69
+
70
+ def notes()
71
+ note = Note.new(@client)
72
+ note.set_endpoint_base(self.endpoint())
73
+ end
74
+
75
+ def void()
76
+ response = @client.request(:post, "#{self.endpoint()}/void", {})
77
+
78
+ refresh_from(response[:body].dup.merge({:id => self.id}))
79
+
80
+ return response[:code] == 200
81
+ end
52
82
  end
53
83
  end
@@ -0,0 +1,5 @@
1
+ module Invoiced
2
+ class Letter < Object
3
+ OBJECT_NAME = 'letter'
4
+ end
5
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Note < 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 = 'note'
9
+ end
10
+ end
@@ -10,5 +10,11 @@ module Invoiced
10
10
  def cancel
11
11
  delete
12
12
  end
13
+
14
+ def preview(params={}, opts={})
15
+ response = @client.request(:post, "/subscriptions/preview", params, opts)
16
+
17
+ response[:body]
18
+ end
13
19
  end
14
20
  end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class Task < 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 = 'task'
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ module Invoiced
2
+ class TaxRate < 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_rate'
9
+ end
10
+ end
@@ -0,0 +1,5 @@
1
+ module Invoiced
2
+ class TextMessage < Object
3
+ OBJECT_NAME = 'text_message'
4
+ end
5
+ end
@@ -20,5 +20,11 @@ module Invoiced
20
20
 
21
21
  Util.convert_to_object(self, response[:body])
22
22
  end
23
+
24
+ def initiate_charge(params={}, opts={})
25
+ response = @client.request(:post, "/charges", params, opts)
26
+
27
+ Util.convert_to_object(self, response[:body])
28
+ end
23
29
  end
24
30
  end
@@ -1,3 +1,3 @@
1
1
  module Invoiced
2
- VERSION = '0.14.0'
2
+ VERSION = '1.0.0'
3
3
  end
data/lib/invoiced.rb CHANGED
@@ -21,6 +21,7 @@ require 'invoiced/object'
21
21
  require 'invoiced/attachment'
22
22
  require 'invoiced/catalog_item'
23
23
  require 'invoiced/contact'
24
+ require 'invoiced/coupon'
24
25
  require 'invoiced/credit_note'
25
26
  require 'invoiced/customer'
26
27
  require 'invoiced/email'
@@ -28,10 +29,15 @@ require 'invoiced/estimate'
28
29
  require 'invoiced/event'
29
30
  require 'invoiced/file'
30
31
  require 'invoiced/invoice'
32
+ require 'invoiced/letter'
31
33
  require 'invoiced/line_item'
34
+ require 'invoiced/note'
32
35
  require 'invoiced/payment_plan'
33
36
  require 'invoiced/plan'
34
37
  require 'invoiced/subscription'
38
+ require 'invoiced/task'
39
+ require 'invoiced/tax_rate'
40
+ require 'invoiced/text_message'
35
41
  require 'invoiced/transaction'
36
42
 
37
43
  module Invoiced
@@ -43,7 +49,7 @@ module Invoiced
43
49
  ReadTimeout = 80
44
50
 
45
51
  attr_reader :api_key, :api_url, :sandbox, :sso_key
46
- attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
52
+ attr_reader :CatalogItem, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Plan, :Subscription, :Task, :TaxRate, :Transaction
47
53
 
48
54
  def initialize(api_key, sandbox=false, sso_key=false)
49
55
  @api_key = api_key
@@ -53,14 +59,18 @@ module Invoiced
53
59
 
54
60
  # Object endpoints
55
61
  @CatalogItem = Invoiced::CatalogItem.new(self)
62
+ @Coupon = Invoiced::Coupon.new(self)
56
63
  @CreditNote = Invoiced::CreditNote.new(self)
57
64
  @Customer = Invoiced::Customer.new(self)
58
65
  @Estimate = Invoiced::Estimate.new(self)
59
66
  @Event = Invoiced::Event.new(self)
60
67
  @File = Invoiced::File.new(self)
61
68
  @Invoice = Invoiced::Invoice.new(self)
69
+ @Note = Invoiced::Note.new(self)
62
70
  @Plan = Invoiced::Plan.new(self)
63
71
  @Subscription = Invoiced::Subscription.new(self)
72
+ @Task = Invoiced::Task.new(self)
73
+ @TaxRate = Invoiced::TaxRate.new(self)
64
74
  @Transaction = Invoiced::Transaction.new(self)
65
75
  end
66
76
 
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
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)
88
+ end
89
+ end
90
+ end
@@ -122,5 +122,19 @@ module Invoiced
122
122
  assert_instance_of(Invoiced::List, metadata)
123
123
  assert_equal(10, metadata.total_count)
124
124
  end
125
+
126
+ should "void a credit note" do
127
+ mockResponse = mock('RestClient::Response')
128
+ mockResponse.stubs(:code).returns(200)
129
+ mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
130
+ mockResponse.stubs(:headers).returns({})
131
+
132
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
133
+
134
+ credit_note = CreditNote.new(@client, 123)
135
+ assert_true(credit_note.void)
136
+
137
+ assert_equal(credit_note.status, 'voided')
138
+ end
125
139
  end
126
140
  end
@@ -87,7 +87,7 @@ module Invoiced
87
87
  assert_true(customer.delete)
88
88
  end
89
89
 
90
- should "send an account statement" do
90
+ should "send an account statement by email" do
91
91
  mockResponse = mock('RestClient::Response')
92
92
  mockResponse.stubs(:code).returns(201)
93
93
  mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
@@ -104,6 +104,40 @@ module Invoiced
104
104
  assert_equal(4567, emails[0].id)
105
105
  end
106
106
 
107
+ should "send an account statement by text message" do
108
+ mockResponse = mock('RestClient::Response')
109
+ mockResponse.stubs(:code).returns(201)
110
+ mockResponse.stubs(:body).returns('[{"id":5678,"state":"sent"}]')
111
+ mockResponse.stubs(:headers).returns({})
112
+
113
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
114
+
115
+ customer = Customer.new(@client, 123)
116
+ text_messages = customer.send_statement_sms(:type => "open_item", :message => "example")
117
+
118
+ assert_instance_of(Array, text_messages)
119
+ assert_equal(1, text_messages.length)
120
+ assert_instance_of(Invoiced::TextMessage, text_messages[0])
121
+ assert_equal(5678, text_messages[0].id)
122
+ end
123
+
124
+ should "send an account statement by letter" do
125
+ mockResponse = mock('RestClient::Response')
126
+ mockResponse.stubs(:code).returns(201)
127
+ mockResponse.stubs(:body).returns('[{"id":6789,"state":"queued"}]')
128
+ mockResponse.stubs(:headers).returns({})
129
+
130
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
131
+
132
+ customer = Customer.new(@client, 123)
133
+ letters = customer.send_statement_letter(:type => "open_item")
134
+
135
+ assert_instance_of(Array, letters)
136
+ assert_equal(1, letters.length)
137
+ assert_instance_of(Invoiced::Letter, letters[0])
138
+ assert_equal(6789, letters[0].id)
139
+ end
140
+
107
141
  should "retrieve a customer's balance" do
108
142
  mockResponse = mock('RestClient::Response')
109
143
  mockResponse.stubs(:code).returns(200)
@@ -141,7 +175,7 @@ module Invoiced
141
175
  assert_equal('/customers/456/contacts/123', contact.endpoint())
142
176
  end
143
177
 
144
- should "list all of the customer's contact" do
178
+ should "list all of the customer's contacts" do
145
179
  mockResponse = mock('RestClient::Response')
146
180
  mockResponse.stubs(:code).returns(200)
147
181
  mockResponse.stubs(:body).returns('[{"id":123,"name":"Nancy"}]')
@@ -246,5 +280,40 @@ module Invoiced
246
280
  assert_instance_of(Invoiced::Invoice, invoice)
247
281
  assert_equal(4567, invoice.id)
248
282
  end
283
+
284
+ should "list all the customer's notes" do
285
+ mockResponse = mock('RestClient::Response')
286
+ mockResponse.stubs(:code).returns(200)
287
+ mockResponse.stubs(:body).returns('[{"id":1212,"notes":"example"}]')
288
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/customers/123/notes?per_page=25&page=1>; rel="last"')
289
+
290
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
291
+
292
+ customer = Customer.new(@client, 123)
293
+ notes, metadata = customer.list_notes.list
294
+
295
+ assert_instance_of(Array, notes)
296
+ assert_equal(1, notes.length)
297
+ assert_equal(1212, notes[0].id)
298
+ assert_equal('/customers/123/notes/1212', notes[0].endpoint())
299
+
300
+ assert_instance_of(Invoiced::List, metadata)
301
+ assert_equal(15, metadata.total_count)
302
+ end
303
+
304
+ should "create a consolidated invoice" do
305
+ mockResponse = mock('RestClient::Response')
306
+ mockResponse.stubs(:code).returns(201)
307
+ mockResponse.stubs(:body).returns('{"id": 999,"total":1000}')
308
+ mockResponse.stubs(:headers).returns({})
309
+
310
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
311
+
312
+ customer = Customer.new(@client, 123)
313
+ invoice = customer.consolidate_invoices
314
+
315
+ assert_instance_of(Invoiced::Invoice, invoice)
316
+ assert_equal(invoice.id, 999)
317
+ end
249
318
  end
250
319
  end
@@ -137,5 +137,19 @@ module Invoiced
137
137
  assert_instance_of(Invoiced::List, metadata)
138
138
  assert_equal(10, metadata.total_count)
139
139
  end
140
+
141
+ should "void an estimate" do
142
+ mockResponse = mock('RestClient::Response')
143
+ mockResponse.stubs(:code).returns(200)
144
+ mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
145
+ mockResponse.stubs(:headers).returns({})
146
+
147
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
148
+
149
+ estimate = Estimate.new(@client, 123)
150
+ assert_true(estimate.void)
151
+
152
+ assert_equal(estimate.status, 'voided')
153
+ end
140
154
  end
141
155
  end
@@ -87,7 +87,7 @@ module Invoiced
87
87
  assert_true(invoice.delete)
88
88
  end
89
89
 
90
- should "send an invoice" do
90
+ should "send an invoice by email" do
91
91
  mockResponse = mock('RestClient::Response')
92
92
  mockResponse.stubs(:code).returns(201)
93
93
  mockResponse.stubs(:body).returns('[{"id":4567,"email":"test@example.com"}]')
@@ -104,6 +104,40 @@ module Invoiced
104
104
  assert_equal(4567, emails[0].id)
105
105
  end
106
106
 
107
+ should "send an invoice by text message" do
108
+ mockResponse = mock('RestClient::Response')
109
+ mockResponse.stubs(:code).returns(201)
110
+ mockResponse.stubs(:body).returns('[{"id":5678,"state":"sent"}]')
111
+ mockResponse.stubs(:headers).returns({})
112
+
113
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
114
+
115
+ invoice = Invoice.new(@client, 1234)
116
+ text_messages = invoice.send_sms(:message => "example")
117
+
118
+ assert_instance_of(Array, text_messages)
119
+ assert_equal(1, text_messages.length)
120
+ assert_instance_of(Invoiced::TextMessage, text_messages[0])
121
+ assert_equal(5678, text_messages[0].id)
122
+ end
123
+
124
+ should "send an invoice by letter" do
125
+ mockResponse = mock('RestClient::Response')
126
+ mockResponse.stubs(:code).returns(201)
127
+ mockResponse.stubs(:body).returns('[{"id":6789,"state":"queued"}]')
128
+ mockResponse.stubs(:headers).returns({})
129
+
130
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
131
+
132
+ invoice = Invoice.new(@client, 1234)
133
+ letters = invoice.send_letter
134
+
135
+ assert_instance_of(Array, letters)
136
+ assert_equal(1, letters.length)
137
+ assert_instance_of(Invoiced::Letter, letters[0])
138
+ assert_equal(6789, letters[0].id)
139
+ end
140
+
107
141
  should "pay an invoice" do
108
142
  mockResponse = mock('RestClient::Response')
109
143
  mockResponse.stubs(:code).returns(200)
@@ -170,5 +204,39 @@ module Invoiced
170
204
  assert_equal("active", payment_plan.status)
171
205
  assert_equal('/invoices/456/payment_plan', payment_plan.endpoint())
172
206
  end
207
+
208
+ should "list all notes associated with invoice" do
209
+ mockResponse = mock('RestClient::Response')
210
+ mockResponse.stubs(:code).returns(200)
211
+ mockResponse.stubs(:body).returns('[{"id":1212,"notes":"example"}]')
212
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/invoices/1234/notes?per_page=25&page=1>; rel="last"')
213
+
214
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
215
+
216
+ invoice = Invoice.new(@client, 1234)
217
+ notes, metadata = invoice.notes.list
218
+
219
+ assert_instance_of(Array, notes)
220
+ assert_equal(1, notes.length)
221
+ assert_equal(1212, notes[0].id)
222
+ assert_equal('/invoices/1234/notes/1212', notes[0].endpoint())
223
+
224
+ assert_instance_of(Invoiced::List, metadata)
225
+ assert_equal(15, metadata.total_count)
226
+ end
227
+
228
+ should "void an invoice" do
229
+ mockResponse = mock('RestClient::Response')
230
+ mockResponse.stubs(:code).returns(200)
231
+ mockResponse.stubs(:body).returns('{"id":123,"status":"voided"}')
232
+ mockResponse.stubs(:headers).returns({})
233
+
234
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
235
+
236
+ invoice = Invoice.new(@client, 123)
237
+ assert_true(invoice.void)
238
+
239
+ assert_equal(invoice.status, 'voided')
240
+ end
173
241
  end
174
242
  end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class NoteTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ note = Note.new(@client, "test")
7
+ assert_equal('/notes/test', note.endpoint())
8
+ end
9
+
10
+ should "create a note" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ note = @client.Note.create({:notes => "Test Note"})
19
+
20
+ assert_instance_of(Invoiced::Note, note)
21
+ assert_equal("test", note.id)
22
+ assert_equal('Test Note', note.notes)
23
+ end
24
+
25
+ should "retrieve a note" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"Test Note"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ note = @client.Note.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::Note, note)
36
+ assert_equal("test", note.id)
37
+ assert_equal('Test Note', note.notes)
38
+ end
39
+
40
+ should "not update a note when no params" do
41
+ note = Note.new(@client, "test")
42
+ assert_false(note.save)
43
+ end
44
+
45
+ should "update a note" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","notes":"new contents"}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ note = Note.new(@client, "test")
54
+ note.notes = "new contents"
55
+ assert_true(note.save)
56
+
57
+ assert_equal(note.notes, 'new contents')
58
+ end
59
+
60
+ should "list all notes" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","notes":"Test Note"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/notes?per_page=25&page=1>; rel="self", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="first", <https://api.invoiced.com/notes?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ notes, metadata = @client.Note.list
69
+
70
+ assert_instance_of(Array, notes)
71
+ assert_equal(1, notes.length)
72
+ assert_equal("test", notes[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a note" 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
+ note = Note.new(@client, "test")
87
+ assert_true(note.delete)
88
+ end
89
+ end
90
+ end
@@ -87,5 +87,18 @@ module Invoiced
87
87
  assert_true(subscription.cancel)
88
88
  assert_equal("canceled", subscription.status)
89
89
  end
90
+
91
+ should "preview a subscription" do
92
+ mockResponse = mock('RestClient::Response')
93
+ mockResponse.stubs(:code).returns(200)
94
+ mockResponse.stubs(:body).returns('{"first_invoice": {"id": false}, "mrr": 9}')
95
+ mockResponse.stubs(:headers).returns({})
96
+
97
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
98
+
99
+ subscription = Subscription.new(@client, 123)
100
+ preview = subscription.preview(:customer => 1234, :plan => "enterprise")
101
+ assert_equal(preview[:first_invoice], {:id=>false})
102
+ end
90
103
  end
91
104
  end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class TaskTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ task = Task.new(@client, "test")
7
+ assert_equal('/tasks/test', task.endpoint())
8
+ end
9
+
10
+ should "create a task" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Task"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ task = @client.Task.create({:name => "Test Task"})
19
+
20
+ assert_instance_of(Invoiced::Task, task)
21
+ assert_equal("test", task.id)
22
+ assert_equal('Test Task', task.name)
23
+ end
24
+
25
+ should "retrieve a task" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test Task"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ task = @client.Task.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::Task, task)
36
+ assert_equal("test", task.id)
37
+ assert_equal('Test Task', task.name)
38
+ end
39
+
40
+ should "not update a task when no params" do
41
+ task = Task.new(@client, "test")
42
+ assert_false(task.save)
43
+ end
44
+
45
+ should "update a task" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","name":"new contents"}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ task = Task.new(@client, "test")
54
+ task.name = "new contents"
55
+ assert_true(task.save)
56
+
57
+ assert_equal(task.name, 'new contents')
58
+ end
59
+
60
+ should "list all tasks" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","name":"Test Task"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/tasks?per_page=25&page=1>; rel="self", <https://api.invoiced.com/tasks?per_page=25&page=1>; rel="first", <https://api.invoiced.com/tasks?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ tasks, metadata = @client.Task.list
69
+
70
+ assert_instance_of(Array, tasks)
71
+ assert_equal(1, tasks.length)
72
+ assert_equal("test", tasks[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a task" 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
+ task = Task.new(@client, "test")
87
+ assert_true(task.delete)
88
+ end
89
+ end
90
+ end
@@ -0,0 +1,90 @@
1
+ require File.expand_path('../../test_helper', __FILE__)
2
+
3
+ module Invoiced
4
+ class TaxRateTest < Test::Unit::TestCase
5
+ should "return the api endpoint" do
6
+ tax_rate = TaxRate.new(@client, "test")
7
+ assert_equal('/tax_rates/test', tax_rate.endpoint())
8
+ end
9
+
10
+ should "create a tax rate" do
11
+ mockResponse = mock('RestClient::Response')
12
+ mockResponse.stubs(:code).returns(201)
13
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test TaxRate"}')
14
+ mockResponse.stubs(:headers).returns({})
15
+
16
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
17
+
18
+ tax_rate = @client.TaxRate.create({:name => "Test TaxRate"})
19
+
20
+ assert_instance_of(Invoiced::TaxRate, tax_rate)
21
+ assert_equal("test", tax_rate.id)
22
+ assert_equal('Test TaxRate', tax_rate.name)
23
+ end
24
+
25
+ should "retrieve a tax rate" do
26
+ mockResponse = mock('RestClient::Response')
27
+ mockResponse.stubs(:code).returns(200)
28
+ mockResponse.stubs(:body).returns('{"id":"test","name":"Test TaxRate"}')
29
+ mockResponse.stubs(:headers).returns({})
30
+
31
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
32
+
33
+ tax_rate = @client.TaxRate.retrieve("test")
34
+
35
+ assert_instance_of(Invoiced::TaxRate, tax_rate)
36
+ assert_equal("test", tax_rate.id)
37
+ assert_equal('Test TaxRate', tax_rate.name)
38
+ end
39
+
40
+ should "not update a tax rate when no params" do
41
+ tax_rate = TaxRate.new(@client, "test")
42
+ assert_false(tax_rate.save)
43
+ end
44
+
45
+ should "update a tax rate" do
46
+ mockResponse = mock('RestClient::Response')
47
+ mockResponse.stubs(:code).returns(200)
48
+ mockResponse.stubs(:body).returns('{"id":"test","name":"new contents"}')
49
+ mockResponse.stubs(:headers).returns({})
50
+
51
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
52
+
53
+ tax_rate = TaxRate.new(@client, "test")
54
+ tax_rate.name = "new contents"
55
+ assert_true(tax_rate.save)
56
+
57
+ assert_equal(tax_rate.name, 'new contents')
58
+ end
59
+
60
+ should "list all tax rates" do
61
+ mockResponse = mock('RestClient::Response')
62
+ mockResponse.stubs(:code).returns(200)
63
+ mockResponse.stubs(:body).returns('[{"id":"test","name":"Test TaxRate"}]')
64
+ mockResponse.stubs(:headers).returns(:x_total_count => 15, :link => '<https://api.invoiced.com/tax_rates?per_page=25&page=1>; rel="self", <https://api.invoiced.com/tax_rates?per_page=25&page=1>; rel="first", <https://api.invoiced.com/tax_rates?per_page=25&page=1>; rel="last"')
65
+
66
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
67
+
68
+ tax_rates, metadata = @client.TaxRate.list
69
+
70
+ assert_instance_of(Array, tax_rates)
71
+ assert_equal(1, tax_rates.length)
72
+ assert_equal("test", tax_rates[0].id)
73
+
74
+ assert_instance_of(Invoiced::List, metadata)
75
+ assert_equal(15, metadata.total_count)
76
+ end
77
+
78
+ should "delete a tax rate" 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
+ tax_rate = TaxRate.new(@client, "test")
87
+ assert_true(tax_rate.delete)
88
+ end
89
+ end
90
+ end
@@ -118,5 +118,20 @@ module Invoiced
118
118
  assert_instance_of(Invoiced::Transaction, refund)
119
119
  assert_equal(456, refund.id)
120
120
  end
121
+
122
+ should "initiate a charge" do
123
+ mockResponse = mock('RestClient::Response')
124
+ mockResponse.stubs(:code).returns(201)
125
+ mockResponse.stubs(:body).returns('{"id":"a1b2c3","amount":100,"object":"card"}')
126
+ mockResponse.stubs(:headers).returns({})
127
+
128
+ RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
129
+
130
+ transaction = Transaction.new(@client, 1234)
131
+ charge = transaction.initiate_charge(:amount => 100, :payment_source_type => "card")
132
+
133
+ assert_instance_of(Invoiced::Transaction, charge)
134
+ assert_equal(charge.id, "a1b2c3")
135
+ end
121
136
  end
122
137
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invoiced
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jared King
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-11 00:00:00.000000000 Z
11
+ date: 2019-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rest-client
@@ -55,6 +55,7 @@ files:
55
55
  - lib/invoiced/attachment.rb
56
56
  - lib/invoiced/catalog_item.rb
57
57
  - lib/invoiced/contact.rb
58
+ - lib/invoiced/coupon.rb
58
59
  - lib/invoiced/credit_note.rb
59
60
  - lib/invoiced/customer.rb
60
61
  - lib/invoiced/email.rb
@@ -68,8 +69,10 @@ files:
68
69
  - lib/invoiced/event.rb
69
70
  - lib/invoiced/file.rb
70
71
  - lib/invoiced/invoice.rb
72
+ - lib/invoiced/letter.rb
71
73
  - lib/invoiced/line_item.rb
72
74
  - lib/invoiced/list.rb
75
+ - lib/invoiced/note.rb
73
76
  - lib/invoiced/object.rb
74
77
  - lib/invoiced/operations/create.rb
75
78
  - lib/invoiced/operations/delete.rb
@@ -78,11 +81,15 @@ files:
78
81
  - lib/invoiced/payment_plan.rb
79
82
  - lib/invoiced/plan.rb
80
83
  - lib/invoiced/subscription.rb
84
+ - lib/invoiced/task.rb
85
+ - lib/invoiced/tax_rate.rb
86
+ - lib/invoiced/text_message.rb
81
87
  - lib/invoiced/transaction.rb
82
88
  - lib/invoiced/util.rb
83
89
  - lib/invoiced/version.rb
84
90
  - test/invoiced/catalog_item_test.rb
85
91
  - test/invoiced/contact_test.rb
92
+ - test/invoiced/coupon_test.rb
86
93
  - test/invoiced/credit_note_test.rb
87
94
  - test/invoiced/customer_test.rb
88
95
  - test/invoiced/error_test.rb
@@ -92,10 +99,13 @@ files:
92
99
  - test/invoiced/invoice_test.rb
93
100
  - test/invoiced/invoiced_test.rb
94
101
  - test/invoiced/line_item_test.rb
102
+ - test/invoiced/note_test.rb
95
103
  - test/invoiced/object_test.rb
96
104
  - test/invoiced/payment_plan_test.rb
97
105
  - test/invoiced/plan_test.rb
98
106
  - test/invoiced/subscription_test.rb
107
+ - test/invoiced/task_test.rb
108
+ - test/invoiced/tax_rate_test.rb
99
109
  - test/invoiced/transaction_test.rb
100
110
  - test/invoiced/util_test.rb
101
111
  - test/test_helper.rb
@@ -118,14 +128,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
118
128
  - !ruby/object:Gem::Version
119
129
  version: '0'
120
130
  requirements: []
121
- rubyforge_project:
122
- rubygems_version: 2.2.2
131
+ rubygems_version: 3.0.6
123
132
  signing_key:
124
133
  specification_version: 4
125
134
  summary: Ruby client library for the Invoiced API
126
135
  test_files:
127
136
  - test/invoiced/catalog_item_test.rb
128
137
  - test/invoiced/contact_test.rb
138
+ - test/invoiced/coupon_test.rb
129
139
  - test/invoiced/credit_note_test.rb
130
140
  - test/invoiced/customer_test.rb
131
141
  - test/invoiced/error_test.rb
@@ -135,10 +145,13 @@ test_files:
135
145
  - test/invoiced/invoice_test.rb
136
146
  - test/invoiced/invoiced_test.rb
137
147
  - test/invoiced/line_item_test.rb
148
+ - test/invoiced/note_test.rb
138
149
  - test/invoiced/object_test.rb
139
150
  - test/invoiced/payment_plan_test.rb
140
151
  - test/invoiced/plan_test.rb
141
152
  - test/invoiced/subscription_test.rb
153
+ - test/invoiced/task_test.rb
154
+ - test/invoiced/tax_rate_test.rb
142
155
  - test/invoiced/transaction_test.rb
143
156
  - test/invoiced/util_test.rb
144
157
  - test/test_helper.rb