invoiced 0.7.0 → 0.8.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 +4 -4
- data/Gemfile +3 -1
- data/lib/invoiced/attachment.rb +1 -1
- data/lib/invoiced/contact.rb +5 -5
- data/lib/invoiced/credit_note.rb +37 -0
- data/lib/invoiced/customer.rb +37 -37
- data/lib/invoiced/email.rb +1 -1
- data/lib/invoiced/error/api_connection_error.rb +2 -2
- data/lib/invoiced/error/api_error.rb +2 -2
- data/lib/invoiced/error/authentication_error.rb +2 -2
- data/lib/invoiced/error/error_base.rb +13 -13
- data/lib/invoiced/error/invalid_request.rb +2 -2
- data/lib/invoiced/estimate.rb +37 -0
- data/lib/invoiced/event.rb +2 -2
- data/lib/invoiced/file.rb +3 -3
- data/lib/invoiced/invoice.rb +33 -33
- data/lib/invoiced/line_item.rb +5 -5
- data/lib/invoiced/list.rb +20 -20
- data/lib/invoiced/object.rb +165 -165
- data/lib/invoiced/operations/create.rb +8 -8
- data/lib/invoiced/operations/delete.rb +10 -10
- data/lib/invoiced/operations/list.rb +12 -12
- data/lib/invoiced/operations/update.rb +19 -19
- data/lib/invoiced/subscription.rb +8 -8
- data/lib/invoiced/transaction.rb +15 -15
- data/lib/invoiced/util.rb +51 -51
- data/lib/invoiced/version.rb +1 -1
- data/lib/invoiced.rb +114 -110
- data/test/invoiced/credit_note_test.rb +126 -0
- data/test/invoiced/estimate_test.rb +126 -0
- metadata +8 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f736084452a6d592a98f327acd5d3fc8409b8db
|
4
|
+
data.tar.gz: 4f4ba8787785a2131686c4db8966e3c8460e4022
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 416ba0ed6f5b90cd1ca822b246103b749999e0d32be0c33fdfb566955f16d0ebf76fe382ae45aae11ab4d3114ac6e0cccbe21f8634ba03419db10916cd212aa2
|
7
|
+
data.tar.gz: 82345c29a000f4242968818d9a66979153ab3040d215db97179d829753d45ef77e386dea946bfe1c8857abc0aaa5ecf4073ed95bf758eb43d87898d6a5f9bd96
|
data/Gemfile
CHANGED
@@ -6,4 +6,6 @@ gem 'rest-client', '~> 1.8.0'
|
|
6
6
|
gem 'activesupport', '~> 4.2.3'
|
7
7
|
gem 'coveralls', :require => false, :group => :test
|
8
8
|
gem 'simplecov', '~> 0.10.0', :require => false, :group => :test
|
9
|
-
gem 'simplecov-console', :require => false, :group => :test
|
9
|
+
gem 'simplecov-console', '~> 0.3.1', :require => false, :group => :test
|
10
|
+
gem 'term-ansicolor', '~> 1.3.2', :require => false, :group => :test
|
11
|
+
gem 'tins', '~> 1.6.0', :require => false, :group => :test
|
data/lib/invoiced/attachment.rb
CHANGED
data/lib/invoiced/contact.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Invoiced
|
2
2
|
class Contact < Object
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
|
+
end
|
8
8
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class CreditNote < Object
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
|
+
|
8
|
+
def send(opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
10
|
+
|
11
|
+
# build email objects
|
12
|
+
email = Email.new(@client)
|
13
|
+
Util.build_objects(email, response[:body])
|
14
|
+
end
|
15
|
+
|
16
|
+
def attachments(opts={})
|
17
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
|
18
|
+
|
19
|
+
# ensure each attachment has an ID
|
20
|
+
body = response[:body]
|
21
|
+
body.each do |attachment|
|
22
|
+
if !attachment.has_key?(:id)
|
23
|
+
attachment[:id] = attachment[:file][:id]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# build objects
|
28
|
+
attachment = Attachment.new(@client)
|
29
|
+
attachments = Util.build_objects(attachment, body)
|
30
|
+
|
31
|
+
# store the metadata from the list operation
|
32
|
+
metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
|
33
|
+
|
34
|
+
return attachments, metadata
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/invoiced/customer.rb
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
module Invoiced
|
2
2
|
class Customer < Object
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
|
+
|
8
|
+
def send_statement(opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
10
|
+
|
11
|
+
# build email objects
|
12
|
+
email = Email.new(@client)
|
13
|
+
Util.build_objects(email, response[:body])
|
14
|
+
end
|
15
|
+
|
16
|
+
def balance
|
17
|
+
response = @client.request(:get, "#{self.endpoint()}/balance")
|
18
|
+
|
19
|
+
response[:body]
|
20
|
+
end
|
21
|
+
|
22
|
+
def contacts(opts={})
|
23
|
+
contact = Contact.new(@client)
|
24
|
+
contact.set_endpoint_base(self.endpoint())
|
25
|
+
end
|
26
|
+
|
27
|
+
def line_items(opts={})
|
28
|
+
line = LineItem.new(@client)
|
29
|
+
line.set_endpoint_base(self.endpoint())
|
30
|
+
end
|
31
|
+
|
32
|
+
def invoice(opts={})
|
33
|
+
response = @client.request(:post, "#{self.endpoint()}/invoices", opts)
|
34
|
+
|
35
|
+
# build invoice object
|
36
|
+
invoice = Invoice.new(@client)
|
37
|
+
Util.convert_to_object(invoice, response[:body])
|
38
|
+
end
|
39
|
+
end
|
40
40
|
end
|
data/lib/invoiced/email.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module Invoiced
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
class ErrorBase < StandardError
|
3
|
+
attr_reader :message
|
4
|
+
attr_reader :status_code
|
5
|
+
attr_reader :error
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
7
|
+
def initialize(message=nil, status_code=nil, error=nil)
|
8
|
+
@message = message
|
9
|
+
@status_code = status_code
|
10
|
+
@error = error
|
11
|
+
end
|
12
12
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def to_s
|
14
|
+
"(#{@status_code}): #{@message}"
|
15
|
+
end
|
16
|
+
end
|
17
17
|
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
module Invoiced
|
2
|
+
class Estimate < Object
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
|
+
|
8
|
+
def send(opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
10
|
+
|
11
|
+
# build email objects
|
12
|
+
email = Email.new(@client)
|
13
|
+
Util.build_objects(email, response[:body])
|
14
|
+
end
|
15
|
+
|
16
|
+
def attachments(opts={})
|
17
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
|
18
|
+
|
19
|
+
# ensure each attachment has an ID
|
20
|
+
body = response[:body]
|
21
|
+
body.each do |attachment|
|
22
|
+
if !attachment.has_key?(:id)
|
23
|
+
attachment[:id] = attachment[:file][:id]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
# build objects
|
28
|
+
attachment = Attachment.new(@client)
|
29
|
+
attachments = Util.build_objects(attachment, body)
|
30
|
+
|
31
|
+
# store the metadata from the list operation
|
32
|
+
metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
|
33
|
+
|
34
|
+
return attachments, metadata
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
data/lib/invoiced/event.rb
CHANGED
data/lib/invoiced/file.rb
CHANGED
data/lib/invoiced/invoice.rb
CHANGED
@@ -1,46 +1,46 @@
|
|
1
1
|
module Invoiced
|
2
2
|
class Invoice < Object
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
def send(opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
# build email objects
|
12
|
+
email = Email.new(@client)
|
13
|
+
Util.build_objects(email, response[:body])
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
16
|
+
def pay
|
17
|
+
response = @client.request(:post, "#{self.endpoint()}/pay")
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
# update the local values with the response
|
20
|
+
refresh_from(response[:body].dup.merge({:id => self.id}))
|
21
21
|
|
22
|
-
|
23
|
-
|
22
|
+
return response[:code] == 200
|
23
|
+
end
|
24
24
|
|
25
|
-
|
26
|
-
|
25
|
+
def attachments(opts={})
|
26
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
|
27
27
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
28
|
+
# ensure each attachment has an ID
|
29
|
+
body = response[:body]
|
30
|
+
body.each do |attachment|
|
31
|
+
if !attachment.has_key?(:id)
|
32
|
+
attachment[:id] = attachment[:file][:id]
|
33
|
+
end
|
34
|
+
end
|
35
35
|
|
36
|
-
|
37
|
-
|
38
|
-
|
36
|
+
# build objects
|
37
|
+
attachment = Attachment.new(@client)
|
38
|
+
attachments = Util.build_objects(attachment, body)
|
39
39
|
|
40
|
-
|
41
|
-
|
40
|
+
# store the metadata from the list operation
|
41
|
+
metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
|
42
42
|
|
43
|
-
|
44
|
-
|
45
|
-
|
43
|
+
return attachments, metadata
|
44
|
+
end
|
45
|
+
end
|
46
46
|
end
|
data/lib/invoiced/line_item.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module Invoiced
|
2
2
|
class LineItem < Object
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
include Invoiced::Operations::List
|
4
|
+
include Invoiced::Operations::Create
|
5
|
+
include Invoiced::Operations::Update
|
6
|
+
include Invoiced::Operations::Delete
|
7
|
+
end
|
8
8
|
end
|
data/lib/invoiced/list.rb
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
module Invoiced
|
2
|
-
|
3
|
-
|
4
|
-
|
2
|
+
class List
|
3
|
+
attr_reader :links
|
4
|
+
attr_reader :total_count
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
def initialize(link_header, total_count)
|
7
|
+
@links = parse_link_header(link_header)
|
8
|
+
@total_count = total_count
|
9
|
+
end
|
10
10
|
|
11
|
-
|
11
|
+
private
|
12
12
|
|
13
|
-
|
14
|
-
|
13
|
+
def parse_link_header(header)
|
14
|
+
links = Hash.new
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
16
|
+
# Parse each part into a named link
|
17
|
+
header.split(',').each do |part, index|
|
18
|
+
section = part.split(';')
|
19
|
+
url = section[0][/<(.*)>/,1]
|
20
|
+
name = section[1][/rel="(.*)"/,1].to_sym
|
21
|
+
links[name] = url
|
22
|
+
end
|
23
23
|
|
24
|
-
|
25
|
-
|
26
|
-
|
24
|
+
return links
|
25
|
+
end
|
26
|
+
end
|
27
27
|
end
|