invoiced 0.13.0 → 1.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 +5 -5
  2. data/.gitignore +3 -1
  3. data/.travis.yml +3 -1
  4. data/Gemfile +1 -2
  5. data/README.md +14 -6
  6. data/invoiced.gemspec +2 -2
  7. data/lib/invoiced.rb +25 -4
  8. data/lib/invoiced/bank_account.rb +6 -0
  9. data/lib/invoiced/card.rb +6 -0
  10. data/lib/invoiced/charge.rb +12 -0
  11. data/lib/invoiced/{catalog_item.rb → coupon.rb} +2 -2
  12. data/lib/invoiced/credit_note.rb +8 -0
  13. data/lib/invoiced/customer.rb +34 -0
  14. data/lib/invoiced/estimate.rb +8 -0
  15. data/lib/invoiced/invoice.rb +31 -1
  16. data/lib/invoiced/item.rb +10 -0
  17. data/lib/invoiced/letter.rb +5 -0
  18. data/lib/invoiced/note.rb +10 -0
  19. data/lib/invoiced/object.rb +2 -2
  20. data/lib/invoiced/operations/create.rb +1 -1
  21. data/lib/invoiced/payment.rb +18 -0
  22. data/lib/invoiced/payment_source.rb +8 -0
  23. data/lib/invoiced/payment_source_object.rb +5 -0
  24. data/lib/invoiced/refund.rb +11 -0
  25. data/lib/invoiced/subscription.rb +6 -0
  26. data/lib/invoiced/task.rb +10 -0
  27. data/lib/invoiced/tax_rate.rb +10 -0
  28. data/lib/invoiced/text_message.rb +5 -0
  29. data/lib/invoiced/transaction.rb +6 -0
  30. data/lib/invoiced/util.rb +13 -1
  31. data/lib/invoiced/version.rb +1 -1
  32. data/test/invoiced/charge_test.rb +25 -0
  33. data/test/invoiced/{catalog_item_test.rb → coupon_test.rb} +33 -33
  34. data/test/invoiced/credit_note_test.rb +14 -0
  35. data/test/invoiced/customer_test.rb +101 -2
  36. data/test/invoiced/estimate_test.rb +14 -0
  37. data/test/invoiced/invoice_test.rb +69 -1
  38. data/test/invoiced/invoiced_test.rb +1 -2
  39. data/test/invoiced/item_test.rb +90 -0
  40. data/test/invoiced/note_test.rb +90 -0
  41. data/test/invoiced/payment_source_test.rb +57 -0
  42. data/test/invoiced/payment_test.rb +107 -0
  43. data/test/invoiced/refund_test.rb +25 -0
  44. data/test/invoiced/subscription_test.rb +13 -0
  45. data/test/invoiced/task_test.rb +90 -0
  46. data/test/invoiced/tax_rate_test.rb +90 -0
  47. data/test/invoiced/transaction_test.rb +15 -0
  48. metadata +38 -10
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: af3c9c33d3ab2a41846eec239e659b6a83567f1e
4
- data.tar.gz: c27763abfd2ac362595eb44c9ff4afd067485346
2
+ SHA256:
3
+ metadata.gz: 96fee7c8ec29ed8496d56e2ad01040962c4e793e03d8746cd1bb33dc9d455310
4
+ data.tar.gz: 24c4ac4cf3671312b13da58e7ffb0798041ff50572d06e49ccbab047f2fe7130
5
5
  SHA512:
