invoiced 0.12.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +3 -1
- data/.travis.yml +5 -1
- data/Gemfile +6 -2
- data/README.md +4 -2
- data/invoiced.gemspec +2 -8
- data/lib/invoiced.rb +43 -5
- data/lib/invoiced/attachment.rb +1 -0
- data/lib/invoiced/bank_account.rb +6 -0
- data/lib/invoiced/card.rb +6 -0
- data/lib/invoiced/catalog_item.rb +2 -0
- data/lib/invoiced/charge.rb +12 -0
- data/lib/invoiced/contact.rb +2 -0
- data/lib/invoiced/coupon.rb +10 -0
- data/lib/invoiced/credit_note.rb +10 -0
- data/lib/invoiced/customer.rb +36 -0
- data/lib/invoiced/email.rb +1 -0
- data/lib/invoiced/estimate.rb +10 -0
- data/lib/invoiced/event.rb +2 -0
- data/lib/invoiced/file.rb +2 -0
- data/lib/invoiced/invoice.rb +33 -1
- data/lib/invoiced/letter.rb +5 -0
- data/lib/invoiced/line_item.rb +2 -0
- data/lib/invoiced/note.rb +10 -0
- data/lib/invoiced/object.rb +11 -5
- data/lib/invoiced/operations/create.rb +1 -1
- data/lib/invoiced/payment.rb +18 -0
- data/lib/invoiced/payment_plan.rb +2 -0
- data/lib/invoiced/payment_source.rb +8 -0
- data/lib/invoiced/payment_source_object.rb +5 -0
- data/lib/invoiced/plan.rb +2 -0
- data/lib/invoiced/refund.rb +11 -0
- data/lib/invoiced/subscription.rb +8 -0
- data/lib/invoiced/task.rb +10 -0
- data/lib/invoiced/tax_rate.rb +10 -0
- data/lib/invoiced/text_message.rb +5 -0
- data/lib/invoiced/transaction.rb +8 -0
- data/lib/invoiced/util.rb +13 -1
- data/lib/invoiced/version.rb +1 -1
- data/test/invoiced/charge_test.rb +25 -0
- data/test/invoiced/coupon_test.rb +90 -0
- data/test/invoiced/credit_note_test.rb +14 -0
- data/test/invoiced/customer_test.rb +101 -2
- data/test/invoiced/estimate_test.rb +14 -0
- data/test/invoiced/invoice_test.rb +69 -1
- data/test/invoiced/invoiced_test.rb +27 -1
- data/test/invoiced/note_test.rb +90 -0
- data/test/invoiced/payment_source_test.rb +57 -0
- data/test/invoiced/payment_test.rb +107 -0
- data/test/invoiced/refund_test.rb +25 -0
- data/test/invoiced/subscription_test.rb +13 -0
- data/test/invoiced/task_test.rb +90 -0
- data/test/invoiced/tax_rate_test.rb +90 -0
- data/test/invoiced/transaction_test.rb +15 -0
- metadata +36 -78
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3c9a2f8ec999dc38fc2d99a9a6c70ed9f908453399e7a1391b139f08d0016c58
|
4
|
+
data.tar.gz: bded9ce98e08adf08061d9411958f358c2a53622f1c6df96ddbdee4ea34c02b8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cce64c5c13a67dcfb8d1b693fa915e3927b9785a4f27c9a19dd72c0c36e9b97ad17b1159a0023994d73562e90d8cd0384f51704c890e8f2e849d9e8b9f1a3800
|
7
|
+
data.tar.gz: 9763afc75104c54d36b1a31cf603d9fd13d8a777b17f3d871cb59eadc8b80fa1e0ebfd2bdfd68de52110e27fd6a35c73a29c4f34fafc0b647386a6073bb17b91
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
source "https://rubygems.org"
|
2
2
|
gemspec
|
3
3
|
|
4
|
-
gem 'json', '~> 1.8.3'
|
5
4
|
gem 'rest-client', '~> 2.0.0'
|
6
|
-
gem '
|
5
|
+
gem 'jwt', '~> 2.0'
|
6
|
+
|
7
|
+
gem 'mocha', '~> 0.13.2', :require => false, :group => :test
|
8
|
+
gem 'shoulda', '~> 3.4.0', :require => false, :group => :test
|
9
|
+
gem 'test-unit', :require => false, :group => :test
|
10
|
+
gem 'rake', :require => false, :group => :test
|
7
11
|
gem 'coveralls', :require => false, :group => :test
|
8
12
|
gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
|
9
13
|
gem 'simplecov-console', '~> 0.3.1', :require => false, :group => :test
|
data/README.md
CHANGED
@@ -5,6 +5,7 @@ This repository contains the Ruby client library for the [Invoiced](https://invo
|
|
5
5
|
|
6
6
|
[![Build Status](https://travis-ci.org/Invoiced/invoiced-ruby.svg?branch=master)](https://travis-ci.org/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.
|
28
|
-
- rest_client
|
28
|
+
- Ruby 2.1+
|
29
|
+
- `rest_client` gem
|
30
|
+
- `jwt` gem
|
29
31
|
|
30
32
|
## Usage
|
31
33
|
|
data/invoiced.gemspec
CHANGED
@@ -12,16 +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.
|
15
|
+
s.required_ruby_version = '>= 2.1.0'
|
16
16
|
|
17
17
|
s.add_dependency('rest-client', '~> 2.0.0')
|
18
|
-
s.add_dependency('
|
19
|
-
s.add_dependency('activesupport', '~> 4.2.3')
|
20
|
-
|
21
|
-
s.add_development_dependency('mocha', '~> 0.13.2')
|
22
|
-
s.add_development_dependency('shoulda', '~> 3.4.0')
|
23
|
-
s.add_development_dependency('test-unit')
|
24
|
-
s.add_development_dependency('rake')
|
18
|
+
s.add_dependency('jwt', '~> 2.0')
|
25
19
|
|
26
20
|
s.files = `git ls-files`.split("\n")
|
27
21
|
s.test_files = `git ls-files -- test/*`.split("\n")
|
data/lib/invoiced.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'rest-client'
|
2
|
+
require 'jwt'
|
2
3
|
require 'json'
|
3
4
|
require 'base64'
|
4
|
-
require 'active_support/inflector'
|
5
5
|
|
6
6
|
require 'invoiced/version'
|
7
7
|
require 'invoiced/util'
|
@@ -18,9 +18,14 @@ require 'invoiced/operations/delete'
|
|
18
18
|
require 'invoiced/operations/update'
|
19
19
|
|
20
20
|
require 'invoiced/object'
|
21
|
+
require 'invoiced/payment_source_object'
|
21
22
|
require 'invoiced/attachment'
|
23
|
+
require 'invoiced/bank_account'
|
24
|
+
require 'invoiced/card'
|
22
25
|
require 'invoiced/catalog_item'
|
26
|
+
require 'invoiced/charge'
|
23
27
|
require 'invoiced/contact'
|
28
|
+
require 'invoiced/coupon'
|
24
29
|
require 'invoiced/credit_note'
|
25
30
|
require 'invoiced/customer'
|
26
31
|
require 'invoiced/email'
|
@@ -28,10 +33,18 @@ require 'invoiced/estimate'
|
|
28
33
|
require 'invoiced/event'
|
29
34
|
require 'invoiced/file'
|
30
35
|
require 'invoiced/invoice'
|
36
|
+
require 'invoiced/letter'
|
31
37
|
require 'invoiced/line_item'
|
38
|
+
require 'invoiced/note'
|
39
|
+
require 'invoiced/payment'
|
32
40
|
require 'invoiced/payment_plan'
|
41
|
+
require 'invoiced/payment_source'
|
33
42
|
require 'invoiced/plan'
|
43
|
+
require 'invoiced/refund'
|
34
44
|
require 'invoiced/subscription'
|
45
|
+
require 'invoiced/task'
|
46
|
+
require 'invoiced/tax_rate'
|
47
|
+
require 'invoiced/text_message'
|
35
48
|
require 'invoiced/transaction'
|
36
49
|
|
37
50
|
module Invoiced
|
@@ -42,24 +55,32 @@ module Invoiced
|
|
42
55
|
OpenTimeout = 30
|
43
56
|
ReadTimeout = 80
|
44
57
|
|
45
|
-
attr_reader :api_key, :api_url, :sandbox
|
46
|
-
attr_reader :CatalogItem, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Plan, :Subscription, :Transaction
|
58
|
+
attr_reader :api_key, :api_url, :sandbox, :sso_key
|
59
|
+
attr_reader :CatalogItem, :Charge, :Coupon, :CreditNote, :Customer, :Estimate, :Event, :File, :Invoice, :Note, :Payment, :Plan, :Refund, :Subscription, :Task, :TaxRate, :Transaction
|
47
60
|
|
48
|
-
def initialize(api_key, sandbox=false)
|
61
|
+
def initialize(api_key, sandbox=false, sso_key=false)
|
49
62
|
@api_key = api_key
|
50
63
|
@sandbox = sandbox
|
51
64
|
@api_url = sandbox ? ApiBaseSandbox : ApiBase
|
65
|
+
@sso_key = sso_key
|
52
66
|
|
53
67
|
# Object endpoints
|
54
68
|
@CatalogItem = Invoiced::CatalogItem.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
|
|
@@ -97,6 +118,23 @@ module Invoiced
|
|
97
118
|
parse(response)
|
98
119
|
end
|
99
120
|
|
121
|
+
def generate_sign_in_token(customerId, ttl)
|
122
|
+
if !@sso_key
|
123
|
+
raise "Please provide a single sign-on key! You can find this value in Settings > Developers > Single Sign-On of the Invoiced application."
|
124
|
+
end
|
125
|
+
|
126
|
+
expires = Time.now + ttl # TTL should be in seconds
|
127
|
+
|
128
|
+
payload = {
|
129
|
+
:sub => customerId,
|
130
|
+
:iss => "Invoiced Ruby/#{Invoiced::VERSION}",
|
131
|
+
:iat => Time.now.to_i,
|
132
|
+
:exp => expires.to_i
|
133
|
+
}
|
134
|
+
|
135
|
+
JWT.encode payload, @sso_key, 'HS256'
|
136
|
+
end
|
137
|
+
|
100
138
|
private
|
101
139
|
|
102
140
|
def buildHeaders(opts)
|
@@ -184,4 +222,4 @@ module Invoiced
|
|
184
222
|
ApiError.new("API Error #{code} - #{body}", code)
|
185
223
|
end
|
186
224
|
end
|
187
|
-
end
|
225
|
+
end
|
data/lib/invoiced/attachment.rb
CHANGED
@@ -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
|
data/lib/invoiced/contact.rb
CHANGED
data/lib/invoiced/credit_note.rb
CHANGED
@@ -5,6 +5,8 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
+
OBJECT_NAME = 'credit_note'
|
9
|
+
|
8
10
|
def send(params={}, opts={})
|
9
11
|
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
12
|
|
@@ -33,5 +35,13 @@ module Invoiced
|
|
33
35
|
|
34
36
|
return attachments, metadata
|
35
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
|
36
46
|
end
|
37
47
|
end
|
data/lib/invoiced/customer.rb
CHANGED
@@ -5,6 +5,8 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
+
OBJECT_NAME = 'customer'
|
9
|
+
|
8
10
|
def send_statement(params={}, opts={})
|
9
11
|
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
12
|
|
@@ -13,6 +15,22 @@ module Invoiced
|
|
13
15
|
Util.build_objects(email, response[:body])
|
14
16
|
end
|
15
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
|
+
|
16
34
|
def balance
|
17
35
|
response = @client.request(:get, "#{self.endpoint()}/balance")
|
18
36
|
|
@@ -24,11 +42,21 @@ module Invoiced
|
|
24
42
|
contact.set_endpoint_base(self.endpoint())
|
25
43
|
end
|
26
44
|
|
45
|
+
def payment_sources()
|
46
|
+
source = PaymentSource.new(@client)
|
47
|
+
source.set_endpoint_base(self.endpoint())
|
48
|
+
end
|
49
|
+
|
27
50
|
def line_items()
|
28
51
|
line = LineItem.new(@client)
|
29
52
|
line.set_endpoint_base(self.endpoint())
|
30
53
|
end
|
31
54
|
|
55
|
+
def list_notes()
|
56
|
+
note = Note.new(@client)
|
57
|
+
note.set_endpoint_base(self.endpoint())
|
58
|
+
end
|
59
|
+
|
32
60
|
def invoice(params={}, opts={})
|
33
61
|
response = @client.request(:post, "#{self.endpoint()}/invoices", params, opts)
|
34
62
|
|
@@ -36,5 +64,13 @@ module Invoiced
|
|
36
64
|
invoice = Invoice.new(@client)
|
37
65
|
Util.convert_to_object(invoice, response[:body])
|
38
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
|
39
75
|
end
|
40
76
|
end
|
data/lib/invoiced/email.rb
CHANGED
data/lib/invoiced/estimate.rb
CHANGED
@@ -5,6 +5,8 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
+
OBJECT_NAME = 'estimate'
|
9
|
+
|
8
10
|
def send(params={}, opts={})
|
9
11
|
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
12
|
|
@@ -41,5 +43,13 @@ module Invoiced
|
|
41
43
|
|
42
44
|
return attachments, metadata
|
43
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
|
44
54
|
end
|
45
55
|
end
|
data/lib/invoiced/event.rb
CHANGED
data/lib/invoiced/file.rb
CHANGED
data/lib/invoiced/invoice.rb
CHANGED
@@ -5,6 +5,8 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
+
OBJECT_NAME = 'invoice'
|
9
|
+
|
8
10
|
def send(params={}, opts={})
|
9
11
|
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
12
|
|
@@ -13,6 +15,23 @@ module Invoiced
|
|
13
15
|
Util.build_objects(email, response[:body])
|
14
16
|
end
|
15
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
|
+
|
16
35
|
def pay(opts={})
|
17
36
|
response = @client.request(:post, "#{self.endpoint()}/pay", {}, opts)
|
18
37
|
|
@@ -31,7 +50,7 @@ module Invoiced
|
|
31
50
|
if !attachment.has_key?(:id)
|
32
51
|
attachment[:id] = attachment[:file][:id]
|
33
52
|
end
|
34
|
-
|
53
|
+
end
|
35
54
|
|
36
55
|
# build objects
|
37
56
|
attachment = Attachment.new(@client)
|
@@ -47,5 +66,18 @@ module Invoiced
|
|
47
66
|
paymentPlan = PaymentPlan.new(@client)
|
48
67
|
paymentPlan.set_endpoint_base(self.endpoint())
|
49
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
|
50
82
|
end
|
51
83
|
end
|