rubill 0.1.6 → 0.1.7

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: dfa35c17dedae428277fbad66942a6e2e4c1ff45
4
- data.tar.gz: e37d4ddd90ff38b584d20a5fc4caee707aecc08f
3
+ metadata.gz: f96a5cd060d28c4392edf23dc9c628a63d1d860c
4
+ data.tar.gz: 23030225af499e6ef66a6697f5e63d38a99dba9c
5
5
  SHA512:
6
- metadata.gz: 89ec10063490ad9106136d2271d8bd6c33022251e89936c5301f085433f473a393761f914fa6f781407f2dac3b2cc567c1f868e59126f47270dbb3411e8ae939
7
- data.tar.gz: 27a82b53109929435f5058eb97d7182aae018795e6d37de4bf109c49e53b430f7deda1d844f7f1de037c1b30e81a3a9ee30c1d33439810e0bea129607745a17c
6
+ metadata.gz: fc8c0601f8b9b4e832e79fe751a0f7dd6028b295931242722f36b8be839da2c9ead9bf14cfb4799fb633778cd79f612706251320b63e9756c30077785a876446
7
+ data.tar.gz: 6313e9208df792a06532ce0fd718d0722151d21a529a377d1cbfcc39797e2c19b93ada6eceb6c8137e618dbf4fc196573b05e17b227e57c8294bda3313b3b6c7
@@ -43,18 +43,8 @@ module Rubill
43
43
  end
44
44
  end
45
45
 
46
- require "rubill/session"
47
- require "rubill/query"
48
46
  require "rubill/base"
49
- require "rubill/bill"
50
- require "rubill/bill_payment"
51
- require "rubill/invoice"
52
- require "rubill/attachment"
53
- require "rubill/sent_payment"
54
- require "rubill/sent_bill_payment"
55
- require "rubill/received_payment"
56
- require "rubill/vendor"
57
- require "rubill/customer"
58
- require "rubill/customer_contact"
59
- require "rubill/attachment"
47
+ require "rubill/query"
48
+ require "rubill/session"
60
49
 
50
+ Dir["#{File.dirname(__FILE__)}/rubill/entities/*.rb"].each { |f| require f }
@@ -48,6 +48,12 @@ module Rubill
48
48
  Query.delete(remote_class_name, id)
49
49
  end
50
50
 
51
+ def self.find_by_name(name)
52
+ raw_result = Query.list(remote_class_name, 0, 1, [Query::Filter.new("name", "=", name)])
53
+
54
+ new(raw_result.first)
55
+ end
56
+
51
57
  def self.where(filters=[])
52
58
  raise ArgumentError unless filters.is_a?(Enumerable)
53
59
  raise ArgumentError if !filters.is_a?(Hash) && !filters.all? { |f| f.is_a?(Query::Filter) }
@@ -84,7 +90,8 @@ module Rubill
84
90
  private
85
91
 
86
92
  def self.remote_class_name
87
- raise NotImplementedError
93
+ # Assume remote class name is the same as the class name
94
+ self.name.sub('Rubill::', '')
88
95
  end
89
96
  end
90
97
  end
@@ -0,0 +1,3 @@
1
+ module Rubill
2
+ class ActgClass; end
3
+ end
@@ -6,12 +6,9 @@ module Rubill
6
6
  Query.upload_attachment({
7
7
  id: object_id,
8
8
  fileName: file_name,
9
+ document: content,
9
10
  content: content
10
11
  })
11
12
  end
12
-
13
- def self.remote_class_name
14
- "Attachment"
15
- end
16
13
  end
17
14
  end
@@ -3,9 +3,5 @@ module Rubill
3
3
  def self.send_payment(opts)
4
4
  SentPayment.create(opts)
5
5
  end
6
-
7
- def self.remote_class_name
8
- "Bill"
9
- end
10
6
  end
11
7
  end