6
- metadata.gz: df10f784d4468a435fab99638180f213c30325cc0f40a695809b306bf3ebad5846804eb5a47d1f9a865ddc77ececf0694f634c28ff6fea45b1d102425a8aed7e
7
- data.tar.gz: 5a0e7161ac5632520f9cf7c39e4f91ab2a2d39f47a4e240c8144e314fc22dc8a81839864da14a2bcc8e3b8f28d1b48101fe3e959de35eeec79673d0e19c95267
6
+ metadata.gz: f8a1fbde18532af461b0051de5a9a35beeefa4e6b9826cbbc65d8ce4ac73b91ce6d40d81c7b3d3fd6d68a989c74441cd0ee45d9cd1f8d9f1c7e50095a4666cd1
7
+ data.tar.gz: 79c75b2a9c9654ecf61a520aaa1e1bc3c2802d189b540238dd4556108c00255e0d88155f2d96200c11a8ddb870b4ee16be2e8fb0cd1b34e6e80597b7661b357d
data/.gitignore CHANGED
@@ -1,4 +1,6 @@
1
1
  Gemfile.lock
2
2
  example.rb
3
3
  /invoiced-*.gem
4
- /coverage
4
+ /coverage
5
+ .DS_Store
6
+ .idea/
@@ -1,11 +1,13 @@
1
1
  language: ruby
2
2
 
3
3
  rvm:
4
- - 2.0
5
4
  - 2.1
6
5
  - 2.2
7
6
  - 2.3
8
7
  - 2.4
8
+ - 2.5
9
+ - 2.6
10
+ - 2.7
9
11
 
10
12
  sudo: false
11
13
 
data/Gemfile CHANGED
@@ -2,13 +2,12 @@ source "https://rubygems.org"
2
2
  gemspec
3
3
 
4
4
  gem 'rest-client', '~> 2.0.0'
5
- gem 'jwt', '~> 2.0.0'
5
+ gem 'jwt', '~> 2.0'
6
6
 
7
7
  gem 'mocha', '~> 0.13.2', :require => false, :group => :test
8
8
  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
- gem 'activesupport', '~> 4.2.9', :require => false, :group => :test
12
11
  gem 'coveralls', :require => false, :group => :test
13
12
  gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
14
13
  gem 'simplecov-console', '~> 0.3.1', :require => false, :group => :test
