rentvine 0.1.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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.rspec +4 -0
  3. data/.rubocop.yml +704 -0
  4. data/.ruby-gemset +1 -0
  5. data/.ruby-version +1 -0
  6. data/CHANGELOG.md +5 -0
  7. data/CODE_OF_CONDUCT.md +84 -0
  8. data/Gemfile +11 -0
  9. data/Gemfile.lock +75 -0
  10. data/LICENSE.txt +21 -0
  11. data/README.md +152 -0
  12. data/Rakefile +8 -0
  13. data/bin/console +15 -0
  14. data/bin/setup +8 -0
  15. data/examples/accounts.rb +17 -0
  16. data/examples/applications.rb +19 -0
  17. data/examples/associations.rb +17 -0
  18. data/examples/bills.rb +54 -0
  19. data/examples/diagnostics.rb +67 -0
  20. data/examples/files.rb +37 -0
  21. data/examples/inspections.rb +37 -0
  22. data/examples/leases.rb +23 -0
  23. data/examples/ledgers.rb +28 -0
  24. data/examples/object_types.rb +15 -0
  25. data/examples/owners.rb +17 -0
  26. data/examples/portfolios.rb +17 -0
  27. data/examples/properties.rb +75 -0
  28. data/examples/tenants.rb +17 -0
  29. data/examples/transaction_entries.rb +17 -0
  30. data/examples/transactions.rb +17 -0
  31. data/examples/units.rb +29 -0
  32. data/examples/vendor_trades.rb +36 -0
  33. data/examples/vendors.rb +17 -0
  34. data/examples/work_order_statuses.rb +36 -0
  35. data/examples/work_orders.rb +42 -0
  36. data/lib/rentvine/client/accounts.rb +13 -0
  37. data/lib/rentvine/client/applications.rb +18 -0
  38. data/lib/rentvine/client/associations.rb +13 -0
  39. data/lib/rentvine/client/bills.rb +32 -0
  40. data/lib/rentvine/client/diagnostics.rb +81 -0
  41. data/lib/rentvine/client/files.rb +37 -0
  42. data/lib/rentvine/client/inspections.rb +27 -0
  43. data/lib/rentvine/client/leases.rb +20 -0
  44. data/lib/rentvine/client/ledgers.rb +25 -0
  45. data/lib/rentvine/client/owners.rb +13 -0
  46. data/lib/rentvine/client/portfolios.rb +19 -0
  47. data/lib/rentvine/client/properties.rb +49 -0
  48. data/lib/rentvine/client/tenants.rb +13 -0
  49. data/lib/rentvine/client/transaction_entries.rb +25 -0
  50. data/lib/rentvine/client/transactions.rb +21 -0
  51. data/lib/rentvine/client/units.rb +20 -0
  52. data/lib/rentvine/client/vendor_trades.rb +27 -0
  53. data/lib/rentvine/client/vendors.rb +13 -0
  54. data/lib/rentvine/client/work_order_statuses.rb +30 -0
  55. data/lib/rentvine/client/work_orders.rb +27 -0
  56. data/lib/rentvine/client.rb +149 -0
  57. data/lib/rentvine/model/account.rb +7 -0
  58. data/lib/rentvine/model/application.rb +7 -0
  59. data/lib/rentvine/model/association.rb +7 -0
  60. data/lib/rentvine/model/bill.rb +7 -0
  61. data/lib/rentvine/model/diagnostic.rb +7 -0
  62. data/lib/rentvine/model/file.rb +7 -0
  63. data/lib/rentvine/model/inspection.rb +7 -0
  64. data/lib/rentvine/model/lease.rb +7 -0
  65. data/lib/rentvine/model/ledger.rb +7 -0
  66. data/lib/rentvine/model/owner.rb +7 -0
  67. data/lib/rentvine/model/portfolio.rb +7 -0
  68. data/lib/rentvine/model/property.rb +16 -0
  69. data/lib/rentvine/model/rentvine_model.rb +26 -0
  70. data/lib/rentvine/model/tenant.rb +7 -0
  71. data/lib/rentvine/model/transaction.rb +7 -0
  72. data/lib/rentvine/model/transaction_entry.rb +7 -0
  73. data/lib/rentvine/model/unit.rb +7 -0
  74. data/lib/rentvine/model/vendor.rb +7 -0
  75. data/lib/rentvine/model/vendor_trade.rb +7 -0
  76. data/lib/rentvine/model/work_order.rb +7 -0
  77. data/lib/rentvine/model/work_order_status.rb +7 -0
  78. data/lib/rentvine/rentvine_error.rb +61 -0
  79. data/lib/rentvine/rentvine_object_types.rb +57 -0
  80. data/lib/rentvine/version.rb +5 -0
  81. data/lib/rentvine.rb +14 -0
  82. data/rentvine.gemspec +34 -0
  83. metadata +185 -0
