rubill 0.1.8 → 0.2.1
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/lib/rubill.rb +5 -0
- data/lib/rubill/entities/attachment.rb +21 -6
- data/lib/rubill/entities/chart_of_account.rb +3 -0
- data/lib/rubill/entities/get_check_image_data.rb +7 -0
- data/lib/rubill/entities/get_disbursement_data.rb +7 -0
- data/lib/rubill/entities/invoice.rb +18 -14
- data/lib/rubill/query.rb +0 -4
- data/lib/rubill/session.rb +7 -33
- metadata +17 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4961b00b32927361eb9199a1726a4a15b29b7d01
|
4
|
+
data.tar.gz: c83063ee067f7be30d3298b500127c2a28d9dcda
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 644255332c3280f3091394e81f988920334e1231636e49c987d41e4fe16632140bb51cab3d0450645e6f669f6877c6a8f7a0290169a8dc4309ebab2c1e2bc3a9
|
7
|
+
data.tar.gz: 6e93a600cb3cf3e9852dbd9f3806c216e44c2f056d5b029eb30e646e7d64f52855422b2431a1a28e18be144cd6e2f0365bd3d78a6844e791fc43c8e27361fc00
|
data/lib/rubill.rb
CHANGED
@@ -3,12 +3,27 @@ require 'base64'
|
|
3
3
|
module Rubill
|
4
4
|
class Attachment < Base
|
5
5
|
def self.send_attachment(object_id, file_name, content)
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
file = Tempfile.new(file_name)
|
7
|
+
|
8
|
+
begin
|
9
|
+
file.write(content)
|
10
|
+
file.rewind
|
11
|
+
|
12
|
+
Query.execute("/UploadAttachment.json", {
|
13
|
+
id: object_id,
|
14
|
+
fileName: file_name,
|
15
|
+
document: content,
|
16
|
+
"_top_level_data" => {
|
17
|
+
file: file,
|
18
|
+
multipart: true
|
19
|
+
}
|
20
|
+
})
|
21
|
+
ensure
|
22
|
+
# Ensure temp file is garbage collected with explicit close
|
23
|
+
# https://ruby-doc.org/stdlib-1.9.3/libdoc/tempfile/rdoc/Tempfile.html
|
24
|
+
file.close
|
25
|
+
file.unlink
|
26
|
+
end
|
12
27
|
end
|
13
28
|
end
|
14
29
|
end
|
@@ -8,20 +8,24 @@ module Rubill
|
|
8
8
|
remote_record[:amount]
|
9
9
|
end
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
11
|
+
##
|
12
|
+
# Send email about invoice to customer
|
13
|
+
#
|
14
|
+
# Bill.com Documentation:
|
15
|
+
# https://developer.bill.com/hc/en-us/articles/208197236
|
16
|
+
#
|
17
|
+
# Possible header keys:
|
18
|
+
# * fromUserId
|
19
|
+
# * toEmailAddresses
|
20
|
+
# * ccMe
|
21
|
+
# * subject
|
22
|
+
#
|
23
|
+
# Will use headers and body from the Default Email Template if
|
24
|
+
# not otherwise specified
|
25
|
+
def send_email(headers = {}, body = nil)
|
26
|
+
options = { headers: headers, content: body ? { body: body } : {}}
|
27
|
+
|
28
|
+
Query.execute("/SendInvoice.json", { invoiceId: id }.merge(options))
|
25
29
|
end
|
26
30
|
|
27
31
|
def amount_due
|
data/lib/rubill/query.rb
CHANGED
data/lib/rubill/session.rb
CHANGED
@@ -1,9 +1,3 @@
|
|
1
|
-
require "rest-client"
|
2
|
-
require "json"
|
3
|
-
require "singleton"
|
4
|
-
require "tempfile"
|
5
|
-
|
6
|
-
|
7
1
|
module Rubill
|
8
2
|
class APIError < StandardError; end
|
9
3
|
|
@@ -47,31 +41,18 @@ module Rubill
|
|
47
41
|
end
|
48
42
|
|
49
43
|
def options(data={})
|
50
|
-
|
51
|
-
|
44
|
+
top_level_data = data.delete("_top_level_data")
|
45
|
+
|
52
46
|
{
|
53
47
|
sessionId: id,
|
54
48
|
devKey: self.class.configuration.dev_key,
|
55
49
|
data: data.to_json,
|
56
|
-
}
|
57
|
-
end
|
58
|
-
|
59
|
-
def file_from_data(data = {})
|
60
|
-
if data && data.is_a?(Hash) && data.key?(:fileName)
|
61
|
-
file = Tempfile.new(data[:fileName])
|
62
|
-
file.write data[:content]
|
63
|
-
file.rewind
|
64
|
-
end
|
65
|
-
|
66
|
-
file
|
50
|
+
}.merge(top_level_data || {})
|
67
51
|
end
|
68
52
|
|
69
53
|
def _post(url, data, retries=0)
|
70
54
|
begin
|
71
|
-
|
72
|
-
response_data = self.class._post(self.base_uri + url, options(data), file)
|
73
|
-
file.close if file
|
74
|
-
response_data
|
55
|
+
self.class._post(self.base_uri + url, options(data))
|
75
56
|
rescue APIError => e
|
76
57
|
if e.message =~ /Session is invalid/ && retries < 3
|
77
58
|
login
|
@@ -82,19 +63,12 @@ module Rubill
|
|
82
63
|
end
|
83
64
|
end
|
84
65
|
|
85
|
-
def self._post(url, options
|
86
|
-
post_options = options
|
87
|
-
|
88
|
-
if file
|
89
|
-
post_options[:file] = file
|
90
|
-
post_options[:multipart] = true
|
91
|
-
end
|
92
|
-
|
66
|
+
def self._post(url, options)
|
93
67
|
if self.configuration.debug
|
94
|
-
|
68
|
+
options[:debug_output] = $stdout
|
95
69
|
end
|
96
70
|
|
97
|
-
response = RestClient.post(url,
|
71
|
+
response = RestClient.post(url, options)
|
98
72
|
result = JSON.parse(response.body, symbolize_names: true)
|
99
73
|
|
100
74
|
unless result[:response_status] == 0
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubill
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Taber
|
8
|
+
- Aleksey Chebotarev
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date:
|
12
|
+
date: 2017-05-30 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: rest-client
|
@@ -42,32 +43,34 @@ dependencies:
|
|
42
43
|
name: rspec
|
43
44
|
requirement: !ruby/object:Gem::Requirement
|
44
45
|
requirements:
|
45
|
-
- - "
|
46
|
+
- - "~>"
|
46
47
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
48
|
+
version: '3.1'
|
48
49
|
type: :development
|
49
50
|
prerelease: false
|
50
51
|
version_requirements: !ruby/object:Gem::Requirement
|
51
52
|
requirements:
|
52
|
-
- - "
|
53
|
+
- - "~>"
|
53
54
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
+
version: '3.1'
|
55
56
|
- !ruby/object:Gem::Dependency
|
56
57
|
name: rake
|
57
58
|
requirement: !ruby/object:Gem::Requirement
|
58
59
|
requirements:
|
59
|
-
- - "
|
60
|
+
- - "~>"
|
60
61
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
62
|
+
version: '10.3'
|
62
63
|
type: :development
|
63
64
|
prerelease: false
|
64
65
|
version_requirements: !ruby/object:Gem::Requirement
|
65
66
|
requirements:
|
66
|
-
- - "
|
67
|
+
- - "~>"
|
67
68
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
69
|
+
version: '10.3'
|
69
70
|
description: A Ruby interface to Bill.com's API
|
70
|
-
email:
|
71
|
+
email:
|
72
|
+
- andrew.e.taber@gmail.com
|
73
|
+
- aleksey.chebotarev@gmail.com
|
71
74
|
executables: []
|
72
75
|
extensions: []
|
73
76
|
extra_rdoc_files: []
|
@@ -78,8 +81,11 @@ files:
|
|
78
81
|
- lib/rubill/entities/attachment.rb
|
79
82
|
- lib/rubill/entities/bill.rb
|
80
83
|
- lib/rubill/entities/bill_payment.rb
|
84
|
+
- lib/rubill/entities/chart_of_account.rb
|
81
85
|
- lib/rubill/entities/customer.rb
|
82
86
|
- lib/rubill/entities/customer_contact.rb
|
87
|
+
- lib/rubill/entities/get_check_image_data.rb
|
88
|
+
- lib/rubill/entities/get_disbursement_data.rb
|
83
89
|
- lib/rubill/entities/invoice.rb
|
84
90
|
- lib/rubill/entities/item.rb
|
85
91
|
- lib/rubill/entities/location.rb
|