business-central 1.0.1 → 1.0.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +58 -15
- data/lib/business_central.rb +47 -2
- data/lib/business_central/client.rb +82 -39
- data/lib/business_central/exceptions.rb +30 -10
- data/lib/business_central/object/account.rb +4 -12
- data/lib/business_central/object/aged_account_payable.rb +4 -12
- data/lib/business_central/object/aged_account_receivable.rb +4 -12
- data/lib/business_central/object/argument_helper.rb +22 -0
- data/lib/business_central/object/attachment.rb +30 -0
- data/lib/business_central/object/balance_sheet.rb +4 -12
- data/lib/business_central/object/base.rb +100 -49
- data/lib/business_central/object/cash_flow_statement.rb +4 -12
- data/lib/business_central/object/company.rb +9 -2
- data/lib/business_central/object/company_information.rb +7 -15
- data/lib/business_central/object/country_region.rb +26 -0
- data/lib/business_central/object/currency.rb +29 -0
- data/lib/business_central/object/customer.rb +34 -0
- data/lib/business_central/object/customer_financial_detail.rb +13 -0
- data/lib/business_central/object/customer_payment.rb +43 -0
- data/lib/business_central/object/customer_payment_journal.rb +25 -0
- data/lib/business_central/object/customer_sale.rb +13 -0
- data/lib/business_central/object/default_dimension.rb +51 -0
- data/lib/business_central/object/dimension.rb +20 -0
- data/lib/business_central/object/dimension_line.rb +37 -0
- data/lib/business_central/object/dimension_value.rb +28 -0
- data/lib/business_central/object/employee.rb +21 -0
- data/lib/business_central/object/filter_query.rb +18 -0
- data/lib/business_central/object/general_ledger_entry.rb +13 -0
- data/lib/business_central/object/income_statement.rb +13 -0
- data/lib/business_central/object/irs1099_code.rb +16 -0
- data/lib/business_central/object/item.rb +16 -19
- data/lib/business_central/object/item_category.rb +16 -0
- data/lib/business_central/object/journal.rb +29 -0
- data/lib/business_central/object/journal_line.rb +48 -0
- data/lib/business_central/object/object_helper.rb +49 -0
- data/lib/business_central/object/payment_method.rb +16 -0
- data/lib/business_central/object/payment_term.rb +16 -0
- data/lib/business_central/object/picture.rb +53 -0
- data/lib/business_central/object/purchase_invoice.rb +8 -16
- data/lib/business_central/object/purchase_invoice_line.rb +14 -18
- data/lib/business_central/object/request.rb +61 -50
- data/lib/business_central/object/response.rb +31 -23
- data/lib/business_central/object/retained_earning_statement.rb +13 -0
- data/lib/business_central/object/sales_credit_memo.rb +20 -0
- data/lib/business_central/object/sales_credit_memo_line.rb +30 -0
- data/lib/business_central/object/sales_invoice.rb +62 -0
- data/lib/business_central/object/sales_invoice_line.rb +30 -0
- data/lib/business_central/object/sales_order.rb +20 -0
- data/lib/business_central/object/sales_order_line.rb +30 -0
- data/lib/business_central/object/sales_quote.rb +20 -0
- data/lib/business_central/object/sales_quote_line.rb +30 -0
- data/lib/business_central/object/shipment_method.rb +16 -0
- data/lib/business_central/object/subscription.rb +16 -0
- data/lib/business_central/object/tax_area.rb +16 -0
- data/lib/business_central/object/tax_group.rb +16 -0
- data/lib/business_central/object/time_registration_entry.rb +16 -0
- data/lib/business_central/object/trial_balance.rb +13 -0
- data/lib/business_central/object/units_of_measure.rb +16 -0
- data/lib/business_central/object/url_builder.rb +59 -0
- data/lib/business_central/object/url_helper.rb +44 -0
- data/lib/business_central/object/validation.rb +10 -7
- data/lib/business_central/object/vendor.rb +12 -15
- data/lib/business_central/object/vendor_purchase.rb +13 -0
- data/lib/business_central/version.rb +4 -2
- data/lib/business_central/web_service.rb +78 -0
- data/lib/core_ext/string.rb +18 -12
- data/test/business_central/client_test.rb +49 -7
- data/test/business_central/object/account_test.rb +6 -5
- data/test/business_central/object/aged_account_payable_test.rb +6 -5
- data/test/business_central/object/aged_account_receivable_test.rb +6 -5
- data/test/business_central/object/attachment_test.rb +117 -0
- data/test/business_central/object/balance_sheet_test.rb +6 -5
- data/test/business_central/object/base_test.rb +41 -0
- data/test/business_central/object/cash_flow_statement_test.rb +6 -5
- data/test/business_central/object/company_information_test.rb +9 -10
- data/test/business_central/object/company_test.rb +6 -5
- data/test/business_central/object/country_region_test.rb +129 -0
- data/test/business_central/object/currency_test.rb +150 -0
- data/test/business_central/object/customer_financial_detail_test.rb +68 -0
- data/test/business_central/object/customer_payment_journal_test.rb +134 -0
- data/test/business_central/object/customer_payment_test.rb +141 -0
- data/test/business_central/object/customer_sale_test.rb +72 -0
- data/test/business_central/object/customer_test.rb +168 -0
- data/test/business_central/object/default_dimension_test.rb +170 -0
- data/test/business_central/object/dimension_line_test.rb +165 -0
- data/test/business_central/object/dimension_test.rb +65 -0
- data/test/business_central/object/dimension_value_test.rb +68 -0
- data/test/business_central/object/employee_test.rb +141 -0
- data/test/business_central/object/filter_query_test.rb +36 -0
- data/test/business_central/object/general_ledger_entry_test.rb +82 -0
- data/test/business_central/object/income_statement_test.rb +82 -0
- data/test/business_central/object/irs1099_code_test.rb +124 -0
- data/test/business_central/object/item_category_test.rb +122 -0
- data/test/business_central/object/item_test.rb +16 -17
- data/test/business_central/object/journal_line_test.rb +152 -0
- data/test/business_central/object/journal_test.rb +144 -0
- data/test/business_central/object/payment_method_test.rb +134 -0
- data/test/business_central/object/payment_term_test.rb +134 -0
- data/test/business_central/object/picture_test.rb +74 -0
- data/test/business_central/object/purchase_invoice_line_test.rb +15 -15
- data/test/business_central/object/purchase_invoice_test.rb +15 -15
- data/test/business_central/object/request_test.rb +75 -12
- data/test/business_central/object/response_test.rb +34 -9
- data/test/business_central/object/retained_earning_statement_test.rb +52 -0
- data/test/business_central/object/sales_credit_memo_line_test.rb +134 -0
- data/test/business_central/object/sales_credit_memo_test.rb +146 -0
- data/test/business_central/object/sales_invoice_line_test.rb +164 -0
- data/test/business_central/object/sales_invoice_test.rb +156 -0
- data/test/business_central/object/sales_order_line_test.rb +134 -0
- data/test/business_central/object/sales_order_test.rb +146 -0
- data/test/business_central/object/sales_quote_line_test.rb +134 -0
- data/test/business_central/object/sales_quote_test.rb +146 -0
- data/test/business_central/object/shipment_method_test.rb +133 -0
- data/test/business_central/object/subscription_test.rb +126 -0
- data/test/business_central/object/tax_area_test.rb +126 -0
- data/test/business_central/object/tax_group_test.rb +126 -0
- data/test/business_central/object/time_registration_entry_test.rb +126 -0
- data/test/business_central/object/trial_balance_test.rb +82 -0
- data/test/business_central/object/units_of_measure_test.rb +126 -0
- data/test/business_central/object/validation_test.rb +5 -4
- data/test/business_central/object/vendor_purchase_test.rb +82 -0
- data/test/business_central/object/vendor_test.rb +16 -16
- data/test/business_central/web_service_test.rb +100 -0
- data/test/business_central_test.rb +3 -1
- data/test/test_helper.rb +16 -6
- metadata +188 -37
- data/lib/business_central/object/helper.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8a9fce53948fe9fcc7fead040e9f2a3c11df882dc59ebe5db8add78fe4b9c396
|
4
|
+
data.tar.gz: 34c62baa8d371b776fae566c97c935467c7c3ee86cd2d3d36c4a22824257c16e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d2acefa8f9086e59343fa0d25ff74f3c9782f20ac719983c5fcbc958ccaaf15fdd1ff28c9defd087d096ed89eb4ecc990c2a1e5e815f24f49217defba06fae3
|
7
|
+
data.tar.gz: f0978a52503c33b618a8d8a6df09c112dc0d4457c3665d67945de478d8ceb5e5e84a9b216d8190f016be62da92b2e5d521890f0532bc4a4d0bd1ee69aa91edfa
|
data/README.md
CHANGED
@@ -26,6 +26,22 @@ This gem supports both authentication methods:
|
|
26
26
|
|
27
27
|
https://docs.microsoft.com/en-us/dynamics-nav/api-reference/v1.0/endpoints-apis-for-dynamics
|
28
28
|
|
29
|
+
```Ruby
|
30
|
+
require 'business_central'
|
31
|
+
|
32
|
+
client = BusinessCentral::Client.new(
|
33
|
+
username: '<username>', # Basic authentication username
|
34
|
+
password: '<password>', # Basic authentication password
|
35
|
+
url: '<url>', # URL for API defaults to https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0
|
36
|
+
web_service_url: '<url>', # URL for custom web services defaults to https://api.businesscentral.dynamics.com/v2.0/production/ODataV4
|
37
|
+
application_id: '<application_id>', # Oauth2 authentication application ID
|
38
|
+
secret_key: '<application_secret_key>', # OAuth2 authentication application secret key
|
39
|
+
oauth2_login_url: '<url>', # OAuth2 authentication login URL defaults to https://login.microsoftonline.com/common
|
40
|
+
default_company_id: '<company_id>', # Default company ID used in all requests (if required)
|
41
|
+
debug: false # Output requests to console
|
42
|
+
)
|
43
|
+
```
|
44
|
+
|
29
45
|
### Basic Authentication:
|
30
46
|
|
31
47
|
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/developer/devenv-develop-connect-apps#setting-up-basic-authentication
|
@@ -36,26 +52,27 @@ require 'business_central'
|
|
36
52
|
client = BusinessCentral::Client.new(
|
37
53
|
username: '<username>',
|
38
54
|
password: '<password>',
|
39
|
-
url: '<url>'
|
55
|
+
url: '<url>',
|
56
|
+
default_company_id: '11111111-2222-3333-4444-555555555555'
|
40
57
|
)
|
41
58
|
|
42
59
|
# Find all vendors
|
43
|
-
vendors = client.vendor
|
60
|
+
vendors = client.vendor.all
|
44
61
|
|
45
62
|
# Find vendor by ID
|
46
|
-
vendor = client.vendor
|
63
|
+
vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
|
47
64
|
|
48
65
|
# Query vendor by display name
|
49
|
-
vendor = client.vendor
|
66
|
+
vendor = client.vendor.where("displayName eq 'First Up Consultants'")
|
50
67
|
|
51
68
|
# Create a new vendor
|
52
|
-
vendor = client.vendor
|
69
|
+
vendor = client.vendor.create({ display_name: 'hello testing new vendor' })
|
53
70
|
|
54
71
|
# Update an existing vendor by ID
|
55
|
-
vendor = client.vendor
|
72
|
+
vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
|
56
73
|
|
57
74
|
# Delete a vendor
|
58
|
-
client.vendor
|
75
|
+
client.vendor.destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
|
59
76
|
```
|
60
77
|
|
61
78
|
### Oauth2 Authentication
|
@@ -67,10 +84,10 @@ require 'business_central'
|
|
67
84
|
|
68
85
|
# Create client - used to connect to the API
|
69
86
|
client = BusinessCentral::Client.new(
|
70
|
-
tenant_id: '<tenant_id>',
|
71
87
|
application_id: '<application_id>',
|
72
88
|
secret_key: '<application_secret_key>',
|
73
|
-
url: '<url>'
|
89
|
+
url: '<url>',
|
90
|
+
default_company_id: '11111111-2222-3333-4444-555555555555'
|
74
91
|
)
|
75
92
|
|
76
93
|
# Controller endpoint 1
|
@@ -87,22 +104,48 @@ client.authorize_from_token(
|
|
87
104
|
)
|
88
105
|
|
89
106
|
# Find all vendors
|
90
|
-
vendors = client.vendor
|
107
|
+
vendors = client.vendor.all
|
91
108
|
|
92
109
|
# Find vendor by ID
|
93
|
-
vendor = client.vendor
|
110
|
+
vendor = client.vendor.find('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4')
|
94
111
|
|
95
112
|
# Query vendor by display name
|
96
|
-
vendor = client.vendor
|
113
|
+
vendor = client.vendor.where("displayName eq 'First Up Consultants'")
|
97
114
|
|
98
115
|
# Create a new vendor
|
99
|
-
vendor = client.vendor
|
116
|
+
vendor = client.vendor.create({ display_name: 'hello testing' })
|
100
117
|
|
101
118
|
# Update an existing vendor by ID
|
102
|
-
vendor = client.vendor
|
119
|
+
vendor = client.vendor.update('3f445b08-2ffd-4f9d-81a0-b82f0d9714c4', { phone_number: '1112' })
|
103
120
|
|
104
121
|
# Delete a vendor
|
105
|
-
client.vendor
|
122
|
+
client.vendor.destroy('f0730ada-b315-ea11-a813-000d3ad21e99')
|
123
|
+
```
|
124
|
+
|
125
|
+
### OData Web Services
|
126
|
+
|
127
|
+
https://docs.microsoft.com/en-us/dynamics365/business-central/dev-itpro/webservices/odata-web-services
|
128
|
+
|
129
|
+
```Ruby
|
130
|
+
require 'business_central'
|
131
|
+
|
132
|
+
client = BusinessCentral::Client.new(
|
133
|
+
username: '<username>',
|
134
|
+
password: '<password>',
|
135
|
+
web_service_url: '<url>'
|
136
|
+
)
|
137
|
+
|
138
|
+
# Query a record
|
139
|
+
company = client.web_service.object("Company('?')/Purchase_Order", 'My Company').get
|
140
|
+
|
141
|
+
# Create a record
|
142
|
+
client.web_service.object("Company('?')/Purchase_Order", 'My Company').post({})
|
143
|
+
|
144
|
+
# Update a record
|
145
|
+
client.web_service.object("Company('?')/Purchase_Order", 'My Company').patch({})
|
146
|
+
|
147
|
+
# Delete a record
|
148
|
+
client.web_service.object("Company('?')/Purchase_Order", 'My Company').delete
|
106
149
|
```
|
107
150
|
|
108
151
|
## Development
|
data/lib/business_central.rb
CHANGED
@@ -5,23 +5,68 @@ require 'json'
|
|
5
5
|
|
6
6
|
require 'core_ext/string'
|
7
7
|
|
8
|
-
require 'business_central/object/
|
8
|
+
require 'business_central/object/argument_helper'
|
9
|
+
require 'business_central/object/url_helper'
|
10
|
+
require 'business_central/object/object_helper'
|
11
|
+
|
9
12
|
require 'business_central/object/base'
|
10
13
|
require 'business_central/object/validation'
|
11
14
|
require 'business_central/object/response'
|
12
15
|
require 'business_central/object/request'
|
16
|
+
require 'business_central/object/filter_query'
|
17
|
+
require 'business_central/object/url_builder'
|
13
18
|
|
14
19
|
require 'business_central/object/account'
|
15
20
|
require 'business_central/object/aged_account_payable'
|
16
21
|
require 'business_central/object/aged_account_receivable'
|
22
|
+
require 'business_central/object/attachment'
|
17
23
|
require 'business_central/object/cash_flow_statement'
|
18
24
|
require 'business_central/object/balance_sheet'
|
19
25
|
require 'business_central/object/company'
|
20
26
|
require 'business_central/object/company_information'
|
21
|
-
require 'business_central/object/
|
27
|
+
require 'business_central/object/country_region'
|
28
|
+
require 'business_central/object/currency'
|
29
|
+
require 'business_central/object/customer'
|
30
|
+
require 'business_central/object/customer_financial_detail'
|
31
|
+
require 'business_central/object/customer_payment'
|
32
|
+
require 'business_central/object/customer_payment_journal'
|
33
|
+
require 'business_central/object/customer_sale'
|
34
|
+
require 'business_central/object/default_dimension'
|
35
|
+
require 'business_central/object/dimension'
|
36
|
+
require 'business_central/object/dimension_line'
|
37
|
+
require 'business_central/object/dimension_value'
|
38
|
+
require 'business_central/object/employee'
|
39
|
+
require 'business_central/object/general_ledger_entry'
|
40
|
+
require 'business_central/object/income_statement'
|
41
|
+
require 'business_central/object/irs1099_code'
|
22
42
|
require 'business_central/object/item'
|
43
|
+
require 'business_central/object/item_category'
|
44
|
+
require 'business_central/object/journal'
|
45
|
+
require 'business_central/object/journal_line'
|
46
|
+
require 'business_central/object/payment_method'
|
47
|
+
require 'business_central/object/payment_term'
|
48
|
+
require 'business_central/object/picture'
|
23
49
|
require 'business_central/object/purchase_invoice'
|
24
50
|
require 'business_central/object/purchase_invoice_line'
|
51
|
+
require 'business_central/object/retained_earning_statement'
|
52
|
+
require 'business_central/object/sales_invoice'
|
53
|
+
require 'business_central/object/sales_invoice_line'
|
54
|
+
require 'business_central/object/sales_credit_memo'
|
55
|
+
require 'business_central/object/sales_credit_memo_line'
|
56
|
+
require 'business_central/object/sales_order'
|
57
|
+
require 'business_central/object/sales_order_line'
|
58
|
+
require 'business_central/object/sales_quote'
|
59
|
+
require 'business_central/object/sales_quote_line'
|
60
|
+
require 'business_central/object/shipment_method'
|
61
|
+
require 'business_central/object/subscription'
|
62
|
+
require 'business_central/object/tax_area'
|
63
|
+
require 'business_central/object/tax_group'
|
64
|
+
require 'business_central/object/time_registration_entry'
|
65
|
+
require 'business_central/object/trial_balance'
|
66
|
+
require 'business_central/object/units_of_measure'
|
67
|
+
require 'business_central/object/vendor'
|
68
|
+
require 'business_central/object/vendor_purchase'
|
25
69
|
|
26
70
|
require 'business_central/exceptions'
|
27
71
|
require 'business_central/client'
|
72
|
+
require 'business_central/web_service'
|
@@ -1,99 +1,142 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module BusinessCentral
|
2
4
|
class Client
|
3
|
-
extend BusinessCentral::Object::
|
5
|
+
extend BusinessCentral::Object::ObjectHelper
|
6
|
+
|
7
|
+
DEFAULT_LOGIN_URL = 'https://login.microsoftonline.com/common'
|
4
8
|
|
5
|
-
DEFAULT_URL = 'https://api.businesscentral.dynamics.com/
|
9
|
+
DEFAULT_URL = 'https://api.businesscentral.dynamics.com/v2.0/production/api/v1.0'
|
6
10
|
|
7
|
-
attr_reader :
|
8
|
-
:username,
|
11
|
+
attr_reader :username,
|
9
12
|
:password,
|
10
13
|
:application_id,
|
11
14
|
:secret_key,
|
12
15
|
:url,
|
13
|
-
:
|
16
|
+
:web_service_url,
|
17
|
+
:oauth2_login_url,
|
18
|
+
:oauth2_access_token,
|
19
|
+
:default_company_id,
|
20
|
+
:debug
|
14
21
|
|
15
|
-
|
22
|
+
alias access_token oauth2_access_token
|
16
23
|
|
17
24
|
object :account
|
18
25
|
object :aged_account_payable
|
19
26
|
object :aged_account_receivable
|
27
|
+
object :attachment
|
20
28
|
object :balance_sheet
|
21
29
|
object :cash_flow_statement
|
22
30
|
object :company
|
23
31
|
object :company_information
|
24
|
-
object :
|
32
|
+
object :country_region
|
33
|
+
object :currency
|
34
|
+
object :customer
|
35
|
+
object :customer_financial_detail
|
36
|
+
object :customer_payment
|
37
|
+
object :customer_payment_journal
|
38
|
+
object :customer_sale
|
39
|
+
object :default_dimension
|
40
|
+
object :dimension
|
41
|
+
object :dimension_line
|
42
|
+
object :dimension_value
|
43
|
+
object :employee
|
44
|
+
object :general_ledger_entry
|
45
|
+
object :income_statement
|
46
|
+
object :irs1099_code
|
25
47
|
object :purchase_invoice
|
26
48
|
object :purchase_invoice_line
|
27
49
|
object :item
|
50
|
+
object :item_category
|
51
|
+
object :journal
|
52
|
+
object :journal_line
|
53
|
+
object :payment_method
|
54
|
+
object :payment_term
|
55
|
+
object :picture
|
56
|
+
object :retained_earning_statement
|
57
|
+
object :sales_invoice
|
58
|
+
object :sales_invoice_line
|
59
|
+
object :sales_credit_memo
|
60
|
+
object :sales_credit_memo_line
|
61
|
+
object :sales_order
|
62
|
+
object :sales_order_line
|
63
|
+
object :sales_quote
|
64
|
+
object :sales_quote_line
|
65
|
+
object :shipment_method
|
66
|
+
object :subscription
|
67
|
+
object :tax_area
|
68
|
+
object :tax_group
|
69
|
+
object :time_registration_entry
|
70
|
+
object :trial_balance
|
71
|
+
object :units_of_measure
|
72
|
+
object :vendor
|
73
|
+
object :vendor_purchase
|
28
74
|
|
29
75
|
def initialize(options = {})
|
30
76
|
opts = options.dup
|
31
|
-
@tenant_id = opts.delete(:tenant_id)
|
32
77
|
@username = opts.delete(:username)
|
33
78
|
@password = opts.delete(:password)
|
34
79
|
@url = opts.delete(:url) || DEFAULT_URL
|
80
|
+
@web_service_url = opts.delete(:web_service_url)
|
35
81
|
@application_id = opts.delete(:application_id)
|
36
82
|
@secret_key = opts.delete(:secret_key)
|
83
|
+
@oauth2_login_url = opts.delete(:oauth2_login_url) || DEFAULT_LOGIN_URL
|
84
|
+
@default_company_id = opts.delete(:default_company_id)
|
85
|
+
@debug = opts.delete(:debug) || false
|
37
86
|
end
|
38
87
|
|
39
88
|
def authorize(params = {}, oauth_authorize_callback: '')
|
40
89
|
params[:redirect_uri] = oauth_authorize_callback
|
41
90
|
begin
|
42
91
|
oauth2_client.auth_code.authorize_url(params)
|
43
|
-
rescue
|
44
|
-
handle_error(
|
92
|
+
rescue OAuth2::Error => e
|
93
|
+
handle_error(e)
|
45
94
|
end
|
46
95
|
end
|
47
96
|
|
48
97
|
def request_token(code = '', oauth_token_callback: '')
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
handle_error(error)
|
53
|
-
end
|
98
|
+
oauth2_client.auth_code.get_token(code, redirect_uri: oauth_token_callback)
|
99
|
+
rescue OAuth2::Error => e
|
100
|
+
handle_error(e)
|
54
101
|
end
|
55
102
|
|
56
103
|
def authorize_from_token(token: '', refresh_token: '', expires_at: nil, expires_in: nil)
|
57
|
-
@
|
104
|
+
@oauth2_access_token = OAuth2::AccessToken.new(
|
58
105
|
oauth2_client,
|
59
106
|
token,
|
60
107
|
refresh_token: refresh_token,
|
61
108
|
expires_at: expires_at,
|
62
|
-
expires_in: expires_in
|
109
|
+
expires_in: expires_in
|
63
110
|
)
|
64
111
|
end
|
65
112
|
|
66
113
|
def refresh_token
|
67
|
-
@
|
114
|
+
@oauth2_access_token.refresh!
|
115
|
+
end
|
116
|
+
|
117
|
+
def web_service
|
118
|
+
@web_service ||= BusinessCentral::WebService.new(client: self, url: web_service_url)
|
68
119
|
end
|
69
120
|
|
70
121
|
private
|
71
122
|
|
72
123
|
def oauth2_client
|
73
|
-
|
74
|
-
@
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
|
81
|
-
}
|
82
|
-
)
|
83
|
-
end
|
84
|
-
|
85
|
-
return @oauth2_client
|
124
|
+
OAuth2::Client.new(
|
125
|
+
@application_id,
|
126
|
+
@secret_key,
|
127
|
+
site: @oauth2_login_url,
|
128
|
+
authorize_url: 'oauth2/authorize?resource=https://api.businesscentral.dynamics.com',
|
129
|
+
token_url: 'oauth2/token?resource=https://api.businesscentral.dynamics.com'
|
130
|
+
)
|
86
131
|
end
|
87
132
|
|
88
133
|
def handle_error(error)
|
89
|
-
if error.code.
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
else
|
95
|
-
raise ApiException.new(error.message)
|
134
|
+
raise ApiException, error.message if error.code.nil?
|
135
|
+
|
136
|
+
case error.code
|
137
|
+
when 'invalid_client'
|
138
|
+
raise InvalidClientException
|
96
139
|
end
|
97
140
|
end
|
98
141
|
end
|
99
|
-
end
|
142
|
+
end
|
@@ -1,10 +1,11 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
+
module BusinessCentral
|
3
4
|
class BusinessCentralError < StandardError; end
|
4
5
|
|
5
6
|
class InvalidClientException < BusinessCentralError
|
6
7
|
def message
|
7
|
-
'Invalid
|
8
|
+
'Invalid client setup'
|
8
9
|
end
|
9
10
|
end
|
10
11
|
|
@@ -13,9 +14,7 @@ module BusinessCentral
|
|
13
14
|
@message = message
|
14
15
|
end
|
15
16
|
|
16
|
-
|
17
|
-
@message
|
18
|
-
end
|
17
|
+
attr_reader :message
|
19
18
|
end
|
20
19
|
|
21
20
|
class CompanyNotFoundException < BusinessCentralError
|
@@ -30,15 +29,19 @@ module BusinessCentral
|
|
30
29
|
end
|
31
30
|
end
|
32
31
|
|
32
|
+
class NotFoundException < BusinessCentralError
|
33
|
+
def message
|
34
|
+
'Not Found - The URL provided cannot be found'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
33
38
|
class InvalidObjectException < BusinessCentralError
|
34
39
|
def initialize(errors)
|
35
40
|
@errors = errors
|
36
41
|
end
|
37
42
|
|
38
43
|
def message
|
39
|
-
@errors.each
|
40
|
-
"#{error[:field]} - #{error[:message]}"
|
41
|
-
end
|
44
|
+
@errors.each { |error| "#{error[:field]} - #{error[:message]}" }
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
@@ -49,7 +52,24 @@ module BusinessCentral
|
|
49
52
|
end
|
50
53
|
|
51
54
|
def message
|
52
|
-
|
55
|
+
methods_allowed = @allowed_methods.join(', ')
|
56
|
+
"#{@method} method is currently not support. Allowed methods are: #{methods_allowed}"
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
class InvalidArgumentException < BusinessCentralError
|
61
|
+
def initialize(message)
|
62
|
+
@message = message
|
63
|
+
end
|
64
|
+
|
65
|
+
def message
|
66
|
+
"Invalid argument entered - #{@message}"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
class InvalidObjectURLException < BusinessCentralError
|
71
|
+
def message
|
72
|
+
'Object URL missing for request'
|
53
73
|
end
|
54
74
|
end
|
55
|
-
end
|
75
|
+
end
|