@@ -3,9 +3,5 @@ module Rubill
3
3
  def self.pay_bills(opts)
4
4
  SentBillPayment.create(opts)
5
5
  end
6
-
7
- def self.remote_class_name
8
- "BillPayment"
9
- end
10
6
  end
11
7
  end
@@ -0,0 +1,7 @@
1
+ module Rubill
2
+ class Customer < Base
3
+ def contacts
4
+ CustomerContact.active_by_customer(id)
5
+ end
6
+ end
7
+ end
@@ -12,9 +12,5 @@ module Rubill
12
12
  ]
13
13
  )
14
14
  end
15
-
16
- def self.remote_class_name
17
- "CustomerContact"
18
- end
19
15
  end
20
16
  end
@@ -38,9 +38,5 @@ module Rubill
38
38
  description: description,
39
39
  }
40
40
  end
41
-
42
- def self.remote_class_name
43
- "Invoice"
44
- end
45
41
  end
46
42
  end
@@ -0,0 +1,3 @@
1
+ module Rubill
2
+ class Item < Base; end
3
+ end
@@ -0,0 +1,3 @@
1
+ module Rubill
2
+ class Location; end
3
+ end
@@ -1,9 +1,5 @@
1
1
  module Rubill
2
2
  class Vendor < Base
3
- def self.remote_class_name
4
- "Vendor"
5
- end
6
-
7
3
  def bills
