invoiced 0.11.2 → 0.12.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/invoiced.gemspec +1 -1
- data/lib/invoiced/credit_note.rb +4 -4
- data/lib/invoiced/customer.rb +6 -6
- data/lib/invoiced/estimate.rb +6 -6
- data/lib/invoiced/invoice.rb +7 -7
- data/lib/invoiced/object.rb +2 -5
- data/lib/invoiced/operations/create.rb +2 -2
- data/lib/invoiced/operations/list.rb +2 -2
- data/lib/invoiced/operations/update.rb +2 -2
- data/lib/invoiced/payment_plan.rb +4 -4
- data/lib/invoiced/transaction.rb +4 -4
- data/lib/invoiced/version.rb +1 -1
- data/lib/invoiced.rb +18 -7
- data/test/invoiced/invoiced_test.rb +34 -0
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5997cf1ddd23e0cece25a26780c348354a672b9c
|
4
|
+
data.tar.gz: 7f0a09349c1b87b9cfb11c8afbdf6533a566cdd2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cf0aa2c91593969dfe034a8f6f5db01fe6e7ee7164c0327ddd67de29c968b2378311af6ccbae253d90f75be240491cda23fa8bb3d3b09bc351ef9ce2a27cabdf
|
7
|
+
data.tar.gz: 9c936769e5d820574fdfef68e508454c1aa0fba468a602bfc4bc1e49edba3dcad2a2d4f8ca27fe92d2f2a546d6a55a45ecf58783b1bcfcb8541cbb43cf95dca4
|
data/invoiced.gemspec
CHANGED
@@ -12,7 +12,7 @@ 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 = '>=
|
15
|
+
s.required_ruby_version = '>= 2.0.0'
|
16
16
|
|
17
17
|
s.add_dependency('rest-client', '~> 2.0.0')
|
18
18
|
s.add_dependency('json', '~> 1.8.3')
|
data/lib/invoiced/credit_note.rb
CHANGED
@@ -5,16 +5,16 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
def send(opts={})
|
9
|
-
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
8
|
+
def send(params={}, opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
10
|
|
11
11
|
# build email objects
|
12
12
|
email = Email.new(@client)
|
13
13
|
Util.build_objects(email, response[:body])
|
14
14
|
end
|
15
15
|
|
16
|
-
def attachments(
|
17
|
-
response = @client.request(:get, "#{self.endpoint()}/attachments",
|
16
|
+
def attachments(params={})
|
17
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", params)
|
18
18
|
|
19
19
|
# ensure each attachment has an ID
|
20
20
|
body = response[:body]
|
data/lib/invoiced/customer.rb
CHANGED
@@ -5,8 +5,8 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
def send_statement(opts={})
|
9
|
-
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
8
|
+
def send_statement(params={}, opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
10
|
|
11
11
|
# build email objects
|
12
12
|
email = Email.new(@client)
|
@@ -19,18 +19,18 @@ module Invoiced
|
|
19
19
|
response[:body]
|
20
20
|
end
|
21
21
|
|
22
|
-
def contacts(
|
22
|
+
def contacts()
|
23
23
|
contact = Contact.new(@client)
|
24
24
|
contact.set_endpoint_base(self.endpoint())
|
25
25
|
end
|
26
26
|
|
27
|
-
def line_items(
|
27
|
+
def line_items()
|
28
28
|
line = LineItem.new(@client)
|
29
29
|
line.set_endpoint_base(self.endpoint())
|
30
30
|
end
|
31
31
|
|
32
|
-
def invoice(opts={})
|
33
|
-
response = @client.request(:post, "#{self.endpoint()}/invoices", opts)
|
32
|
+
def invoice(params={}, opts={})
|
33
|
+
response = @client.request(:post, "#{self.endpoint()}/invoices", params, opts)
|
34
34
|
|
35
35
|
# build invoice object
|
36
36
|
invoice = Invoice.new(@client)
|
data/lib/invoiced/estimate.rb
CHANGED
@@ -5,24 +5,24 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
def send(opts={})
|
9
|
-
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
8
|
+
def send(params={}, opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
10
|
|
11
11
|
# build email objects
|
12
12
|
email = Email.new(@client)
|
13
13
|
Util.build_objects(email, response[:body])
|
14
14
|
end
|
15
15
|
|
16
|
-
def generate_invoice(opts={})
|
17
|
-
response = @client.request(:post, "#{self.endpoint()}/invoice", opts)
|
16
|
+
def generate_invoice(params={}, opts={})
|
17
|
+
response = @client.request(:post, "#{self.endpoint()}/invoice", params, opts)
|
18
18
|
|
19
19
|
# build invoice object
|
20
20
|
invoice = Invoice.new(@client)
|
21
21
|
Util.convert_to_object(invoice, response[:body])
|
22
22
|
end
|
23
23
|
|
24
|
-
def attachments(
|
25
|
-
response = @client.request(:get, "#{self.endpoint()}/attachments",
|
24
|
+
def attachments(params={})
|
25
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", params)
|
26
26
|
|
27
27
|
# ensure each attachment has an ID
|
28
28
|
body = response[:body]
|
data/lib/invoiced/invoice.rb
CHANGED
@@ -5,16 +5,16 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
def send(opts={})
|
9
|
-
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
8
|
+
def send(params={}, opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
10
|
|
11
11
|
# build email objects
|
12
12
|
email = Email.new(@client)
|
13
13
|
Util.build_objects(email, response[:body])
|
14
14
|
end
|
15
15
|
|
16
|
-
def pay
|
17
|
-
response = @client.request(:post, "#{self.endpoint()}/pay")
|
16
|
+
def pay(opts={})
|
17
|
+
response = @client.request(:post, "#{self.endpoint()}/pay", {}, opts)
|
18
18
|
|
19
19
|
# update the local values with the response
|
20
20
|
refresh_from(response[:body].dup.merge({:id => self.id}))
|
@@ -22,8 +22,8 @@ module Invoiced
|
|
22
22
|
return response[:code] == 200
|
23
23
|
end
|
24
24
|
|
25
|
-
def attachments(
|
26
|
-
response = @client.request(:get, "#{self.endpoint()}/attachments",
|
25
|
+
def attachments(params={})
|
26
|
+
response = @client.request(:get, "#{self.endpoint()}/attachments", params)
|
27
27
|
|
28
28
|
# ensure each attachment has an ID
|
29
29
|
body = response[:body]
|
@@ -43,7 +43,7 @@ module Invoiced
|
|
43
43
|
return attachments, metadata
|
44
44
|
end
|
45
45
|
|
46
|
-
def payment_plan(
|
46
|
+
def payment_plan()
|
47
47
|
paymentPlan = PaymentPlan.new(@client)
|
48
48
|
paymentPlan.set_endpoint_base(self.endpoint())
|
49
49
|
end
|
data/lib/invoiced/object.rb
CHANGED
@@ -35,19 +35,16 @@ module Invoiced
|
|
35
35
|
@endpoint_base + @endpoint
|
36
36
|
end
|
37
37
|
|
38
|
-
def retrieve(id,
|
38
|
+
def retrieve(id, params={})
|
39
39
|
if !id
|
40
40
|
raise ArgumentError.new("Missing ID.")
|
41
41
|
end
|
42
42
|
|
43
|
-
response = @client.request(:get, "#{self.endpoint()}/#{id}",
|
43
|
+
response = @client.request(:get, "#{self.endpoint()}/#{id}", params)
|
44
44
|
|
45
45
|
Util.convert_to_object(self, response[:body])
|
46
46
|
end
|
47
47
|
|
48
|
-
def load(opts={})
|
49
|
-
end
|
50
|
-
|
51
48
|
def to_s(*args)
|
52
49
|
JSON.pretty_generate(@values)
|
53
50
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Invoiced
|
2
2
|
module Operations
|
3
3
|
module Create
|
4
|
-
def create(body={})
|
5
|
-
response = @client.request(:post, self.endpoint(), body)
|
4
|
+
def create(body={}, opts={})
|
5
|
+
response = @client.request(:post, self.endpoint(), body, opts)
|
6
6
|
|
7
7
|
Util.convert_to_object(self, response[:body])
|
8
8
|
end
|
@@ -1,8 +1,8 @@
|
|
1
1
|
module Invoiced
|
2
2
|
module Operations
|
3
3
|
module List
|
4
|
-
def list(
|
5
|
-
response = @client.request(:get, self.endpoint(),
|
4
|
+
def list(params={})
|
5
|
+
response = @client.request(:get, self.endpoint(), params)
|
6
6
|
|
7
7
|
# build objects
|
8
8
|
objects = Util.build_objects(self, response[:body])
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module Invoiced
|
2
2
|
module Operations
|
3
3
|
module Update
|
4
|
-
def save(params =
|
4
|
+
def save(params={}, opts={})
|
5
5
|
update = {}
|
6
6
|
|
7
7
|
@unsaved.each do |k|
|
@@ -12,7 +12,7 @@ module Invoiced
|
|
12
12
|
|
13
13
|
# perform the update if there are any changes
|
14
14
|
if update.length > 0
|
15
|
-
response = @client.request(:patch, self.endpoint(), update)
|
15
|
+
response = @client.request(:patch, self.endpoint(), update, opts)
|
16
16
|
|
17
17
|
# update the local values with the response
|
18
18
|
refresh_from(response[:body].dup.merge({:id => self.id}))
|
@@ -7,14 +7,14 @@ module Invoiced
|
|
7
7
|
@endpoint = '/payment_plan'
|
8
8
|
end
|
9
9
|
|
10
|
-
def create(
|
11
|
-
response = @client.request(:put, self.endpoint(),
|
10
|
+
def create(params={}, opts={})
|
11
|
+
response = @client.request(:put, self.endpoint(), params, opts)
|
12
12
|
|
13
13
|
Util.convert_to_object(self, response[:body])
|
14
14
|
end
|
15
15
|
|
16
|
-
def retrieve(
|
17
|
-
response = @client.request(:get, self.endpoint(),
|
16
|
+
def retrieve(params={})
|
17
|
+
response = @client.request(:get, self.endpoint(), params)
|
18
18
|
|
19
19
|
Util.convert_to_object(self, response[:body])
|
20
20
|
end
|
data/lib/invoiced/transaction.rb
CHANGED
@@ -5,16 +5,16 @@ module Invoiced
|
|
5
5
|
include Invoiced::Operations::Update
|
6
6
|
include Invoiced::Operations::Delete
|
7
7
|
|
8
|
-
def send(opts={})
|
9
|
-
response = @client.request(:post, "#{self.endpoint()}/emails", opts)
|
8
|
+
def send(params={}, opts={})
|
9
|
+
response = @client.request(:post, "#{self.endpoint()}/emails", params, opts)
|
10
10
|
|
11
11
|
# build email objects
|
12
12
|
email = Email.new(@client)
|
13
13
|
Util.build_objects(email, response[:body])
|
14
14
|
end
|
15
15
|
|
16
|
-
def refund(opts={})
|
17
|
-
response = @client.request(:post, "#{self.endpoint()}/refunds", opts)
|
16
|
+
def refund(params={}, opts={})
|
17
|
+
response = @client.request(:post, "#{self.endpoint()}/refunds", params, opts)
|
18
18
|
|
19
19
|
Util.convert_to_object(self, response[:body])
|
20
20
|
end
|
data/lib/invoiced/version.rb
CHANGED
data/lib/invoiced.rb
CHANGED
@@ -63,7 +63,7 @@ module Invoiced
|
|
63
63
|
@Transaction = Invoiced::Transaction.new(self)
|
64
64
|
end
|
65
65
|
|
66
|
-
def request(method, endpoint, params={})
|
66
|
+
def request(method, endpoint, params={}, opts={})
|
67
67
|
url = @api_url + endpoint
|
68
68
|
|
69
69
|
case method.to_s.downcase.to_sym
|
@@ -81,11 +81,7 @@ module Invoiced
|
|
81
81
|
response = RestClient::Request.execute(
|
82
82
|
:method => method,
|
83
83
|
:url => url,
|
84
|
-
:headers =>
|
85
|
-
:authorization => Util.auth_header(@api_key),
|
86
|
-
:content_type => "application/json",
|
87
|
-
:user_agent => "Invoiced Ruby/#{Invoiced::VERSION}"
|
88
|
-
},
|
84
|
+
:headers => buildHeaders(opts),
|
89
85
|
:payload => payload,
|
90
86
|
:open_timeout => OpenTimeout,
|
91
87
|
:timeout => ReadTimeout
|
@@ -103,6 +99,21 @@ module Invoiced
|
|
103
99
|
|
104
100
|
private
|
105
101
|
|
102
|
+
def buildHeaders(opts)
|
103
|
+
headers = {
|
104
|
+
:authorization => Util.auth_header(@api_key),
|
105
|
+
:content_type => "application/json",
|
106
|
+
:user_agent => "Invoiced Ruby/#{Invoiced::VERSION}"
|
107
|
+
}
|
108
|
+
|
109
|
+
# idempotency keys
|
110
|
+
if opts[:idempotency_key]
|
111
|
+
headers[:idempotency_key] = opts[:idempotency_key]
|
112
|
+
end
|
113
|
+
|
114
|
+
return headers
|
115
|
+
end
|
116
|
+
|
106
117
|
def parse(response)
|
107
118
|
unless response.code == 204
|
108
119
|
parsed_response = JSON.parse(response.body, :symbolize_names => true)
|
@@ -139,7 +150,7 @@ module Invoiced
|
|
139
150
|
def handle_network_error(error)
|
140
151
|
case error
|
141
152
|
when RestClient::Exceptions::OpenTimeout
|
142
|
-
message = "
|
153
|
+
message = "Timed out while connecting to Invoiced. Please check your internet connection or status.invoiced.com for service outages."
|
143
154
|
when RestClient::Exceptions::ReadTimeout
|
144
155
|
message = "The request timed out reading data from the server."
|
145
156
|
when RestClient::ServerBrokeConnection
|
@@ -93,6 +93,40 @@ module Invoiced
|
|
93
93
|
assert_equal(expectedResponse, response)
|
94
94
|
end
|
95
95
|
|
96
|
+
should "perform an idempotent post request" do
|
97
|
+
mockResponse = mock('RestClient::Response')
|
98
|
+
mockResponse.stubs(:code).returns(204)
|
99
|
+
mockResponse.stubs(:headers).returns({})
|
100
|
+
|
101
|
+
# not used
|
102
|
+
# expectedParameters = {
|
103
|
+
# :method => "POST",
|
104
|
+
# :url => "https://api.invoiced.com/invoices?test=property&filter[levels]=work",
|
105
|
+
# :headers => {
|
106
|
+
# :authorization => "Basic dGVzdDo=",
|
107
|
+
# :content_type => "application/json",
|
108
|
+
# :user_agent => "Invoiced Ruby/#{Invoiced::VERSION}"
|
109
|
+
# :idempotency_key => "a random value"
|
110
|
+
# },
|
111
|
+
# :payload => '{"test":"property"}'
|
112
|
+
# }
|
113
|
+
|
114
|
+
RestClient::Request.any_instance.expects(:execute).returns(mockResponse)
|
115
|
+
|
116
|
+
client = Invoiced::Client.new('test')
|
117
|
+
params = {
|
118
|
+
"test" => "property"
|
119
|
+
}
|
120
|
+
response = client.request("POST", "/invoices", params, {:idempotency_key => "a random value"})
|
121
|
+
|
122
|
+
expectedResponse = {
|
123
|
+
:code => 204,
|
124
|
+
:headers => {},
|
125
|
+
:body => nil
|
126
|
+
}
|
127
|
+
assert_equal(expectedResponse, response)
|
128
|
+
end
|
129
|
+
|
96
130
|
should "handle a generic network error" do
|
97
131
|
RestClient::Request.any_instance.expects(:execute).raises(RestClient::Exception.new)
|
98
132
|
|
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.
|
4
|
+
version: 0.12.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: 2017-07-
|
11
|
+
date: 2017-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rest-client
|
@@ -181,7 +181,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
181
181
|
requirements:
|
182
182
|
- - ">="
|
183
183
|
- !ruby/object:Gem::Version
|
184
|
-
version:
|
184
|
+
version: 2.0.0
|
185
185
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
186
186
|
requirements:
|
187
187
|
- - ">="
|