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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 35c409ed2ae535f3c067050c264aeff63a853721
4
- data.tar.gz: 3aba150984f9a4f676ff6a64db1165ed0b1a5c7e
3
+ metadata.gz: 4f736084452a6d592a98f327acd5d3fc8409b8db
4
+ data.tar.gz: 4f4ba8787785a2131686c4db8966e3c8460e4022
5
5
  SHA512:
6
- metadata.gz: 7a6ed8b5a0082fedbbdb8fa7997b6fbe9d00b5f0d66f34f83de38a5733ad5792134a95ea3f57cb842de79773b1a94c7bc1d360ee5c7a3bc81a2bf38396a8a3a5
7
- data.tar.gz: 8b4400f97f936d70f815bae2d79baf6692bf5916ee06481f3587847448ca2e7684a023b506852a4bd679ff6e0224eadf4e85d9b50da893b1870d476c47499291
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
@@ -1,4 +1,4 @@
1
1
  module Invoiced
2
2
  class Attachment < Object
3
- end
3
+ end
4
4
  end
@@ -1,8 +1,8 @@
1
1
  module Invoiced
2
2
  class Contact < Object
3
- include Invoiced::Operations::List
4
- include Invoiced::Operations::Create
5
- include Invoiced::Operations::Update
6
- include Invoiced::Operations::Delete
7
- end
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
@@ -1,40 +1,40 @@
1
1
  module Invoiced
2
2
  class Customer < 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_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
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
@@ -1,4 +1,4 @@
1
1
  module Invoiced
2
2
  class Email < Object
3
- end
3
+ end
4
4
  end
@@ -1,5 +1,5 @@
1
1
  module Invoiced
2
- class ApiConnectionError < ErrorBase
2
+ class ApiConnectionError < ErrorBase
3
3
 
4
- end
4
+ end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Invoiced
2
- class ApiError < ErrorBase
2
+ class ApiError < ErrorBase
3
3
 
4
- end
4
+ end
5
5
  end
@@ -1,5 +1,5 @@
1
1
  module Invoiced
2
- class AuthenticationError < ErrorBase
2
+ class AuthenticationError < ErrorBase
3
3
 
4
- end
4
+ end
5
5
  end
@@ -1,17 +1,17 @@
1
1
  module Invoiced
2
- class ErrorBase < StandardError
3
- attr_reader :message
4
- attr_reader :status_code
5
- attr_reader :error
2
+ class ErrorBase < StandardError
3
+ attr_reader :message
4
+ attr_reader :status_code
5
+ attr_reader :error
6
6
 
7
- def initialize(message=nil, status_code=nil, error=nil)
8
- @message = message
9
- @status_code = status_code
10
- @error = error
11
- end
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
- def to_s
14
- "(#{@status_code}): #{@message}"
15
- end
16
- end
13
+ def to_s
14
+ "(#{@status_code}): #{@message}"
15
+ end
16
+ end
17
17
  end
@@ -1,5 +1,5 @@
1
1
  module Invoiced
2
- class InvalidRequestError < ErrorBase
2
+ class InvalidRequestError < ErrorBase
3
3
 
4
- end
4
+ end
5
5
  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
@@ -1,5 +1,5 @@
1
1
  module Invoiced
2
2
  class Event < Object
3
- include Invoiced::Operations::List
4
- end
3
+ include Invoiced::Operations::List
4
+ end
5
5
  end
data/lib/invoiced/file.rb CHANGED
@@ -1,6 +1,6 @@
1
1
  module Invoiced
2
2
  class File < Object
3
- include Invoiced::Operations::Create
4
- include Invoiced::Operations::Delete
5
- end
3
+ include Invoiced::Operations::Create
4
+ include Invoiced::Operations::Delete
5
+ end
6
6
  end
@@ -1,46 +1,46 @@
1
1
  module Invoiced
2
2
  class Invoice < Object
3
- include Invoiced::Operations::List
4
- include Invoiced::Operations::Create
5
- include Invoiced::Operations::Update
6
- include Invoiced::Operations::Delete
3
+ include Invoiced::Operations::List
4
+ include Invoiced::Operations::Create
5
+ include Invoiced::Operations::Update
6
+ include Invoiced::Operations::Delete
7
7
 
8
- def send(opts={})
9
- response = @client.request(:post, "#{self.endpoint()}/emails", opts)
8
+ def send(opts={})
9
+ response = @client.request(:post, "#{self.endpoint()}/emails", opts)
10
10
 
11
- # build email objects
12
- email = Email.new(@client)
13
- Util.build_objects(email, response[:body])
14
- end
11
+ # build email objects
12
+ email = Email.new(@client)
13
+ Util.build_objects(email, response[:body])
14
+ end
15
15
 
16
- def pay
17
- response = @client.request(:post, "#{self.endpoint()}/pay")
16
+ def pay
17
+ response = @client.request(:post, "#{self.endpoint()}/pay")
18
18
 
19
- # update the local values with the response
20
- refresh_from(response[:body].dup.merge({:id => self.id}))
19
+ # update the local values with the response
20
+ refresh_from(response[:body].dup.merge({:id => self.id}))
21
21
 
22
- return response[:code] == 200
23
- end
22
+ return response[:code] == 200
23
+ end
24
24
 
25
- def attachments(opts={})
26
- response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
25
+ def attachments(opts={})
26
+ response = @client.request(:get, "#{self.endpoint()}/attachments", opts)
27
27
 
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
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
- # build objects
37
- attachment = Attachment.new(@client)
38
- attachments = Util.build_objects(attachment, body)
36
+ # build objects
37
+ attachment = Attachment.new(@client)
38
+ attachments = Util.build_objects(attachment, body)
39
39
 
40
- # store the metadata from the list operation
41
- metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
40
+ # store the metadata from the list operation
41
+ metadata = Invoiced::List.new(response[:headers][:link], response[:headers][:x_total_count])
42
42
 
43
- return attachments, metadata
44
- end
45
- end
43
+ return attachments, metadata
44
+ end
45
+ end
46
46
  end
@@ -1,8 +1,8 @@
1
1
  module Invoiced
2
2
  class LineItem < Object
3
- include Invoiced::Operations::List
4
- include Invoiced::Operations::Create
5
- include Invoiced::Operations::Update
6
- include Invoiced::Operations::Delete
7
- end
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
- class List
3
- attr_reader :links
4
- attr_reader :total_count
2
+ class List
3
+ attr_reader :links
4
+ attr_reader :total_count
5
5
 
6
- def initialize(link_header, total_count)
7
- @links = parse_link_header(link_header)
8
- @total_count = total_count
9
- end
6
+ def initialize(link_header, total_count)
7
+ @links = parse_link_header(link_header)
8
+ @total_count = total_count
9
+ end
10
10
 
11
- private
11
+ private
12
12
 
13
- def parse_link_header(header)
14
- links = Hash.new
13
+ def parse_link_header(header)
14
+ links = Hash.new
15
15
 
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
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
- return links
25
- end
26
- end
24
+ return links
25
+ end
26
+ end
27
27
  end