badbill 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CONTRIBUTING.md +5 -2
- data/Gemfile +14 -3
- data/Gemfile.lock +51 -15
- data/Guardfile +6 -0
- data/LICENSE +1 -1
- data/README.md +8 -3
- data/Rakefile +5 -1
- data/badbill.gemspec +86 -0
- data/lib/badbill.rb +32 -2
- data/lib/badbill/base_resource.rb +51 -9
- data/lib/badbill/client.rb +1 -1
- data/lib/badbill/faraday_gzip.rb +18 -0
- data/lib/badbill/forward_methods.rb +6 -0
- data/lib/badbill/invoice.rb +31 -1
- data/lib/badbill/invoice_comment.rb +24 -0
- data/lib/badbill/invoice_item.rb +17 -0
- data/lib/badbill/invoice_payment.rb +28 -0
- data/lib/badbill/recurring.rb +11 -0
- data/spec/badbill/base_resource_spec.rb +1 -1
- data/spec/badbill/client_spec.rb +72 -68
- data/spec/badbill/invoice_comment_spec.rb +33 -0
- data/spec/badbill/invoice_item_spec.rb +17 -0
- data/spec/badbill/invoice_payment_spec.rb +17 -0
- data/spec/badbill/invoice_spec.rb +77 -176
- data/spec/badbill/recurring_spec.rb +18 -0
- data/spec/badbill_spec.rb +19 -17
- data/spec/fixtures/vcr_cassettes/aggregated_invoices.yml +64 -0
- data/spec/fixtures/vcr_cassettes/all_clients.yml +72 -0
- data/spec/fixtures/vcr_cassettes/all_invoices.yml +134 -0
- data/spec/fixtures/vcr_cassettes/all_recurring_invoices.yml +131 -0
- data/spec/fixtures/vcr_cassettes/client_on_change.yml +54 -0
- data/spec/fixtures/vcr_cassettes/draft_item.yml +71 -0
- data/spec/fixtures/vcr_cassettes/existent_client.yml +71 -0
- data/spec/fixtures/vcr_cassettes/fetched_invoice_pdf.yml +2111 -0
- data/spec/fixtures/vcr_cassettes/fetches_invoice-item_by_id.yml +123 -0
- data/spec/fixtures/vcr_cassettes/invoice-comments_by_invoice_id.yml +68 -0
- data/spec/fixtures/vcr_cassettes/invoice-comments_by_invoice_id_and_actionkey_PAYMENT.yml +131 -0
- data/spec/fixtures/vcr_cassettes/invoice-comments_by_invoice_id_and_actionkeys.yml +67 -0
- data/spec/fixtures/vcr_cassettes/invoice_canceled.yml +50 -0
- data/spec/fixtures/vcr_cassettes/invoice_deleted.yml +46 -0
- data/spec/fixtures/vcr_cassettes/invoice_info.yml +131 -0
- data/spec/fixtures/vcr_cassettes/invoice_marked_as_complete.yml +95 -0
- data/spec/fixtures/vcr_cassettes/invoice_payments.yml +123 -0
- data/spec/fixtures/vcr_cassettes/invoice_send_email_with_basic_info.yml +48 -0
- data/spec/fixtures/vcr_cassettes/invoice_send_email_with_basic_info_and_from.yml +48 -0
- data/spec/fixtures/vcr_cassettes/invoice_send_email_with_basic_info_from_and_subject.yml +48 -0
- data/spec/fixtures/vcr_cassettes/invoice_send_mail.yml +48 -0
- data/spec/fixtures/vcr_cassettes/invoice_send_mail_invalid_address.yml +48 -0
- data/spec/fixtures/vcr_cassettes/invoice_uploaded_signature.yml +48 -0
- data/spec/fixtures/vcr_cassettes/myself_client.yml +70 -0
- data/spec/fixtures/vcr_cassettes/new_client.yml +50 -0
- data/spec/fixtures/vcr_cassettes/non_existent_client.yml +303 -0
- data/spec/fixtures/vcr_cassettes/save_for_non-existent_client.yml +48 -0
- data/spec/fixtures/vcr_cassettes/wrong_data_for_client.yml +50 -0
- data/spec/spec_helper.rb +50 -0
- metadata +43 -4
- data/spec/helper.rb +0 -24
data/lib/badbill/client.rb
CHANGED
@@ -0,0 +1,18 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'zlib'
|
4
|
+
require 'faraday_middleware/response_middleware'
|
5
|
+
|
6
|
+
module FaradayMiddleware
|
7
|
+
class Gzip < ResponseMiddleware
|
8
|
+
define_parser do |body|
|
9
|
+
Zlib::GzipReader.new(StringIO.new(body)).read
|
10
|
+
end
|
11
|
+
|
12
|
+
def parse_response?(env)
|
13
|
+
super && env[:response_headers]['content-encoding'] == "gzip"
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
Faraday::Response.register_middleware :gzip => FaradayMiddleware::Gzip
|
@@ -11,6 +11,12 @@ class BadBill
|
|
11
11
|
# assignment request, we only check for the method name without the equal sign.
|
12
12
|
def method_missing(method_name, *arguments, &block)
|
13
13
|
if data.respond_to?(method_name.to_s.sub(/=$/, ''))
|
14
|
+
if method_name.to_s.end_with?('=')
|
15
|
+
@__mutated__ ||= []
|
16
|
+
@__mutated__ << method_name.to_s.sub(/=$/, '')
|
17
|
+
@__mutated__.uniq!
|
18
|
+
end
|
19
|
+
|
14
20
|
data.send(method_name, *arguments, &block)
|
15
21
|
else
|
16
22
|
super
|
data/lib/badbill/invoice.rb
CHANGED
@@ -7,6 +7,34 @@ class BadBill
|
|
7
7
|
#
|
8
8
|
# See http://www.billomat.com/en/api/invoices
|
9
9
|
class Invoice < BaseResource
|
10
|
+
# Get aggregated list of invoices.
|
11
|
+
#
|
12
|
+
# BE CAREFUL: The returned objects are not really invoices.
|
13
|
+
# See http://www.billomat.com/en/api/invoices/ for the format.
|
14
|
+
#
|
15
|
+
# @param [String,Symbol,#to_s] type One of ['client', 'status', 'day',
|
16
|
+
# 'week', 'month', 'year'].
|
17
|
+
# Specify multiple types for finer
|
18
|
+
# aggregation.
|
19
|
+
#
|
20
|
+
# @return [Array<Invoices>] All found resources.
|
21
|
+
def self.group_by *type
|
22
|
+
if type.respond_to?(:join)
|
23
|
+
type = type.join(',')
|
24
|
+
end
|
25
|
+
|
26
|
+
all = get resource_name, group_by: type
|
27
|
+
|
28
|
+
return all if all.error
|
29
|
+
|
30
|
+
data = all.__send__('invoice-groups').__send__('invoice-group')
|
31
|
+
|
32
|
+
if data.kind_of? Array
|
33
|
+
data
|
34
|
+
else
|
35
|
+
[data]
|
36
|
+
end
|
37
|
+
end
|
10
38
|
# Get the PDF invoice.
|
11
39
|
#
|
12
40
|
#
|
@@ -16,7 +44,9 @@ class BadBill
|
|
16
44
|
# all parameters.
|
17
45
|
def pdf
|
18
46
|
resp = get resource_name, "#{id}/pdf"
|
19
|
-
resp.pdf
|
47
|
+
ret = resp.pdf
|
48
|
+
ret.id = ret.id.to_i
|
49
|
+
ret
|
20
50
|
end
|
21
51
|
|
22
52
|
# Closes a statement in the draft status (DRAFT). Here, the
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class BadBill
|
4
|
+
# The InvoiceComment resource handles all invoice comments.
|
5
|
+
#
|
6
|
+
# See http://www.billomat.com/en/api/invoices/comments-and-history/
|
7
|
+
class InvoiceComment < BaseResource
|
8
|
+
# Get all Invoice Comments for given invoice id.
|
9
|
+
#
|
10
|
+
# @param [Integer] invoice_id The invoice id to search for.
|
11
|
+
# @param [String,Array] actionkey Indicates what kind of comment it is. See API docu for possible values. An Array will be joined into a String.
|
12
|
+
#
|
13
|
+
# @return [Array<InvoiceComment>] All found invoice comments.
|
14
|
+
def self.all invoice_id, actionkey=nil
|
15
|
+
params = { invoice_id: invoice_id }
|
16
|
+
if actionkey
|
17
|
+
actionkey = actionkey.join(',') if actionkey.respond_to?(:join)
|
18
|
+
params[:actionkey] = actionkey
|
19
|
+
end
|
20
|
+
|
21
|
+
super params
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class BadBill
|
4
|
+
# The InvoiceItem resource handles all invoice items.
|
5
|
+
#
|
6
|
+
# See http://www.billomat.com/en/api/invoices/items/
|
7
|
+
class InvoiceItem < BaseResource
|
8
|
+
# Get all resources of this type.
|
9
|
+
#
|
10
|
+
# @param [Integer] invoice_id The invoice id to search for.
|
11
|
+
#
|
12
|
+
# @return [Array<InvoiceItem>] All found invoice items.
|
13
|
+
def self.all invoice_id
|
14
|
+
super invoice_id: invoice_id
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class BadBill
|
4
|
+
# The InvoicePayment resource handles all invoice payments.
|
5
|
+
#
|
6
|
+
# See http://www.billomat.com/en/api/invoices/payments/
|
7
|
+
class InvoicePayment < BaseResource
|
8
|
+
# Create a new invoice payment.
|
9
|
+
#
|
10
|
+
# @param [String,] invoice_id The ID of the invoice
|
11
|
+
# @param [String,Numeric] amount The paid amount
|
12
|
+
# @param [Boolean] is_paid Wether the invoice should be marked as paid
|
13
|
+
# or not
|
14
|
+
# @return [InvoicePayment,Hashie::Mash] New payment with id and data set
|
15
|
+
# or hash if any error happened
|
16
|
+
def self.create invoice_id, amount, is_paid=false, params={}
|
17
|
+
params['invoice_id'] = invoice_id
|
18
|
+
params['amount'] = amount
|
19
|
+
params['mark_invoice_as_paid'] = is_paid
|
20
|
+
|
21
|
+
res = post(resource_name, {resource_name_singular => params})
|
22
|
+
return res if res.error
|
23
|
+
|
24
|
+
res_data = res.__send__(resource_name_singular)
|
25
|
+
new res_data.id.to_i, res_data
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
data/spec/badbill/client_spec.rb
CHANGED
@@ -1,98 +1,102 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
5
|
describe BadBill::Client do
|
6
6
|
before :all do
|
7
|
-
@badbill =
|
7
|
+
@badbill = new_badbill 1
|
8
8
|
end
|
9
9
|
|
10
10
|
it "fetches all clients" do
|
11
|
-
|
12
|
-
|
13
|
-
to_return(:body => '{"clients":{"client":[{"id":1}]}}',
|
14
|
-
:headers => {'Content-Type' => 'application/json'})
|
11
|
+
VCR.use_cassette('all_clients') do
|
12
|
+
resp = BadBill::Client.all
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
resp.size.should == 1
|
20
|
-
resp.first.id.should == 1
|
14
|
+
resp.size.should eq(1)
|
15
|
+
resp.first.id.should eq(169499)
|
16
|
+
end
|
21
17
|
end
|
22
18
|
|
23
19
|
it "fetches info about myself" do
|
24
|
-
|
25
|
-
|
26
|
-
to_return(:body => '{"client":{"id":1}}',
|
27
|
-
:headers => {'Content-Type' => 'application/json'})
|
28
|
-
|
29
|
-
resp = BadBill::Client.myself
|
30
|
-
stub.should have_been_requested
|
20
|
+
VCR.use_cassette('myself_client') do
|
21
|
+
resp = BadBill::Client.myself
|
31
22
|
|
32
|
-
|
33
|
-
|
23
|
+
resp.id.should eq(148386)
|
24
|
+
resp.myself?.should be_true
|
25
|
+
end
|
34
26
|
end
|
35
27
|
|
36
28
|
it "fetches info about another client" do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
29
|
+
VCR.use_cassette('existent client') do
|
30
|
+
resp = BadBill::Client.find 169499
|
31
|
+
|
32
|
+
resp.id.should eq(169499)
|
33
|
+
resp.myself?.should be_false
|
34
|
+
end
|
35
|
+
end
|
41
36
|
|
42
|
-
|
43
|
-
|
37
|
+
it "returns nil when no client found" do
|
38
|
+
VCR.use_cassette('non existent client') do
|
39
|
+
resp = BadBill::Client.find 11111
|
44
40
|
|
45
|
-
|
46
|
-
|
41
|
+
resp.should be_nil
|
42
|
+
end
|
47
43
|
end
|
48
44
|
|
49
45
|
it "saves changes to client data" do
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
46
|
+
client = nil
|
47
|
+
VCR.use_cassette('existent client') do
|
48
|
+
client = BadBill::Client.find 169499
|
49
|
+
end
|
50
|
+
|
51
|
+
VCR.use_cassette('client on change') do
|
52
|
+
client.name.should eq("Jan-Erik Rediger")
|
53
|
+
client.name = "new name"
|
54
|
+
saved = client.save
|
55
|
+
|
56
|
+
saved.error.should be_nil
|
57
|
+
saved.name.should eq("new name")
|
58
|
+
client.name.should eq("new name")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "returns error on failed save" do
|
63
|
+
VCR.use_cassette('save for non-existent client') do
|
64
|
+
client = BadBill::Client.new 169500, Hashie::Mash.new(name: "foo")
|
65
|
+
client.name = "new name"
|
66
|
+
saved = client.save
|
67
|
+
|
68
|
+
saved.error.should be_a(Faraday::Error::ClientError)
|
69
|
+
end
|
67
70
|
end
|
68
71
|
|
69
72
|
it "creates a new client with given data" do
|
70
|
-
|
71
|
-
|
72
|
-
"name"
|
73
|
-
"salutation"
|
74
|
-
"first_name"
|
75
|
-
"last_name"
|
76
|
-
"street"
|
77
|
-
"zip"
|
78
|
-
"city"
|
79
|
-
"state"
|
80
|
-
"country_code"
|
73
|
+
VCR.use_cassette('new client') do
|
74
|
+
data = {
|
75
|
+
"name" => "Musterfirma",
|
76
|
+
"salutation" => "Herr",
|
77
|
+
"first_name" => "Max",
|
78
|
+
"last_name" => "Muster",
|
79
|
+
"street" => "Musterstraße 123",
|
80
|
+
"zip" => "12345",
|
81
|
+
"city" => "Musterstadt",
|
82
|
+
"state" => "Bundesland",
|
83
|
+
"country_code" => "DE",
|
81
84
|
}
|
82
|
-
}
|
83
85
|
|
84
|
-
|
85
|
-
|
86
|
-
|
86
|
+
client = BadBill::Client.create data
|
87
|
+
client.id.should_not be_nil
|
88
|
+
client.name.should eq("Musterfirma")
|
89
|
+
end
|
90
|
+
end
|
87
91
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
92
|
+
context "create with wrong data" do
|
93
|
+
it "returns an error" do
|
94
|
+
VCR.use_cassette('wrong data for client') do
|
95
|
+
data = { "email" => "this@is.invalid" }
|
96
|
+
client = BadBill::Client.create data
|
93
97
|
|
94
|
-
|
95
|
-
|
96
|
-
|
98
|
+
client.error.should be_a(Faraday::Error::ClientError)
|
99
|
+
end
|
100
|
+
end
|
97
101
|
end
|
98
102
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BadBill::InvoiceComment do
|
6
|
+
before :all do
|
7
|
+
@badbill = new_badbill 1
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fetches all invoice-comments" do
|
11
|
+
VCR.use_cassette("invoice-comments by invoice id") do
|
12
|
+
resp = BadBill::InvoiceComment.all 360264
|
13
|
+
|
14
|
+
resp.size.should eq(3)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
it "fetches all invoice-comments for PAYED status" do
|
19
|
+
VCR.use_cassette("invoice-comments by invoice id and actionkey PAYMENT") do
|
20
|
+
resp = BadBill::InvoiceComment.all 360264, 'PAYMENT'
|
21
|
+
|
22
|
+
resp.size.should eq(1)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
it "fetches all invoice-comments for 2 actionkey params" do
|
27
|
+
VCR.use_cassette("invoice-comments by invoice id and actionkeys") do
|
28
|
+
resp = BadBill::InvoiceComment.all 360264, ['CREATE','PAYMENT']
|
29
|
+
|
30
|
+
resp.size.should eq(2)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BadBill::InvoiceItem do
|
6
|
+
before :all do
|
7
|
+
@badbill = new_badbill 1
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fetches all invoice-item" do
|
11
|
+
VCR.use_cassette("fetches invoice-item by id") do
|
12
|
+
resp = BadBill::InvoiceItem.all 1
|
13
|
+
|
14
|
+
resp.size.should eq(0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe BadBill::InvoicePayment do
|
6
|
+
before :all do
|
7
|
+
@badbill = new_badbill 1
|
8
|
+
end
|
9
|
+
|
10
|
+
it "fetches all invoice-payments" do
|
11
|
+
VCR.use_cassette('invoice payments') do
|
12
|
+
resp = BadBill::InvoicePayment.all
|
13
|
+
|
14
|
+
resp.size.should eq(0)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -1,227 +1,128 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
|
3
|
+
require 'spec_helper'
|
4
4
|
|
5
5
|
describe BadBill::Invoice do
|
6
6
|
before :all do
|
7
|
-
@badbill =
|
7
|
+
@badbill = new_badbill 1
|
8
8
|
end
|
9
9
|
|
10
10
|
it "fetches all invoices" do
|
11
|
-
|
12
|
-
|
13
|
-
to_return(:body => '{"invoices":{"invoice":[{"id":1}]}}',
|
14
|
-
:headers => {'Content-Type' => 'application/json'})
|
11
|
+
VCR.use_cassette("all invoices") do
|
12
|
+
resp = BadBill::Invoice.all
|
15
13
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
resp.size.should == 1
|
20
|
-
resp.first.id.should == 1
|
14
|
+
resp.size.should eq(2)
|
15
|
+
end
|
21
16
|
end
|
22
17
|
|
23
18
|
it "fetches info about an invoice" do
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
19
|
+
VCR.use_cassette("invoice info") do
|
20
|
+
resp = BadBill::Invoice.find 352709
|
21
|
+
|
22
|
+
resp.id.should eq(352709)
|
23
|
+
resp.invoice_number.to_i.should eq(1)
|
24
|
+
end
|
25
|
+
end
|
28
26
|
|
29
|
-
|
30
|
-
|
27
|
+
it "fetches aggregated invoices" do
|
28
|
+
VCR.use_cassette("aggregated invoices") do
|
29
|
+
resp = BadBill::Invoice.group_by :client
|
31
30
|
|
32
|
-
|
31
|
+
resp.first.total_gross.should == "124.00"
|
32
|
+
end
|
33
33
|
end
|
34
34
|
|
35
|
-
context "existing invoice" do
|
35
|
+
context "existing invoice 1" do
|
36
36
|
before :each do
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
:headers => {'Content-Type' => 'application/json'})
|
41
|
-
|
42
|
-
@invoice = BadBill::Invoice.find 1
|
37
|
+
VCR.use_cassette('draft item') do
|
38
|
+
@invoice = BadBill::Invoice.find 352320
|
39
|
+
end
|
43
40
|
end
|
44
41
|
|
45
42
|
it "marks invoice as complete" do
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
@invoice.complete.should == true
|
51
|
-
stub.should have_been_requested
|
43
|
+
VCR.use_cassette('invoice marked as complete') do
|
44
|
+
@invoice.complete.should == true
|
45
|
+
end
|
52
46
|
end
|
53
47
|
|
54
|
-
it "cancels an invoice" do
|
55
|
-
stub = stub_request(:put, "ruby.billomat.net/api/invoices/1/cancel").
|
56
|
-
with(:headers => {'Accept' => 'application/json'}).
|
57
|
-
to_return(:status => 200)
|
58
48
|
|
59
|
-
|
60
|
-
|
49
|
+
it "cancels an invoice" do
|
50
|
+
VCR.use_cassette('invoice canceled') do
|
51
|
+
@invoice.cancel.should == true
|
52
|
+
end
|
61
53
|
end
|
62
54
|
|
63
55
|
it "deletes an invoice" do
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
@invoice.delete.should == true
|
69
|
-
stub.should have_been_requested
|
56
|
+
VCR.use_cassette('invoice deleted') do
|
57
|
+
@invoice.delete.should == true
|
58
|
+
end
|
70
59
|
end
|
60
|
+
end
|
71
61
|
|
62
|
+
context "existing invoice 2" do
|
63
|
+
before :each do
|
64
|
+
VCR.use_cassette('invoice info') do
|
65
|
+
@invoice = BadBill::Invoice.find 352709
|
66
|
+
end
|
67
|
+
end
|
72
68
|
it "fetches the pdf" do
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
"mimetype" => "application/pdf",
|
80
|
-
"filesize" => "1",
|
81
|
-
"base64file" => "foobar"
|
82
|
-
}
|
83
|
-
}
|
84
|
-
|
85
|
-
stub = stub_request(:get, "ruby.billomat.net/api/invoices/1/pdf").
|
86
|
-
with(:headers => {'Accept' => 'application/json'}).
|
87
|
-
to_return(:body => body, :headers => {
|
88
|
-
'Content-Type' => 'application/json'
|
89
|
-
})
|
90
|
-
|
91
|
-
pdf = @invoice.pdf
|
92
|
-
|
93
|
-
stub.should have_been_requested
|
94
|
-
pdf.id.should == 1
|
95
|
-
pdf.invoice_id == 1
|
69
|
+
VCR.use_cassette('fetched invoice pdf') do
|
70
|
+
pdf = @invoice.pdf
|
71
|
+
|
72
|
+
pdf.id.should == 356105
|
73
|
+
pdf.invoice_id == 352709
|
74
|
+
end
|
96
75
|
end
|
97
76
|
|
98
77
|
it "uploads a signature" do
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
@invoice.status = "OPEN"
|
105
|
-
file_content = StringIO.new "ruby"
|
106
|
-
resp = @invoice.upload_signature file_content
|
107
|
-
resp.should == true
|
108
|
-
|
109
|
-
stub.should have_been_requested
|
78
|
+
VCR.use_cassette('invoice uploaded signature') do
|
79
|
+
file_content = StringIO.new "ruby"
|
80
|
+
resp = @invoice.upload_signature file_content
|
81
|
+
resp.should == true
|
82
|
+
end
|
110
83
|
end
|
111
84
|
|
112
85
|
context "sending invoice as mail" do
|
113
86
|
it "sends an invoice via mail" do
|
114
|
-
|
115
|
-
|
116
|
-
"
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
"attachment" => {
|
126
|
-
"filename" => "more.pdf",
|
127
|
-
"mimetype" => "application/pdf",
|
128
|
-
"base64file" => "foobar"
|
87
|
+
VCR.use_cassette('invoice send mail') do
|
88
|
+
resp = @invoice.email "M8R-10apg01@mailinator.com", "janerik@badbill.net",
|
89
|
+
"subject", "body", {
|
90
|
+
recipients: { cc: "f4a269895b2c7eccd43296d2b@mailinator.com" },
|
91
|
+
filename: "invoice",
|
92
|
+
attachments: {
|
93
|
+
attachment: {
|
94
|
+
filename: "more.pdf",
|
95
|
+
mimetype: "application/pdf",
|
96
|
+
base64file: "Zm9vYmFyCg=="
|
97
|
+
}
|
129
98
|
}
|
130
99
|
}
|
131
|
-
}
|
132
|
-
}
|
133
|
-
|
134
|
-
stub = stub_request(:post, "ruby.billomat.net/api/invoices/1/email").
|
135
|
-
with(:headers => {'Accept' => 'application/json'}, :body => body).
|
136
|
-
to_return(:headers => {
|
137
|
-
'Content-Type' => 'application/json'
|
138
|
-
})
|
139
|
-
|
140
|
-
resp = @invoice.email "recv@test.example", "sender@test.example",
|
141
|
-
"subject", "body", {
|
142
|
-
recipients: { cc: "mail@test.example" },
|
143
|
-
filename: "invoice",
|
144
|
-
attachments: {
|
145
|
-
attachment: {
|
146
|
-
filename: "more.pdf",
|
147
|
-
mimetype: "application/pdf",
|
148
|
-
base64file: "foobar"
|
149
|
-
}
|
150
|
-
}
|
151
|
-
}
|
152
100
|
|
153
|
-
|
154
|
-
|
101
|
+
resp.should == true
|
102
|
+
end
|
155
103
|
end
|
156
104
|
|
157
105
|
it "sends an invoice with only basic information" do
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
"cc" => "mail@test.example",
|
163
|
-
}
|
164
|
-
}
|
165
|
-
}
|
166
|
-
|
167
|
-
stub = stub_request(:post, "ruby.billomat.net/api/invoices/1/email").
|
168
|
-
with(:headers => {'Accept' => 'application/json'}, :body => body).
|
169
|
-
to_return(:headers => {
|
170
|
-
'Content-Type' => 'application/json'
|
171
|
-
})
|
172
|
-
|
173
|
-
resp = @invoice.email "recv@test.example", {recipients: { cc: "mail@test.example" }}
|
174
|
-
|
175
|
-
stub.should have_been_requested
|
176
|
-
resp.should == true
|
106
|
+
VCR.use_cassette('invoice send email with basic info') do
|
107
|
+
resp = @invoice.email "M8R-10apg01@mailinator.com", {recipients: { cc: "mail@test.example" }}
|
108
|
+
resp.should == true
|
109
|
+
end
|
177
110
|
end
|
178
111
|
|
179
112
|
it "sends an invoice with basic information and from" do
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
"cc" => "mail@test.example",
|
185
|
-
},
|
186
|
-
"from" => "sender@test.example"
|
187
|
-
}
|
188
|
-
}
|
189
|
-
|
190
|
-
stub = stub_request(:post, "ruby.billomat.net/api/invoices/1/email").
|
191
|
-
with(:headers => {'Accept' => 'application/json'}, :body => body).
|
192
|
-
to_return(:headers => {
|
193
|
-
'Content-Type' => 'application/json'
|
194
|
-
})
|
195
|
-
|
196
|
-
resp = @invoice.email "recv@test.example", "sender@test.example", {recipients: { cc: "mail@test.example" }}
|
197
|
-
|
198
|
-
stub.should have_been_requested
|
199
|
-
resp.should == true
|
113
|
+
VCR.use_cassette('invoice send email with basic info and from') do
|
114
|
+
resp = @invoice.email "M8R-10apg01@mailinator.com", "sender@test.example", {recipients: { cc: "mail@test.example" }}
|
115
|
+
resp.should == true
|
116
|
+
end
|
200
117
|
end
|
201
118
|
|
202
119
|
it "sends an invoice with basic information, from and subject" do
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
"from" => "sender@test.example",
|
210
|
-
"subject" => "subject"
|
211
|
-
}
|
212
|
-
}
|
213
|
-
|
214
|
-
stub = stub_request(:post, "ruby.billomat.net/api/invoices/1/email").
|
215
|
-
with(:headers => {'Accept' => 'application/json'}, :body => body).
|
216
|
-
to_return(:headers => {
|
217
|
-
'Content-Type' => 'application/json'
|
218
|
-
})
|
219
|
-
|
220
|
-
resp = @invoice.email "recv@test.example", "sender@test.example", "subject",
|
221
|
-
{recipients: { cc: "mail@test.example" }}
|
222
|
-
|
223
|
-
stub.should have_been_requested
|
224
|
-
resp.should == true
|
120
|
+
VCR.use_cassette('invoice send email with basic info from and subject') do
|
121
|
+
resp = @invoice.email "M8R-10apg01@mailinator.com", "sender@test.example", "subject",
|
122
|
+
{recipients: { cc: "mail@test.example" }}
|
123
|
+
|
124
|
+
resp.should == true
|
125
|
+
end
|
225
126
|
end
|
226
127
|
end
|
227
128
|
end
|