8
4
  Bill.where([
9
5
  Query::Filter.new("isActive", "=", "1"),
@@ -61,6 +61,14 @@ module Rubill
61
61
  execute("/SendVendorInvite.json", vendorId: vendorId, email: email)
62
62
  end
63
63
 
64
+ def self.get_disbursement_data(id)
65
+ execute("/GetDisbursementData.json", sentPayId: id)
66
+ end
67
+
68
+ def self.get_check_image_data(id)
69
+ execute("/GetCheckImageData.json", sentPayId: id)
70
+ end
71
+
64
72
  def execute
65
73
  Session.instance.execute(self)
66
74
  end
@@ -1,17 +1,16 @@
1
- require "httmultiparty"
1
+ require "rest-client"
2
2
  require "json"
3
3
  require "singleton"
4
+ require "tempfile"
5
+
4
6
 
5
7
  module Rubill
6
8
  class APIError < StandardError; end
7
9
 
8
10
  class Session
9
- include HTTParty
10
11
  include Singleton
11
12
 
12
- attr_accessor :id
13
-
14
- base_uri "https://api.bill.com/api/v2"
13
+ attr_accessor :id, :base_uri
15
14
 
16
15
  def initialize
17
16
  config = self.class.configuration
@@ -20,7 +19,9 @@ module Rubill
20
19
  end
21
20
 
22
21
  if config.sandbox
23
- self.class.base_uri "https://api-stage.bill.com/api/v2"
22
+ self.base_uri = "https://api-stage.bill.com/api/v2"
23
+ else
24
+ self.base_uri = "https://api.bill.com/api/v2"
24
25
  end
25
26
 
26
27
  login
@@ -31,21 +32,23 @@ module Rubill
31
32
  end
32
33
 
33
34
  def login
34
- self.id = self.class.login
35
+ self.id = self.class.login(self.base_uri)
35
36
  end
36
37
 
37
- def self.login
38
+ def self.login(base_uri)
38
39
  login_options = {
39
40
  password: configuration.password,
40
41
  userName: configuration.user_name,
41
42
  devKey: configuration.dev_key,
42
43
  orgId: configuration.org_id,
43
44
  }
44
- login = _post("/Login.json", login_options)
45
+ login = _post(base_uri + "/Login.json", login_options)
45
46
  login[:sessionId]
46
47
  end
47
48
 
48
49
  def options(data={})
50
+ data = data.dup
51
+ data.delete(:content)
49
52
  {
50
53
  sessionId: id,
51
54
  devKey: self.class.configuration.dev_key,
@@ -53,13 +56,22 @@ module Rubill
53
56
  }
54
57
  end
55
58
 
56
- def self.default_headers
57
- {"Content-Type" => "application/x-www-form-urlencoded"}
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
58
67
  end
59
68
 
60
69
  def _post(url, data, retries=0)
61
70
  begin
62
- self.class._post(url, options(data))
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
63
75
  rescue APIError => e
64
76
  if e.message =~ /Session is invalid/ && retries < 3
65
77
  login
@@ -70,23 +82,19 @@ module Rubill
70
82
  end
71
83
  end
72
84
 
73
- def self._post(url, options)
74
- if options.key?(:fileName)
75
- file = StringIO.new(options.delete(:content))
76
- end
77
-
78
- post_options = {
79
- body: options,
80
- headers: default_headers,
81
- }
85
+ def self._post(url, options, file = nil)
86
+ post_options = options
82
87
 
83
- post_options[:file] = file if file
88
+ if file
89
+ post_options[:file] = file
90
+ post_options[:multipart] = true
91
+ end
84
92
 
85
93
  if self.configuration.debug
86
94
  post_options[:debug_output] = $stdout
87
95
  end
88
96
 
89
- response = post(url, post_options)
97
+ response = RestClient.post(url, post_options)
90
98
  result = JSON.parse(response.body, symbolize_names: true)
91
99
 
92
100
  unless result[:response_status] == 0
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubill
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Taber
@@ -11,7 +11,7 @@ cert_chain: []
11
11
  date: 2014-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: httmultiparty
14
+ name: rest-client
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
@@ -73,19 +73,22 @@ extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
75
  - lib/rubill.rb
76
- - lib/rubill/attachment.rb
77
76
  - lib/rubill/base.rb
78
- - lib/rubill/bill.rb
79
- - lib/rubill/bill_payment.rb
80
- - lib/rubill/customer.rb
81
- - lib/rubill/customer_contact.rb
82
- - lib/rubill/invoice.rb
77
+ - lib/rubill/entities/actg_class.rb
78
+ - lib/rubill/entities/attachment.rb
79
+ - lib/rubill/entities/bill.rb
80
+ - lib/rubill/entities/bill_payment.rb
81
+ - lib/rubill/entities/customer.rb
82
+ - lib/rubill/entities/customer_contact.rb
83
+ - lib/rubill/entities/invoice.rb
84
+ - lib/rubill/entities/item.rb
85
+ - lib/rubill/entities/location.rb
86
+ - lib/rubill/entities/received_payment.rb
87
+ - lib/rubill/entities/sent_bill_payment.rb
88
+ - lib/rubill/entities/sent_payment.rb
89
+ - lib/rubill/entities/vendor.rb
83
90
  - lib/rubill/query.rb
84
- - lib/rubill/received_payment.rb
85
- - lib/rubill/sent_bill_payment.rb
86
- - lib/rubill/sent_payment.rb
87
91
  - lib/rubill/session.rb
88
- - lib/rubill/vendor.rb
89
92
  homepage: http://rubygems.org/gems/rubill
90
93
  licenses:
91
94
  - MIT
@@ -106,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
106
109
  version: '0'
107
110
  requirements: []
108
111
  rubyforge_project:
109
- rubygems_version: 2.4.6
112
+ rubygems_version: 2.5.1
110
113
  signing_key:
111
114
  specification_version: 4
112
115
  summary: Interface with Bill.com
@@ -1,15 +0,0 @@
1
- module Rubill
2
- class Customer < Base
3
- def self.find_by_name(name)
4
- where([Query::Filter.new("name", "=", name)]).first
5
- end
6
-
7
- def contacts
8
- CustomerContact.active_by_customer(id)
9
- end
10
-
11
- def self.remote_class_name
12
- "Customer"
13
- end
14
- end
15
- end