@@ -0,0 +1,19 @@
1
+ module Rentvine
2
+ class Client
3
+ module Portfolios
4
+ def portfolios(args = {})
5
+ results = process_request(:get, 'portfolios/search', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map do |result|
9
+ rvobj = Rentvine::Portfolio.new(result[:portfolio])
10
+ rvobj.statement_setting = result[:statement_setting]
11
+ rvobj.last_statement = result[:last_statement]
12
+ rvobj.meta = { appends: [:statement_setting, :last_statement] }
13
+ rvobj
14
+ end
15
+ end
16
+ alias list_portfolios portfolios
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,49 @@
1
+ module Rentvine
2
+ class Client
3
+ module Properties
4
+ def properties(args = {})
5
+ results = process_request(:get, 'properties', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::Property.new(result[:property]) }
9
+ end
10
+ alias list_properties properties
11
+
12
+ def property(property_id)
13
+ result = process_request(:get, "properties/#{property_id}")
14
+ return result if result.is_a?(RentvineError)
15
+
16
+ Rentvine::Property.new(result[:property])
17
+ end
18
+
19
+ def save_property(property_model)
20
+ url_to_use = property_model.property_id.nil? ? 'properties' : "properties/#{property_model.property_id}"
21
+ result = process_request(:post, url_to_use, body: property_model.to_rentvine_hash)
22
+ return result if result.is_a?(RentvineError)
23
+
24
+ Rentvine::Property.new(result[:property])
25
+ end
26
+
27
+ def delete_property(property_id)
28
+ result = process_request(:delete, "properties/#{property_id}")
29
+ return result if result.is_a?(RentvineError)
30
+
31
+ true
32
+ end
33
+
34
+ def activate_property(property_id)
35
+ result = process_request(:post, "properties/#{property_id}/activate")
36
+ return result if result.is_a?(RentvineError)
37
+
38
+ true
39
+ end
40
+
41
+ def deactivate_property(property_id)
42
+ result = process_request(:post, "properties/#{property_id}/deactivate")
43
+ return result if result.is_a?(RentvineError)
44
+
45
+ true
46
+ end
47
+ end
48
+ end
49
+ end
@@ -0,0 +1,13 @@
1
+ module Rentvine
2
+ class Client
3
+ module Tenants
4
+ def tenants(args = {})
5
+ results = process_request(:get, 'tenants/search', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::Tenant.new(result[:contact]) }
9
+ end
10
+ alias list_tenants tenants
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,25 @@
1
+ module Rentvine
2
+ class Client
3
+ module TransactionEntries
4
+ def transaction_entries(args = {})
5
+ results = process_request(:get, 'accounting/transactions/entries/search', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::TransactionEntry.new(result[:transaction_entry]) }
9
+
10
+ results.map do |result|
11
+ rvobj = Rentvine::TransactionEntry.new(result[:transaction_entry])
12
+ rvobj.ledger = Rentvine::Ledger.new(result[:ledger])
13
+ rvobj.portfolio = Rentvine::Portfolio.new(result[:portfolio])
14
+ rvobj.primary_ledger = Rentvine::Ledger.new(result[:primary_ledger])
15
+ rvobj.property = Rentvine::Property.new(result[:property])
16
+ rvobj.transaction = Rentvine::Transaction.new(result[:transaction])
17
+ rvobj.unit = Rentvine::Unit.new(result[:unit])
18
+ rvobj.meta = { appends: [:ledger, :portfolio, :primary_ledger, :property, :transaction, :unit] }
19
+ rvobj
20
+ end
21
+ end
22
+ alias list_transaction_entries transaction_entries
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ module Rentvine
2
+ class Client
3
+ module Transactions
4
+ def transactions(args = {})
5
+ results = process_request(:get, 'accounting/transactions/search', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map do |result|
9
+ rvobj = Rentvine::Transaction.new(result[:transaction])
10
+ rvobj.ledger = Rentvine::Ledger.new(result[:ledger])
11
+ rvobj.portfolio = Rentvine::Portfolio.new(result[:portfolio])
12
+ rvobj.unit = Rentvine::Unit.new(result[:unit])
13
+ rvobj.transaction_entries = Rentvine::TransactionEntry.new(result[:transaction_entries])
14
+ rvobj.meta = { appends: [:ledger, :portfolio, :unit, :transaction_entries] }
15
+ rvobj
16
+ end
17
+ end
18
+ alias list_transactions transactions
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,20 @@
1
+ module Rentvine
2
+ class Client
3
+ module Units
4
+ def units(property_id, args = {})
5
+ results = process_request(:get, "properties/#{property_id}/units", params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::Unit.new(result[:unit]) }
9
+ end
10
+ alias list_units units
11
+
12
+ def unit(property_id, unit_id)
13
+ result = process_request(:get, "properties/#{property_id}/units/#{unit_id}")
14
+ return result if result.is_a?(RentvineError)
15
+
16
+ Rentvine::Unit.new(result[:unit])
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,27 @@
1
+ module Rentvine
2
+ class Client
3
+ module VendorTrades
4
+ def vendor_trades(args = {})
5
+ results = process_request(:get, 'maintenance/vendor-trades', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::VendorTrade.new(result[:vendor_trade]) }
9
+ end
10
+ alias list_vendor_trades vendor_trades
11
+
12
+ def vendor_trade(vendor_trade_id)
13
+ result = process_request(:get, "maintenance/vendor-trades/#{vendor_trade_id}")
14
+ return result if result.is_a?(RentvineError)
15
+
16
+ Rentvine::VendorTrade.new(result[:vendor_trade])
17
+ end
18
+
19
+ def save_vendor_trade(vendor_trade_model)
20
+ result = process_request(:post, '/maintenance/vendor-trades', body: vendor_trade_model.to_rentvine_hash)
21
+ return result if result.is_a?(RentvineError)
22
+
23
+ Rentvine::VendorTrade.new(result[:vendor_trade])
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,13 @@
1
+ module Rentvine
2
+ class Client
3
+ module Vendors
4
+ def vendors(args = {})
5
+ results = process_request(:get, 'vendors/search', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::Vendor.new(result[:contact]) }
9
+ end
10
+ alias list_vendors vendors
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,30 @@
1
+ module Rentvine
2
+ class Client
3
+ module WorkOrderStatuses
4
+ def work_order_statuses(args = {})
5
+ results = process_request(:get, 'maintenance/work-order/statuses', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::WorkOrderStatus.new(result[:work_order_status]) }
9
+ end
10
+ alias list_work_order_statuses work_order_statuses
11
+
12
+ def work_order_status(work_order_status_id)
13
+ result = process_request(:get, "maintenance/work-order/statuses/#{work_order_status_id}")
14
+ return result if result.is_a?(RentvineError)
15
+
16
+ Rentvine::WorkOrderStatus.new(result[:work_order_status])
17
+ end
18
+
19
+ def save_work_order_status(work_order_status_model)
20
+ result = process_request(
21
+ :post, '/maintenance/work-order/statuses',
22
+ body: work_order_status_model.to_rentvine_hash
23
+ )
24
+ return result if result.is_a?(RentvineError)
25
+
26
+ Rentvine::WorkOrderStatus.new(result[:work_order_status])
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ module Rentvine
2
+ class Client
3
+ module WorkOrders
4
+ def work_orders(args = {})
5
+ results = process_request(:get, 'maintenance/work-orders', params: args)
6
+ return results if results.is_a?(RentvineError)
7
+
8
+ results.map { |result| Rentvine::WorkOrder.new(result[:work_order]) }
9
+ end
10
+ alias list_work_orders work_orders
11
+
12
+ def work_order(work_order_id)
13
+ result = process_request(:get, "maintenance/work-orders/#{work_order_id}")
14
+ return result if result.is_a?(RentvineError)
15
+
16
+ Rentvine::WorkOrder.new(result[:work_order])
17
+ end
18
+
19
+ def save_work_order(work_order_model)
20
+ result = process_request(:post, '/maintenance/work-orders', body: work_order_model.to_rentvine_hash)
21
+ return result if result.is_a?(RentvineError)
22
+
23
+ Rentvine::WorkOrder.new(result[:work_order])
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,149 @@
1
+ require_relative 'client/accounts'
2
+ require_relative 'client/applications'
3
+ require_relative 'client/associations'
4
+ require_relative 'client/bills'
5
+ require_relative 'client/diagnostics'
6
+ require_relative 'client/files'
7
+ require_relative 'client/inspections'
8
+ require_relative 'client/leases'
9
+ require_relative 'client/ledgers'
10
+ require_relative 'client/owners'
11
+ require_relative 'client/portfolios'
12
+ require_relative 'client/properties'
13
+ require_relative 'client/tenants'
14
+ require_relative 'client/transaction_entries'
15
+ require_relative 'client/transactions'
16
+ require_relative 'client/units'
17
+ require_relative 'client/vendor_trades'
18
+ require_relative 'client/vendors'
19
+ require_relative 'client/work_order_statuses'
20
+ require_relative 'client/work_orders'
21
+
22
+ require_relative 'model/rentvine_model'
23
+ require_relative 'model/account'
24
+ require_relative 'model/application'
25
+ require_relative 'model/association'
26
+ require_relative 'model/bill'
27
+ require_relative 'model/diagnostic'
28
+ require_relative 'model/file'
29
+ require_relative 'model/inspection'
30
+ require_relative 'model/lease'
31
+ require_relative 'model/ledger'
32
+ require_relative 'model/owner'
33
+ require_relative 'model/portfolio'
34
+ require_relative 'model/property'
35
+ require_relative 'model/tenant'
36
+ require_relative 'model/transaction_entry'
37
+ require_relative 'model/transaction'
38
+ require_relative 'model/unit'
39
+ require_relative 'model/vendor_trade'
40
+ require_relative 'model/vendor'
41
+ require_relative 'model/work_order_status'
42
+ require_relative 'model/work_order'
43
+
44
+ module Rentvine
45
+ class Client
46
+ include Rentvine::Client::Accounts
47
+ include Rentvine::Client::Applications
48
+ include Rentvine::Client::Associations
49
+ include Rentvine::Client::Bills
50
+ include Rentvine::Client::Diagnostics
51
+ include Rentvine::Client::Files
52
+ include Rentvine::Client::Inspections
53
+ include Rentvine::Client::Leases
54
+ include Rentvine::Client::Ledgers
55
+ include Rentvine::Client::Owners
56
+ include Rentvine::Client::Portfolios
57
+ include Rentvine::Client::Properties
58
+ include Rentvine::Client::Tenants
59
+ include Rentvine::Client::TransactionEntries
60
+ include Rentvine::Client::Transactions
61
+ include Rentvine::Client::Units
62
+ include Rentvine::Client::VendorTrades
63
+ include Rentvine::Client::Vendors
64
+ include Rentvine::Client::WorkOrderStatuses
65
+ include Rentvine::Client::WorkOrders
66
+
67
+ def initialize(auth = nil)
68
+ @auth = auth || load_from_environment
69
+
70
+ if @auth.nil?
71
+ raise RentvineError, 'API authentication incomplete! You need the account code, api key and api secret.'
72
+ end
73
+ end
74
+
75
+ private
76
+
77
+ def load_from_environment
78
+ return if ENV['RENTVINE_ACCOUNT_CODE'].nil? || ENV['RENTVINE_API_KEY'].nil? || ENV['RENTVINE_API_SECRET'].nil?
79
+
80
+ {
81
+ account_code: ENV['RENTVINE_ACCOUNT_CODE'],
82
+ api_key: ENV['RENTVINE_API_KEY'],
83
+ api_secret: ENV['RENTVINE_API_SECRET']
84
+ }
85
+ end
86
+
87
+ def process_file(file_path, params)
88
+ request_params = {
89
+ method: :post,
90
+ params: params.to_camelback_keys,
91
+ headers: {
92
+ "Content-Type" => "multipart/form-data",
93
+ 'Authorization' => "Basic #{rentvine_basic_auth}"
94
+ },
95
+ body: { file: File.open(file_path) }
96
+ }
97
+
98
+ proxy = @auth[:proxy] || ENV['PROXY']
99
+ request_params[:proxy] = proxy unless proxy.nil?
100
+
101
+ response = Typhoeus::Request.new(
102
+ "https://#{@auth[:account_code]}.rentvine.com/api/manager/files",
103
+ request_params
104
+ ).run
105
+ return RentvineError.new(response) unless response.success?
106
+
107
+ process_rentvine_response(response)
108
+ end
109
+
110
+ def process_rentvine_response(response)
111
+ JSON.parse(response.body, symbolize_names: true).to_snake_keys
112
+ rescue
113
+ response.body
114
+ end
115
+
116
+ def process_request(request_type, url_path, options = {})
117
+ options_params = options[:params] || {}
118
+ request_params = {
119
+ method: request_type,
120
+ params: options_params.to_camelback_keys,
121
+ headers: rentvine_auth_headers,
122
+ body: options[:body]&.to_json
123
+ }
124
+
125
+ proxy = @auth[:proxy] || ENV['PROXY']
126
+ request_params[:proxy] = proxy unless proxy.nil?
127
+
128
+ response = Typhoeus::Request.new(
129
+ "https://#{@auth[:account_code]}.rentvine.com/api/manager/#{url_path}",
130
+ request_params
131
+ ).run
132
+ return RentvineError.new(response) unless response.success?
133
+
134
+ process_rentvine_response(response)
135
+ end
136
+
137
+ def rentvine_auth_headers
138
+ {
139
+ 'Content-Type' => 'application/json',
140
+ 'charset' => 'utf-8',
141
+ 'Authorization' => "Basic #{rentvine_basic_auth}"
142
+ }
143
+ end
144
+
145
+ def rentvine_basic_auth
146
+ Base64.strict_encode64("#{@auth[:api_key]}:#{@auth[:api_secret]}")
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Account < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Application < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Association < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Bill < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Diagnostic < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class File < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Inspection < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Lease < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Ledger < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Owner < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Portfolio < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,16 @@
1
+ module Rentvine
2
+ class Property < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+
7
+ def to_rentvine_hash
8
+ retval = super()
9
+ unit = retval.delete(:unit)
10
+ {
11
+ property: retval,
12
+ unit: unit
13
+ }
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,26 @@
1
+ module Rentvine
2
+ class RentvineModel < OpenStruct
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+
7
+ def to_rentvine_hash
8
+ data_hash = to_h
9
+
10
+ # Remove custom appends from the hash
11
+ meta&.dig(:appends)&.each { |key| data_hash.delete(key) }
12
+ data_hash.delete(:meta)
13
+
14
+ data_hash = data_hash.to_camelback_keys
15
+
16
+ data_hash.keys.each do |key|
17
+ next if (key.to_s =~ /Id$/).nil?
18
+
19
+ new_key = key.to_s.gsub(/Id$/, 'ID')
20
+ data_hash[new_key.to_sym] = data_hash.delete(key)
21
+ end
22
+
23
+ data_hash.to_camelback_keys
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Tenant < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Transaction < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class TransactionEntry < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Unit < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class Vendor < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class VendorTrade < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class WorkOrder < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,7 @@
1
+ module Rentvine
2
+ class WorkOrderStatus < RentvineModel
3
+ def initialize(data = {})
4
+ super(data)
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rentvine
4
+ class RentvineError < StandardError
5
+ attr_reader :error
6
+ attr_reader :raw
7
+ attr_reader :response_code
8
+
9
+ def initialize(http_response)
10
+ @raw = http_response
11
+ @response_code = @raw.response_code
12
+
13
+ data = process_response_body
14
+ if data.nil?
15
+ set_default_error_message
16
+ else
17
+ @error = data
18
+ end
19
+ end
20
+
21
+ def error?
22
+ true
23
+ end
24
+
25
+ def to_s
26
+ return remove_extra_quotes(@error) if @error.is_a?(String)
27
+
28
+ retval = @error.each_with_object([]) do |(key, value), str|
29
+ str_value = value.is_a?(Array) ? value.join(', ') : value
30
+ str_value = remove_extra_quotes(str_value)
31
+ str << "#{key}: #{str_value}"
32
+ end
33
+ retval.join(', ')
34
+ end
35
+ alias message to_s
36
+
37
+ private
38
+
39
+ def remove_extra_quotes(str)
40
+ str.tr('"', '')
41
+ end
42
+
43
+ def process_response_body
44
+ JSON.parse(@raw.body, symbolize_names: true).to_snake_keys unless @raw.body.empty?
45
+ rescue StandardError
46
+ @raw.body.strip
47
+ end
48
+
49
+ def set_default_error_message
50
+ require 'uri'
51
+ api_path = URI.parse(@raw.effective_url).path
52
+ @error = "Rentvine API returned an error for #{api_path}."
53
+
54
+ if @response_code == 401
55
+ @error += ' Please check your credentials.'
56
+ elsif @response_code == 404
57
+ @error += ' Please check your API path.'
58
+ end
59
+ end
60
+ end
61
+ end