data/README.md CHANGED
@@ -3,8 +3,9 @@ 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.org/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.org/Invoiced/invoiced-ruby)
6
+ [![Build Status](https://travis-ci.com/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.com/Invoiced/invoiced-ruby)
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
+ [![Gem Version](https://badge.fury.io/rb/invoiced.svg)](https://badge.fury.io/rb/invoiced)
8
9
 
9
10
  ## Installing
10
11
 
@@ -24,8 +25,9 @@ gem 'invoiced'
24
25
 
25
26
  ## Requirements
26
27
 
27
- - Ruby 2.0+
28
- - rest_client gem
28
+ - Ruby 2.1+
29
+ - `rest_client` gem
30
+ - `jwt` gem
29
31
 
30
32
  ## Usage
31
33
 
@@ -43,10 +45,16 @@ Then, API calls can be made like this:
43
45
  invoice = invoiced.Invoice.retrieve("{INVOICE_ID}")
44
46
 
45
47
  # mark as paid
46
- transaction = invoiced.Transaction.create(
47
- :invoice => invoice.id,
48
+ payment = invoiced.Payment.create(
48
49
  :amount => invoice.balance,
49
- :method => "check")
50
+ :method => "check",
51
+ :applied_to => [
52
+ {
53
+ :type => "invoice",
54
+ :invoice => invoice.id,
55
+ :amount => invoice.balance
56
+ }
57
+ ])
50
58
  ```
51
59
 
52
60
  If you want to use the sandbox API instead then you must set the second argument on the client to `true` like this:
@@ -12,10 +12,10 @@ Gem::Specification.new do |s|
12
12
  s.email = 'support@invoiced.com'
13
13
  s.files = ["lib/invoiced.rb"]
14
14
  s.homepage = 'https://invoiced.com/docs/dev'
15
- s.required_ruby_version = '>= 2.0.0'
15
+ s.required_ruby_version = '>= 2.1.0'
16
16
 
17
17
  s.add_dependency('rest-client', '~> 2.0.0')
18
- s.add_dependency('jwt', '~> 2.0.0')
18
+ s.add_dependency('jwt', '~> 2.0')
19
19
 
20
20
  s.files = `git ls-files`.split("\n")
21
21
  s.test_files = `git ls-files -- test/*`.split("\n")
@@ -1,4 +1,5 @@
1
1
  require 'rest-client'
2
+ require 'jwt'
2
3
  require 'json'
3
4
  require 'base64'
4
5
 
@@ -17,9 +18,14 @@ require 'invoiced/operations/delete'
17
18
  require 'invoiced/operations/update'
18
19
 
19
20
  require 'invoiced/object'
21
+ require 'invoiced/payment_source_object'
20
22
  require 'invoiced/attachment'
21
- require 'invoiced/catalog_item'
23
+ require 'invoiced/bank_account'
24
+ require 'invoiced/card'
25
+ require 'invoiced/item'
26
+ require 'invoiced/charge'
22
27
  require 'invoiced/contact'
28
+ require 'invoiced/coupon'
23
29
  require 'invoiced/credit_note'
24
30
  require 'invoiced/customer'
25
31
  require 'invoiced/email'
@@ -27,10 +33,18 @@ require 'invoiced/estimate'
27
33
  require 'invoiced/event'
28
34
  require 'invoiced/file'
29
35
  require 'invoiced/invoice'
36
+ require 'invoiced/letter'
30
37
  require 'invoiced/line_item'
38
+ require 'invoiced/note'
39
+ require 'invoiced/payment'
31
40
  require 'invoiced/payment_plan'
41
+ require 'invoiced/payment_source'
32
42
  require 'invoiced/plan'
43
+ require 'invoiced/refund'
33
44
  require 'invoiced/subscription'
45
+ require 'invoiced/task'
46
+ require 'invoiced/tax_rate'
47
+ require 'invoiced/text_message'
34
48
  require 'invoiced/transaction'
35
49
 
36
50
  module Invoiced
@@ -42,7 +56,7 @@ module Invoiced
42
56
  ReadTimeout = 80
43
57
 
44
58
  attr_reader :api_key, :api_url, :sandbox, :sso_key
45
- attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
59
+ attr_reader :Item, :Charge, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate, :Transaction
46
60
 
47
61
  def initialize(api_key, sandbox=false, sso_key=false)
48
62
  @api_key = api_key
@@ -51,15 +65,22 @@ module Invoiced
51
65
  @sso_key = sso_key
52
66
 
53
67
  # Object endpoints
54
- @CatalogItem = Invoiced::CatalogItem.new(self)
68
+ @Item = Invoiced::Item.new(self)
69
+ @Charge = Invoiced::Charge.new(self)
70
+ @Coupon = Invoiced::Coupon.new(self)
55
71
  @CreditNote = Invoiced::CreditNote.new(self)
56
72
  @Customer = Invoiced::Customer.new(self)
57
73
  @Estimate = Invoiced::Estimate.new(self)
58
74
  @Event = Invoiced::Event.new(self)
59
75
  @File = Invoiced::File.new(self)
60
76
  @Invoice = Invoiced::Invoice.new(self)
77
+ @Note = Invoiced::Note.new(self)
78
+ @Payment = Invoiced::Payment.new(self)
61
79
  @Plan = Invoiced::Plan.new(self)
80
+ @Refund = Invoiced::Refund.new(self)
62
81
  @Subscription = Invoiced::Subscription.new(self)
82
+ @Task = Invoiced::Task.new(self)
83
+ @TaxRate = Invoiced::TaxRate.new(self)
63
84
  @Transaction = Invoiced::Transaction.new(self)
64
85
  end
65
86
 
@@ -201,4 +222,4 @@ module Invoiced
201
222
  ApiError.new("API Error #{code} - #{body}", code)
202
223
  end
203
224
  end
204
- end
225
+ end
@@ -0,0 +1,6 @@
1
+ module Invoiced
2
+ class BankAccount < PaymentSourceObject
3
+
4
+ OBJECT_NAME = 'bank_account'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ module Invoiced
2
+ class Card < PaymentSourceObject
3
+
4
+ OBJECT_NAME = 'card'
5
+ end
6
+ end
@@ -0,0 +1,12 @@
1
+ module Invoiced
2
+ class Charge < Object
3
+ OBJECT_NAME = 'charge'
4
+
5
+ def create(body={}, opts={})
6
+ response = @client.request(:post, endpoint(), body, opts)
7
+
8
+ payment = Payment.new(@client)
9
+ Util.convert_to_object(payment, response[:body])
10
+ end
11
+ end
12
+ end
@@ -1,10 +1,10 @@
1
1
  module Invoiced
2
- class CatalogItem < Object
2
+ class Coupon < Object
3
3
  include Invoiced::Operations::List
4
4
  include Invoiced::Operations::Create
5
5
  include Invoiced::Operations::Update
6
6
  include Invoiced::Operations::Delete
7
7
 
8
- OBJECT_NAME = 'catalog_item'
8
+ OBJECT_NAME = 'coupon'
9
9
  end
10
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
 
@@ -26,11 +42,21 @@ module Invoiced
26
42
  contact.set_endpoint_base(self.endpoint())
27
43
  end
28
44
 
45
+ def payment_sources()
46
+ source = PaymentSource.new(@client)
47
+ source.set_endpoint_base(self.endpoint())
48
+ end
49
+
29
50
  def line_items()
30
51
  line = LineItem.new(@client)
31
52
  line.set_endpoint_base(self.endpoint())
32
53
  end
33
54
 
55
+ def list_notes()
56
+ note = Note.new(@client)
57
+ note.set_endpoint_base(self.endpoint())
58
+ end
59
+
34
60
  def invoice(params={}, opts={})
35
61
  response = @client.request(:post, "#{self.endpoint()}/invoices", params, opts)
36
62
 
@@ -38,5 +64,13 @@ module Invoiced
38
64
  invoice = Invoice.new(@client)
39
65
  Util.convert_to_object(invoice, response[:body])
40
66
  end
67
+
68
+ def consolidate_invoices(params={})
69
+ response = @client.request(:post, "#{self.endpoint()}/consolidate_invoices", params)
70
+
71
+ # build invoice object
72
+ invoice = Invoice.new(@client)
73
+ Util.convert_to_object(invoice, response[:body])
74
+ end
41
75
  end
42
76
  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,10 @@
1
+ module Invoiced
2
+ class Item < 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 = 'item'
9
+ end
10
+ 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
@@ -46,7 +46,7 @@ module Invoiced
46
46
  raise ArgumentError.new("Missing ID.")
47
47
  end
48
48
 
49
- response = @client.request(:get, "#{self.endpoint()}/#{id}", params)
49
+ response = @client.request(:get, "#{endpoint()}/#{id}", params)
50
50
 
51
51
  Util.convert_to_object(self, response[:body])
52
52
  end
@@ -57,7 +57,7 @@ module Invoiced
57
57
 
58
58
  def inspect
59
59
  id_string = (!@id.nil?) ? " id=#{@id}" : ""
60
- "#<#{self.class}:0x#{self.object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
60
+ "#<#{self.class}:0x#{object_id.to_s(16)}#{id_string}> JSON: " + JSON.pretty_generate(@values)
61
61
  end
62
62
 
63
63
  def refresh_from(values)
@@ -2,7 +2,7 @@ module Invoiced
2
2
  module Operations
3
3
  module Create
4
4
  def create(body={}, opts={})
5
- response = @client.request(:post, self.endpoint(), body, opts)
5
+ response = @client.request(:post, endpoint(), body, opts)
6
6
 
7
7
  Util.convert_to_object(self, response[:body])
8
8
  end
@@ -0,0 +1,18 @@
1
+ module Invoiced
2
+ class Payment < 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 = 'payment'
9
+
10
+ def send(params={}, opts={})
11
+ response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
12
+
13
+ # build email objects
14
+ email = Email.new(@client)
15
+ Util.build_objects(email, response[:body])
16
+ end
17
+ end
18
+ end