business_central 0.9.3
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 +7 -0
- data/.gitignore +37 -0
- data/Gemfile +4 -0
- data/LICENSE +373 -0
- data/README.md +67 -0
- data/Rakefile +41 -0
- data/azure-pipelines.yml +30 -0
- data/business_central.gemspec +31 -0
- data/lib/business_central/account.rb +9 -0
- data/lib/business_central/aged_accounts_payable.rb +10 -0
- data/lib/business_central/aged_accounts_receivable.rb +10 -0
- data/lib/business_central/api_methods.rb +220 -0
- data/lib/business_central/balance_sheet.rb +10 -0
- data/lib/business_central/base.rb +56 -0
- data/lib/business_central/cash_flow_statement.rb +10 -0
- data/lib/business_central/client.rb +128 -0
- data/lib/business_central/company.rb +9 -0
- data/lib/business_central/company_information.rb +10 -0
- data/lib/business_central/countries_region.rb +9 -0
- data/lib/business_central/currency.rb +9 -0
- data/lib/business_central/customer.rb +9 -0
- data/lib/business_central/customer_financial_details.rb +10 -0
- data/lib/business_central/customer_payment.rb +14 -0
- data/lib/business_central/customer_payments_journal.rb +10 -0
- data/lib/business_central/customer_sales.rb +10 -0
- data/lib/business_central/dimension.rb +10 -0
- data/lib/business_central/dimension_line.rb +14 -0
- data/lib/business_central/employee.rb +10 -0
- data/lib/business_central/general_ledger_entry.rb +10 -0
- data/lib/business_central/income_statement.rb +10 -0
- data/lib/business_central/irs_1099_code.rb +10 -0
- data/lib/business_central/item.rb +10 -0
- data/lib/business_central/item_category.rb +10 -0
- data/lib/business_central/journal.rb +10 -0
- data/lib/business_central/journal_line.rb +14 -0
- data/lib/business_central/payment_method.rb +10 -0
- data/lib/business_central/payment_term.rb +10 -0
- data/lib/business_central/picture.rb +10 -0
- data/lib/business_central/purchase_invoice.rb +10 -0
- data/lib/business_central/purchase_invoice_line.rb +43 -0
- data/lib/business_central/request_builder.rb +60 -0
- data/lib/business_central/response/response_handler.rb +57 -0
- data/lib/business_central/retained_earnings_statement.rb +9 -0
- data/lib/business_central/sales_credit_memo.rb +10 -0
- data/lib/business_central/sales_credit_memo_line.rb +14 -0
- data/lib/business_central/sales_invoice.rb +10 -0
- data/lib/business_central/sales_invoice_line.rb +25 -0
- data/lib/business_central/sales_order.rb +9 -0
- data/lib/business_central/sales_order_line.rb +14 -0
- data/lib/business_central/sales_quote.rb +10 -0
- data/lib/business_central/sales_quote_line.rb +14 -0
- data/lib/business_central/shipment_method.rb +10 -0
- data/lib/business_central/subscription.rb +63 -0
- data/lib/business_central/tax_area.rb +10 -0
- data/lib/business_central/tax_group.rb +10 -0
- data/lib/business_central/trial_balance.rb +10 -0
- data/lib/business_central/unit_of_measure.rb +10 -0
- data/lib/business_central/url_builder.rb +33 -0
- data/lib/business_central/vendor.rb +10 -0
- data/lib/business_central/vendor_purchase.rb +10 -0
- data/lib/business_central/version.rb +3 -0
- data/lib/business_central.rb +67 -0
- data/test/business_central/account_test.rb +26 -0
- data/test/business_central/aged_accounts_payable_test.rb +8 -0
- data/test/business_central/aged_accounts_receivable_test.rb +8 -0
- data/test/business_central/base_test.rb +28 -0
- data/test/business_central/company_information_test.rb +8 -0
- data/test/business_central/company_test.rb +27 -0
- data/test/business_central/countries_region_test.rb +69 -0
- data/test/business_central/currency_test.rb +8 -0
- data/test/business_central/customer_financial_details_test.rb +20 -0
- data/test/business_central/customer_payment_test.rb +8 -0
- data/test/business_central/customer_payments_journal_test.rb +8 -0
- data/test/business_central/customer_sales_test.rb +8 -0
- data/test/business_central/customer_test.rb +138 -0
- data/test/business_central/dimension_line_test.rb +8 -0
- data/test/business_central/dimension_test.rb +8 -0
- data/test/business_central/employee_test.rb +8 -0
- data/test/business_central/general_ledger_entry_test.rb +8 -0
- data/test/business_central/income_statement_test.rb +8 -0
- data/test/business_central/irs_1099_code_test.rb +8 -0
- data/test/business_central/item_category_test.rb +8 -0
- data/test/business_central/item_test.rb +8 -0
- data/test/business_central/journal_line_test.rb +8 -0
- data/test/business_central/journal_test.rb +8 -0
- data/test/business_central/payment_method_test.rb +8 -0
- data/test/business_central/payment_term_test.rb +27 -0
- data/test/business_central/picture_test.rb +8 -0
- data/test/business_central/purchase_invoice_line_test.rb +33 -0
- data/test/business_central/purchase_invoice_test.rb +8 -0
- data/test/business_central/request_builder_test.rb +43 -0
- data/test/business_central/response/response_handler_test.rb +58 -0
- data/test/business_central/sales_credit_memo_line_test.rb +8 -0
- data/test/business_central/sales_credit_memo_test.rb +8 -0
- data/test/business_central/sales_invoice_line_test.rb +58 -0
- data/test/business_central/sales_invoice_test.rb +40 -0
- data/test/business_central/sales_order_line_test.rb +8 -0
- data/test/business_central/sales_order_test.rb +32 -0
- data/test/business_central/sales_quote_line_test.rb +8 -0
- data/test/business_central/sales_quote_test.rb +8 -0
- data/test/business_central/shipment_method_test.rb +19 -0
- data/test/business_central/subscription_test.rb +0 -0
- data/test/business_central/tax_area_test.rb +19 -0
- data/test/business_central/tax_group_test.rb +19 -0
- data/test/business_central/trial_balance_test.rb +8 -0
- data/test/business_central/unit_of_measure_test.rb +19 -0
- data/test/business_central/url_builder_test.rb +19 -0
- data/test/business_central/vendor_purchase_test.rb +8 -0
- data/test/business_central/vendor_test.rb +8 -0
- data/test/client_test.rb +72 -0
- data/test/fixtures/filter_customers_200.json +1 -0
- data/test/fixtures/get_account_200.json +1 -0
- data/test/fixtures/get_accounts_200.json +1 -0
- data/test/fixtures/get_companies_200.json +1 -0
- data/test/fixtures/get_company_200.json +1 -0
- data/test/fixtures/get_countriesRegion_200.json +1 -0
- data/test/fixtures/get_countriesRegions_200.json +1 -0
- data/test/fixtures/get_currencies_200.json +1 -0
- data/test/fixtures/get_currency_200.json +1 -0
- data/test/fixtures/get_customer_200.json +1 -0
- data/test/fixtures/get_customer_expanded_200.json +1 -0
- data/test/fixtures/get_customer_financial_details_200.json +1 -0
- data/test/fixtures/get_customers_200.json +1 -0
- data/test/fixtures/get_paymentMethod_200.json +1 -0
- data/test/fixtures/get_paymentMethods_200.json +1 -0
- data/test/fixtures/get_paymentTerm_200.json +1 -0
- data/test/fixtures/get_paymentTerms_200.json +1 -0
- data/test/fixtures/get_purchaseInvoiceLine_200.json +1 -0
- data/test/fixtures/get_purchaseInvoiceLines_200.json +1 -0
- data/test/fixtures/get_purchaseInvoice_200.json +1 -0
- data/test/fixtures/get_purchase_invoices_200.json +1 -0
- data/test/fixtures/get_salesInvoiceLine_200.json +1 -0
- data/test/fixtures/get_salesInvoiceLines_200.json +1 -0
- data/test/fixtures/get_salesInvoiceLines_single_200.json +1 -0
- data/test/fixtures/get_salesInvoice_200.json +1 -0
- data/test/fixtures/get_salesInvoices_200.json +1 -0
- data/test/fixtures/get_salesOrder_200.json +1 -0
- data/test/fixtures/get_salesOrders_200.json +1 -0
- data/test/fixtures/get_shipmentMethods_200.json +1 -0
- data/test/fixtures/get_taxAreas_200.json +1 -0
- data/test/fixtures/get_taxGroups_200.json +1 -0
- data/test/fixtures/get_unitsOfMeasure_200.json +1 -0
- data/test/fixtures/patch_countriesRegion_200.json +1 -0
- data/test/fixtures/patch_customer_200.json +1 -0
- data/test/fixtures/post_countriesRegion_200.json +1 -0
- data/test/fixtures/post_customer_200.json +1 -0
- data/test/fixtures/post_customer_409.json +1 -0
- data/test/fixtures/post_salesInvoiceLine_200.json +1 -0
- data/test/fixtures/post_salesInvoice_200.json +1 -0
- data/test/fixtures/post_subscription_200.json +1 -0
- data/test/test_helper.rb +86 -0
- metadata +408 -0
|
@@ -0,0 +1,220 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Provides an interface between the object methods and the API
|
|
3
|
+
#
|
|
4
|
+
module BusinessCentral
|
|
5
|
+
module ApiMethods
|
|
6
|
+
|
|
7
|
+
# The method_missing method is used to determine if a called method exists
|
|
8
|
+
# in the defined constant for each local object - SUPPORTED_METHODS. This
|
|
9
|
+
# ensures that only supported operations can be called.
|
|
10
|
+
#
|
|
11
|
+
# @param method_name [String]
|
|
12
|
+
# @param args [Array]]
|
|
13
|
+
# @param block [Block]
|
|
14
|
+
#
|
|
15
|
+
def method_missing(method_name, *args, &block)
|
|
16
|
+
if supported_method?(method_name.to_sym)
|
|
17
|
+
self.send(method_name.to_sym, args)
|
|
18
|
+
else
|
|
19
|
+
"#{method_name} is not supported"
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Determines if the GET operation is for all remote objects, a single
|
|
24
|
+
# object, or a single object with optional parameters being supplied
|
|
25
|
+
#
|
|
26
|
+
# When no parameters are supplied, the GET will be for all remote objects
|
|
27
|
+
# eg
|
|
28
|
+
# .get()
|
|
29
|
+
#
|
|
30
|
+
# When one parameter is supplied, the GET will be for the single object
|
|
31
|
+
# eg
|
|
32
|
+
# .get("1234")
|
|
33
|
+
#
|
|
34
|
+
# When more than one parameter is supplied, the GET will be for the single
|
|
35
|
+
# object, and then for the supplied optional parameters
|
|
36
|
+
#
|
|
37
|
+
# An example of the options is
|
|
38
|
+
# .get("1234", "$extended=customerFinancialDetails")
|
|
39
|
+
#
|
|
40
|
+
# @param args [Array]]
|
|
41
|
+
#
|
|
42
|
+
def get(*args)
|
|
43
|
+
case args.length
|
|
44
|
+
when 0
|
|
45
|
+
find_collection
|
|
46
|
+
when 1
|
|
47
|
+
find_by_id(args[0]).first
|
|
48
|
+
else
|
|
49
|
+
find_by_id_with_options(*args).first
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
# Gets a child object, or array of child objects
|
|
54
|
+
#
|
|
55
|
+
# When only the parent_id is supplied, the GET will return all child
|
|
56
|
+
# objects of that parent
|
|
57
|
+
# eg
|
|
58
|
+
# get_child(1234)
|
|
59
|
+
#
|
|
60
|
+
# when both paremeters are present, the GET will return the single child
|
|
61
|
+
# object
|
|
62
|
+
# eg
|
|
63
|
+
# get_child(1234, 4321)
|
|
64
|
+
#
|
|
65
|
+
# @param parent_id [String]
|
|
66
|
+
# @param child_id [String]
|
|
67
|
+
#
|
|
68
|
+
def get_child(parent_id, child_id = nil)
|
|
69
|
+
url = build_url(parent_id, child_id)
|
|
70
|
+
|
|
71
|
+
response = @client.get(url)
|
|
72
|
+
handle_error(response)
|
|
73
|
+
results = process(response)
|
|
74
|
+
|
|
75
|
+
if results.is_a?(Array)
|
|
76
|
+
return results if child_id.nil? || results.length > 1
|
|
77
|
+
return results.first
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Performs a GET operation with a supplied filter string, to search for
|
|
82
|
+
# remote objects.
|
|
83
|
+
#
|
|
84
|
+
# eg
|
|
85
|
+
# .get("'lastModifiedDate lt '2019-01-01T01:01:01+08:00'")
|
|
86
|
+
#
|
|
87
|
+
# @param args [Array]]
|
|
88
|
+
#
|
|
89
|
+
def query(*args)
|
|
90
|
+
response = @client.get("/#{api_object}?$filter=#{args[0]}")
|
|
91
|
+
handle_error(response)
|
|
92
|
+
process(response)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Performs the POST operation on the supplied args
|
|
96
|
+
#
|
|
97
|
+
# @param args [Array]]
|
|
98
|
+
#
|
|
99
|
+
def create(*args)
|
|
100
|
+
return if args.length == 0
|
|
101
|
+
post(args[0]).first
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
# Performs the PATCH operation on the supplied args
|
|
105
|
+
#
|
|
106
|
+
# Expects arguments (id, etag, data)
|
|
107
|
+
#
|
|
108
|
+
# @param args [Array]]
|
|
109
|
+
#
|
|
110
|
+
def update(*args)
|
|
111
|
+
return if args.length == 0
|
|
112
|
+
patch(args[0], args[1], args[2]).first
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Performs the DELETE operation on the supplied args
|
|
116
|
+
#
|
|
117
|
+
# Expects arguments (id, etag)
|
|
118
|
+
#
|
|
119
|
+
# @param args [Array]
|
|
120
|
+
#
|
|
121
|
+
def delete(*args)
|
|
122
|
+
return if args.length == 0
|
|
123
|
+
destroy(args[0], args[1])
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
private
|
|
127
|
+
|
|
128
|
+
# Finds and returns an array of remote objects
|
|
129
|
+
#
|
|
130
|
+
def find_collection
|
|
131
|
+
response = @client.get("/#{api_object}")
|
|
132
|
+
handle_error(response)
|
|
133
|
+
process(response)
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
# Finds and returns the single object
|
|
137
|
+
#
|
|
138
|
+
# @param id [String]
|
|
139
|
+
#
|
|
140
|
+
def find_by_id(id)
|
|
141
|
+
response = @client.get("/#{api_object}(#{id})")
|
|
142
|
+
handle_error(response)
|
|
143
|
+
process(response)
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# Finds and returns the single object, with additional options
|
|
147
|
+
#
|
|
148
|
+
# @param args [Array]
|
|
149
|
+
#
|
|
150
|
+
def find_by_id_with_options(*args)
|
|
151
|
+
id = args[0]
|
|
152
|
+
options = args[1]
|
|
153
|
+
|
|
154
|
+
response = @client.get("/#{api_object}(#{id})?#{options}")
|
|
155
|
+
handle_error(response)
|
|
156
|
+
process(response)
|
|
157
|
+
end
|
|
158
|
+
|
|
159
|
+
# POSTs supplied data to the API
|
|
160
|
+
#
|
|
161
|
+
# @param data [Hash]
|
|
162
|
+
#
|
|
163
|
+
def post(data)
|
|
164
|
+
response = @client.post("/#{api_object}", data)
|
|
165
|
+
handle_error(response)
|
|
166
|
+
process(response)
|
|
167
|
+
end
|
|
168
|
+
|
|
169
|
+
# Performs the PATCH operation
|
|
170
|
+
#
|
|
171
|
+
# @param id [String]
|
|
172
|
+
# @param etag [String]
|
|
173
|
+
# @param data [Hash]
|
|
174
|
+
#
|
|
175
|
+
def patch(id, etag, data)
|
|
176
|
+
response = @client.patch("/#{api_object}(#{id})", etag, data)
|
|
177
|
+
handle_error(response)
|
|
178
|
+
process(response)
|
|
179
|
+
end
|
|
180
|
+
|
|
181
|
+
# Performs the actual DELETE operation
|
|
182
|
+
#
|
|
183
|
+
# @param id [String] the remote object ID
|
|
184
|
+
# @param etag [String] the remote object etag
|
|
185
|
+
#
|
|
186
|
+
# @returns [Net::HTTPResponse.code]
|
|
187
|
+
#
|
|
188
|
+
def destroy(id, etag)
|
|
189
|
+
response = @client.delete("/#{api_object}(#{id})", etag)
|
|
190
|
+
handle_error(response)
|
|
191
|
+
response.code
|
|
192
|
+
end
|
|
193
|
+
|
|
194
|
+
# Each class definition that corresponds to an API endpoint will have
|
|
195
|
+
# a constant defined that identifies the object to call on the API.
|
|
196
|
+
#
|
|
197
|
+
def api_object
|
|
198
|
+
self.class.const_get(:API_OBJECT)
|
|
199
|
+
end
|
|
200
|
+
|
|
201
|
+
# Some API endpoints are for child objects. In those class definitions
|
|
202
|
+
# a constant is defined to identify the parent object
|
|
203
|
+
#
|
|
204
|
+
def api_object_parent
|
|
205
|
+
self.class.const_get(:API_OBJECT_PARENT)
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
# Not all operations are supported on all API endpoints, so each class
|
|
209
|
+
# definition has an array of supported methods defined in a constant. This
|
|
210
|
+
# function determines if the method supplied is supported, after being
|
|
211
|
+
# called by :method_missing
|
|
212
|
+
#
|
|
213
|
+
# @param method [String]
|
|
214
|
+
# @returns [Boolean]
|
|
215
|
+
#
|
|
216
|
+
def supported_method?(method_name)
|
|
217
|
+
self.class.const_get(:SUPPORTED_METHODS).include?(method_name)
|
|
218
|
+
end
|
|
219
|
+
end
|
|
220
|
+
end
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Provides the mechanisms to interact with the BusinessCentral API
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module BusinessCentral
|
|
6
|
+
class Base
|
|
7
|
+
include BusinessCentral::ApiMethods
|
|
8
|
+
|
|
9
|
+
attr_reader :client
|
|
10
|
+
|
|
11
|
+
# The +Base+ class used to provide functionality to subclasses
|
|
12
|
+
#
|
|
13
|
+
# @param client [BusinessCentral::Client]
|
|
14
|
+
#
|
|
15
|
+
def initialize(client)
|
|
16
|
+
@client = client.nil? ? BusinessCentral::Client.new() : client
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Use a BusinessCentral::Response::ResponseHandler to proces the results
|
|
20
|
+
# from the API query
|
|
21
|
+
#
|
|
22
|
+
# @param response [Net::HTTPResponse]
|
|
23
|
+
#
|
|
24
|
+
def process(response)
|
|
25
|
+
BusinessCentral::Response::ResponseHandler.
|
|
26
|
+
new(@client.dataset(response)).
|
|
27
|
+
compiled_data
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
# Use the BusinessCentral::URLBuilder to create the URL to query the API
|
|
31
|
+
#
|
|
32
|
+
# @param parent_id [String] the ID of the parent object
|
|
33
|
+
# @param child_id [String] any additional options
|
|
34
|
+
#
|
|
35
|
+
def build_url(parent_id, child_id = nil)
|
|
36
|
+
options = { child_path: api_object }
|
|
37
|
+
|
|
38
|
+
if !child_id.nil?
|
|
39
|
+
options[:child_id] = child_id
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
BusinessCentral::URLBuilder.new(api_object_parent, parent_id, options).url
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
private
|
|
46
|
+
|
|
47
|
+
# Check to see if the response contains an error and raise an error if
|
|
48
|
+
# required
|
|
49
|
+
#
|
|
50
|
+
# @param response [Net::HTTPResponse]
|
|
51
|
+
#
|
|
52
|
+
def handle_error(response)
|
|
53
|
+
# raise ServiceUnavailableError unless ["200", "201", "204"].include?(response.code)
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
end
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
#.data_store.nil?.data_store.nil?#
|
|
2
|
+
# An object to handle authentication with BusinessCentral and to
|
|
3
|
+
# provide the transport mechanism for interacting with the BusinessCentral API
|
|
4
|
+
#
|
|
5
|
+
module BusinessCentral
|
|
6
|
+
class Client
|
|
7
|
+
attr_reader :api_username, :api_password, :api_tenant, :api_company_id,
|
|
8
|
+
:api_host, :api_version, :api_path
|
|
9
|
+
|
|
10
|
+
# Creates an instance of the BusinessCentral::Client.
|
|
11
|
+
#
|
|
12
|
+
# Pass in a Hash of the various options:
|
|
13
|
+
# api_version: The path of the API Version - eg "/v1.0"
|
|
14
|
+
# api_path: Appended after the API Version - eg "/api/v1.0"
|
|
15
|
+
# api_username: Used for Basic Auth
|
|
16
|
+
# api_password: Used for Basic Auth
|
|
17
|
+
# api_tenant: The tenant domain for your BusinessCentral installation
|
|
18
|
+
# api_company_id: The company that will be queried
|
|
19
|
+
#
|
|
20
|
+
# @param opts [Hash] A Hash with login configuration options
|
|
21
|
+
#
|
|
22
|
+
def initialize(opts = {})
|
|
23
|
+
@api_version = opts[:api_version] ||= BusinessCentral::API_VERSION
|
|
24
|
+
@api_path = opts[:api_path] ||= BusinessCentral::API_PATH
|
|
25
|
+
@api_tenant = opts[:api_tenant] ||= ENV['BC_TENANT']
|
|
26
|
+
@api_username = opts[:api_username] ||= ENV['BC_USERNAME']
|
|
27
|
+
@api_password = opts[:api_password] ||= ENV['BC_PASSWORD']
|
|
28
|
+
@api_company_id = opts[:api_company_id] ||= ENV['BC_COMPANY_ID']
|
|
29
|
+
@api_host = opts[:api_host] ||= ENV['BC_HOST']
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
# Returns the URL used for interacting with the API
|
|
33
|
+
#
|
|
34
|
+
# @returns [String]
|
|
35
|
+
#
|
|
36
|
+
def base_url
|
|
37
|
+
url = "#{@api_host}#{@api_version}/#{@api_tenant}#{@api_path}"
|
|
38
|
+
unless @api_company_id.nil?
|
|
39
|
+
url += "/companies(#{@api_company_id})"
|
|
40
|
+
end
|
|
41
|
+
url
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Performs a GET operation
|
|
45
|
+
#
|
|
46
|
+
# @param url [String] The URL to perform a request on
|
|
47
|
+
# @returns Net::HttpResponse
|
|
48
|
+
#
|
|
49
|
+
def get(url)
|
|
50
|
+
request = build_request({ verb: "Get", url: url })
|
|
51
|
+
perform_request(request)
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
# Performs a POST operation
|
|
55
|
+
#
|
|
56
|
+
# @param url [String] The URL to perform a request on
|
|
57
|
+
# @param data [Hash] The data to POST to the URL
|
|
58
|
+
# @returns Net::HttpResponse
|
|
59
|
+
#
|
|
60
|
+
def post(url, data)
|
|
61
|
+
request = build_request({ verb: "Post", url: url, data: data })
|
|
62
|
+
perform_request(request)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Performs a PATCH operation
|
|
66
|
+
#
|
|
67
|
+
# @param url [String] The URL to perform a request on
|
|
68
|
+
# @param etag [String] The etag of the remote object on BusinessCentral
|
|
69
|
+
# @param data [Hash] The data to PATCH the remote object with
|
|
70
|
+
# @returns Net::HttpResponse
|
|
71
|
+
#
|
|
72
|
+
def patch(url, etag, data)
|
|
73
|
+
request = build_request({ verb: "Patch", url: url, data: data, etag: etag })
|
|
74
|
+
perform_request(request)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Performs a DELETE operation
|
|
78
|
+
#
|
|
79
|
+
# @param url [String] The URL to perform a request on
|
|
80
|
+
# @param etag [String] The etag of the remote object on BusinessCentral
|
|
81
|
+
# @returns Net::HttpResponse
|
|
82
|
+
#
|
|
83
|
+
def delete(url, etag)
|
|
84
|
+
request = build_request({ verb: "Delete", url: url, etag: etag })
|
|
85
|
+
perform_request(request)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def dataset(response)
|
|
89
|
+
json = JSON.parse(response.body)
|
|
90
|
+
if !json["value"].nil?
|
|
91
|
+
json["value"]
|
|
92
|
+
else
|
|
93
|
+
json
|
|
94
|
+
end
|
|
95
|
+
# rescue
|
|
96
|
+
# {}
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
protected
|
|
100
|
+
|
|
101
|
+
# @param url [String] the URL to convert
|
|
102
|
+
# @returns URI [URI]
|
|
103
|
+
#
|
|
104
|
+
def get_uri(url)
|
|
105
|
+
URI(base_url + url)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Build the actual Request object used to perform the operation
|
|
109
|
+
#
|
|
110
|
+
# @param opts [Hash] contains the request information
|
|
111
|
+
# @returns [Net::HTTP::Request]
|
|
112
|
+
#
|
|
113
|
+
def build_request(opts)
|
|
114
|
+
BusinessCentral::RequestBuilder.new(self, opts).request
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Performs the actual operation
|
|
118
|
+
#
|
|
119
|
+
# @param request [Net::HTTP::Request]
|
|
120
|
+
# @returns [Net::HTTP::Response]
|
|
121
|
+
#
|
|
122
|
+
def perform_request(request)
|
|
123
|
+
Net::HTTP.start(request.uri.hostname, request.uri.port, use_ssl: true) do |http|
|
|
124
|
+
http.request(request)
|
|
125
|
+
end
|
|
126
|
+
end
|
|
127
|
+
end
|
|
128
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Provides access to the /customerPaymentsJournal/{Id}/customerPayments API
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module BusinessCentral
|
|
6
|
+
class CustomerPayment < BusinessCentral::Base
|
|
7
|
+
API_OBJECT_PARENT = "customerPaymentsJournal"
|
|
8
|
+
API_OBJECT = "customerPayments"
|
|
9
|
+
|
|
10
|
+
def get(customer_payments_journal_id, customer_payment_id = nil)
|
|
11
|
+
get_child(customer_payments_journal_id, customer_payment_id)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Provides access to the /dimensions/{Id}/dimensionsLine API
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module BusinessCentral
|
|
6
|
+
class DimensionLine < BusinessCentral::Base
|
|
7
|
+
API_OBJECT_PARENT = "dimensions"
|
|
8
|
+
API_OBJECT = "dimensionLines"
|
|
9
|
+
|
|
10
|
+
def get(dimension_id, dimension_line_id=nil)
|
|
11
|
+
get_child(dimension_id, dimension_line_id)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
##
|
|
2
|
+
# Provides access to the /journals/{Id}/journalLines API
|
|
3
|
+
#
|
|
4
|
+
|
|
5
|
+
module BusinessCentral
|
|
6
|
+
class JournalLine < BusinessCentral::Base
|
|
7
|
+
API_OBJECT_PARENT = "journals"
|
|
8
|
+
API_OBJECT = "journalLines"
|
|
9
|
+
|
|
10
|
+
def get(journal_id, journal_line_id=nil)
|
|
11
|
+
get_child(journal_id, journal_line_id)
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
end
|