rubill 0.1.8 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 800f1ce2d88c431b7067624e850027a3ee681964
4
- data.tar.gz: 51e152179e7eb31720e45e563757fedfb95c9b4f
3
+ metadata.gz: 4961b00b32927361eb9199a1726a4a15b29b7d01
4
+ data.tar.gz: c83063ee067f7be30d3298b500127c2a28d9dcda
5
5
  SHA512:
6
- metadata.gz: 4dc012e662f35eaab3858451c1d0d6e8a86ed312e6f11fb5f4c8d16afb62af29daef566ae12163717c774a08c7c2156441abd7bd0d1a01295f2b29815b838161
7
- data.tar.gz: b9468482e3a9e7d979de98f9b6d6f8a798aec35d7f40533a39acd6c57ab9e604f486a74e598fc3cc803e14ec797a3d1e785b59058db4a8798997fb1c09f3311e
6
+ metadata.gz: 644255332c3280f3091394e81f988920334e1231636e49c987d41e4fe16632140bb51cab3d0450645e6f669f6877c6a8f7a0290169a8dc4309ebab2c1e2bc3a9
7
+ data.tar.gz: 6e93a600cb3cf3e9852dbd9f3806c216e44c2f056d5b029eb30e646e7d64f52855422b2431a1a28e18be144cd6e2f0365bd3d78a6844e791fc43c8e27361fc00
@@ -1,3 +1,8 @@
1
+ require "rest-client"
2
+ require "json"
3
+ require "singleton"
4
+ require "tempfile"
5
+
1
6
  module Rubill
2
7
  attr_writer :configuration
3
8
 
@@ -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
- Query.upload_attachment({
7
- id: object_id,
8
- fileName: file_name,
9
- document: content,
10
- content: content
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
@@ -0,0 +1,3 @@
1
+ module Rubill
2
+ class ChartOfAccount < Base; end
3
+ end
@@ -0,0 +1,7 @@
1
+ module Rubill
2
+ class GetCheckImageData < Base
3
+ def self.find_by_send_pay_id(sent_pay_id)
4
+ Query.get_check_image_data(sent_pay_id)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rubill
2
+ class GetDisbursementData < Base
3
+ def self.find_by_send_pay_id(sent_pay_id)
4
+ Query.get_disbursement_data(sent_pay_id)
5
+ end
6
+ end
7
+ end
@@ -8,20 +8,24 @@ module Rubill
8
8
  remote_record[:amount]
9
9
  end
10
10
 
11
- def send_email(subject, body, contact_emails)
12
- Query.execute(
13
- "/SendInvoice.json",
14
- {
15
- invoiceId: id,
16
- headers: {
17
- subject: subject,
18
- toEmailAddresses: contact_emails
19
- },
20
- content: {
21
- body: body
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
@@ -45,10 +45,6 @@ module Rubill
45
45
  execute("/RecordAPPayment.json", opts)
46
46
  end
47
47
 
48
- def self.upload_attachment(opts={})
49
- execute("/UploadAttachment.json", opts)
50
- end
51
-
52
48
  def self.void_sent_payment(id)
53
49
  execute("/VoidAPPayment.json", sentPayId: id)
54
50
  end
@@ -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
- data = data.dup
51
- data.delete(:content)
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
- file = file_from_data(data)
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, file = nil)
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
- post_options[:debug_output] = $stdout
68
+ options[:debug_output] = $stdout
95
69
  end
96
70
 
97
- response = RestClient.post(url, post_options)
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.8
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: 2014-10-01 00:00:00.000000000 Z
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: '0'
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: '0'
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: '0'
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: '0'
69
+ version: '10.3'
69
70
  description: A Ruby interface to Bill.com's API
70
- email: andrew.e.taber@gmail.com
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