business_central 0.9.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (152) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE +373 -0
  5. data/README.md +67 -0
  6. data/Rakefile +41 -0
  7. data/azure-pipelines.yml +30 -0
  8. data/business_central.gemspec +31 -0
  9. data/lib/business_central/account.rb +9 -0
  10. data/lib/business_central/aged_accounts_payable.rb +10 -0
  11. data/lib/business_central/aged_accounts_receivable.rb +10 -0
  12. data/lib/business_central/api_methods.rb +220 -0
  13. data/lib/business_central/balance_sheet.rb +10 -0
  14. data/lib/business_central/base.rb +56 -0
  15. data/lib/business_central/cash_flow_statement.rb +10 -0
  16. data/lib/business_central/client.rb +128 -0
  17. data/lib/business_central/company.rb +9 -0
  18. data/lib/business_central/company_information.rb +10 -0
  19. data/lib/business_central/countries_region.rb +9 -0
  20. data/lib/business_central/currency.rb +9 -0
  21. data/lib/business_central/customer.rb +9 -0
  22. data/lib/business_central/customer_financial_details.rb +10 -0
  23. data/lib/business_central/customer_payment.rb +14 -0
  24. data/lib/business_central/customer_payments_journal.rb +10 -0
  25. data/lib/business_central/customer_sales.rb +10 -0
  26. data/lib/business_central/dimension.rb +10 -0
  27. data/lib/business_central/dimension_line.rb +14 -0
  28. data/lib/business_central/employee.rb +10 -0
  29. data/lib/business_central/general_ledger_entry.rb +10 -0
  30. data/lib/business_central/income_statement.rb +10 -0
  31. data/lib/business_central/irs_1099_code.rb +10 -0
  32. data/lib/business_central/item.rb +10 -0
  33. data/lib/business_central/item_category.rb +10 -0
  34. data/lib/business_central/journal.rb +10 -0
  35. data/lib/business_central/journal_line.rb +14 -0
  36. data/lib/business_central/payment_method.rb +10 -0
  37. data/lib/business_central/payment_term.rb +10 -0
  38. data/lib/business_central/picture.rb +10 -0
  39. data/lib/business_central/purchase_invoice.rb +10 -0
  40. data/lib/business_central/purchase_invoice_line.rb +43 -0
  41. data/lib/business_central/request_builder.rb +60 -0
  42. data/lib/business_central/response/response_handler.rb +57 -0
  43. data/lib/business_central/retained_earnings_statement.rb +9 -0
  44. data/lib/business_central/sales_credit_memo.rb +10 -0
  45. data/lib/business_central/sales_credit_memo_line.rb +14 -0
  46. data/lib/business_central/sales_invoice.rb +10 -0
  47. data/lib/business_central/sales_invoice_line.rb +25 -0
  48. data/lib/business_central/sales_order.rb +9 -0
  49. data/lib/business_central/sales_order_line.rb +14 -0
  50. data/lib/business_central/sales_quote.rb +10 -0
  51. data/lib/business_central/sales_quote_line.rb +14 -0
  52. data/lib/business_central/shipment_method.rb +10 -0
  53. data/lib/business_central/subscription.rb +63 -0
  54. data/lib/business_central/tax_area.rb +10 -0
  55. data/lib/business_central/tax_group.rb +10 -0
  56. data/lib/business_central/trial_balance.rb +10 -0
  57. data/lib/business_central/unit_of_measure.rb +10 -0
  58. data/lib/business_central/url_builder.rb +33 -0
  59. data/lib/business_central/vendor.rb +10 -0
  60. data/lib/business_central/vendor_purchase.rb +10 -0
  61. data/lib/business_central/version.rb +3 -0
  62. data/lib/business_central.rb +67 -0
  63. data/test/business_central/account_test.rb +26 -0
  64. data/test/business_central/aged_accounts_payable_test.rb +8 -0
  65. data/test/business_central/aged_accounts_receivable_test.rb +8 -0
  66. data/test/business_central/base_test.rb +28 -0
  67. data/test/business_central/company_information_test.rb +8 -0
  68. data/test/business_central/company_test.rb +27 -0
  69. data/test/business_central/countries_region_test.rb +69 -0
  70. data/test/business_central/currency_test.rb +8 -0
  71. data/test/business_central/customer_financial_details_test.rb +20 -0
  72. data/test/business_central/customer_payment_test.rb +8 -0
  73. data/test/business_central/customer_payments_journal_test.rb +8 -0
  74. data/test/business_central/customer_sales_test.rb +8 -0
  75. data/test/business_central/customer_test.rb +138 -0
  76. data/test/business_central/dimension_line_test.rb +8 -0
  77. data/test/business_central/dimension_test.rb +8 -0
  78. data/test/business_central/employee_test.rb +8 -0
  79. data/test/business_central/general_ledger_entry_test.rb +8 -0
  80. data/test/business_central/income_statement_test.rb +8 -0
  81. data/test/business_central/irs_1099_code_test.rb +8 -0
  82. data/test/business_central/item_category_test.rb +8 -0
  83. data/test/business_central/item_test.rb +8 -0
  84. data/test/business_central/journal_line_test.rb +8 -0
  85. data/test/business_central/journal_test.rb +8 -0
  86. data/test/business_central/payment_method_test.rb +8 -0
  87. data/test/business_central/payment_term_test.rb +27 -0
  88. data/test/business_central/picture_test.rb +8 -0
  89. data/test/business_central/purchase_invoice_line_test.rb +33 -0
  90. data/test/business_central/purchase_invoice_test.rb +8 -0
  91. data/test/business_central/request_builder_test.rb +43 -0
  92. data/test/business_central/response/response_handler_test.rb +58 -0
  93. data/test/business_central/sales_credit_memo_line_test.rb +8 -0
  94. data/test/business_central/sales_credit_memo_test.rb +8 -0
  95. data/test/business_central/sales_invoice_line_test.rb +58 -0
  96. data/test/business_central/sales_invoice_test.rb +40 -0
  97. data/test/business_central/sales_order_line_test.rb +8 -0
  98. data/test/business_central/sales_order_test.rb +32 -0
  99. data/test/business_central/sales_quote_line_test.rb +8 -0
  100. data/test/business_central/sales_quote_test.rb +8 -0
  101. data/test/business_central/shipment_method_test.rb +19 -0
  102. data/test/business_central/subscription_test.rb +0 -0
  103. data/test/business_central/tax_area_test.rb +19 -0
  104. data/test/business_central/tax_group_test.rb +19 -0
  105. data/test/business_central/trial_balance_test.rb +8 -0
  106. data/test/business_central/unit_of_measure_test.rb +19 -0
  107. data/test/business_central/url_builder_test.rb +19 -0
  108. data/test/business_central/vendor_purchase_test.rb +8 -0
  109. data/test/business_central/vendor_test.rb +8 -0
  110. data/test/client_test.rb +72 -0
  111. data/test/fixtures/filter_customers_200.json +1 -0
  112. data/test/fixtures/get_account_200.json +1 -0
  113. data/test/fixtures/get_accounts_200.json +1 -0
  114. data/test/fixtures/get_companies_200.json +1 -0
  115. data/test/fixtures/get_company_200.json +1 -0
  116. data/test/fixtures/get_countriesRegion_200.json +1 -0
  117. data/test/fixtures/get_countriesRegions_200.json +1 -0
  118. data/test/fixtures/get_currencies_200.json +1 -0
  119. data/test/fixtures/get_currency_200.json +1 -0
  120. data/test/fixtures/get_customer_200.json +1 -0
  121. data/test/fixtures/get_customer_expanded_200.json +1 -0
  122. data/test/fixtures/get_customer_financial_details_200.json +1 -0
  123. data/test/fixtures/get_customers_200.json +1 -0
  124. data/test/fixtures/get_paymentMethod_200.json +1 -0
  125. data/test/fixtures/get_paymentMethods_200.json +1 -0
  126. data/test/fixtures/get_paymentTerm_200.json +1 -0
  127. data/test/fixtures/get_paymentTerms_200.json +1 -0
  128. data/test/fixtures/get_purchaseInvoiceLine_200.json +1 -0
  129. data/test/fixtures/get_purchaseInvoiceLines_200.json +1 -0
  130. data/test/fixtures/get_purchaseInvoice_200.json +1 -0
  131. data/test/fixtures/get_purchase_invoices_200.json +1 -0
  132. data/test/fixtures/get_salesInvoiceLine_200.json +1 -0
  133. data/test/fixtures/get_salesInvoiceLines_200.json +1 -0
  134. data/test/fixtures/get_salesInvoiceLines_single_200.json +1 -0
  135. data/test/fixtures/get_salesInvoice_200.json +1 -0
  136. data/test/fixtures/get_salesInvoices_200.json +1 -0
  137. data/test/fixtures/get_salesOrder_200.json +1 -0
  138. data/test/fixtures/get_salesOrders_200.json +1 -0
  139. data/test/fixtures/get_shipmentMethods_200.json +1 -0
  140. data/test/fixtures/get_taxAreas_200.json +1 -0
  141. data/test/fixtures/get_taxGroups_200.json +1 -0
  142. data/test/fixtures/get_unitsOfMeasure_200.json +1 -0
  143. data/test/fixtures/patch_countriesRegion_200.json +1 -0
  144. data/test/fixtures/patch_customer_200.json +1 -0
  145. data/test/fixtures/post_countriesRegion_200.json +1 -0
  146. data/test/fixtures/post_customer_200.json +1 -0
  147. data/test/fixtures/post_customer_409.json +1 -0
  148. data/test/fixtures/post_salesInvoiceLine_200.json +1 -0
  149. data/test/fixtures/post_salesInvoice_200.json +1 -0
  150. data/test/fixtures/post_subscription_200.json +1 -0
  151. data/test/test_helper.rb +86 -0
  152. metadata +408 -0
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /purchaseInvoices API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class PurchaseInvoice < BusinessCentral::Base
7
+ API_OBJECT = "purchaseInvoices"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,43 @@
1
+ ##
2
+ # Provides access to the /purchaseInvoices/{Id}/purchaseInvoiceLines API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class PurchaseInvoiceLine < BusinessCentral::Base
7
+ API_OBJECT_PARENT = "purchaseInvoices"
8
+ API_OBJECT = "purchaseInvoiceLines"
9
+
10
+ def get(purchase_invoice_id, purchase_invoice_line_id = nil)
11
+ get_child(purchase_invoice_id, purchase_invoice_line_id)
12
+ end
13
+
14
+ def create(purchase_invoice_id, data)
15
+ url = build_url(purchase_invoice_id, nil)
16
+
17
+ response = @client.post(url, data)
18
+ handle_error(response)
19
+ results = process(response)
20
+
21
+ return results.first
22
+ end
23
+
24
+ def update(purchase_invoice_id, purchase_invoice_line_id, etag, data)
25
+ url = build_url(purchase_invoice_id, purchase_invoice_line_id)
26
+
27
+ response = @client.patch(url, etag, data)
28
+ handle_error(repsonse)
29
+ results = process(response)
30
+
31
+ return results.first
32
+ end
33
+
34
+ def delete(purchase_invoice_id, purchase_invoice_line_id, etag)
35
+ url = build_url(purchase_invoice_id, purchase_invoice_line_id)
36
+
37
+ response = @client.delete(url, etag)
38
+ handle_error(response)
39
+
40
+ return response.code
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,60 @@
1
+ ##
2
+ # An object to build the request object
3
+ #
4
+
5
+ class BusinessCentral::RequestBuilder
6
+ attr_accessor :request
7
+ attr_reader :verb, :url, :etag, :data
8
+
9
+ # @param client [BusinessCentral::Client]
10
+ # @param opts [Hash] Options used to build the request
11
+ #
12
+ def initialize(client, opts = {})
13
+ @client = client
14
+ @verb = opts[:verb] if opts.has_key?(:verb)
15
+ @url = opts[:url] if opts.has_key?(:url)
16
+ @etag = opts[:etag] if opts.has_key?(:etag)
17
+ @data = opts[:data] if opts.has_key?(:data)
18
+ build
19
+ end
20
+
21
+ # Create the appropriate request object
22
+ #
23
+ # Populates @request with the constructed object
24
+ def build
25
+ @request = request_object.new(uri)
26
+ @request.content_type = "application/json"
27
+ @request.basic_auth(@client.api_username, @client.api_password)
28
+ add_etag
29
+ add_data
30
+ end
31
+
32
+ # If an etag is supplied, add it to the request in an ['If-Match'] header
33
+ #
34
+ def add_etag
35
+ return if @etag.nil?
36
+ @request['If-Match'] = @etag
37
+ end
38
+
39
+ # If form data is supplied, add it to the request body as JSON
40
+ #
41
+ def add_data
42
+ return if @data.nil?
43
+ @request.body = JSON.generate(@data)
44
+ end
45
+
46
+ # @returns [Net::HTTP::Request] object, based on the verb supplied in the
47
+ # initialization opts Hash
48
+ #
49
+ def request_object
50
+ Object.const_get("Net::HTTP::#{@verb.capitalize}")
51
+ end
52
+
53
+ # Contstruct URI for the request
54
+ #
55
+ # @returns [URI]
56
+ #
57
+ def uri
58
+ URI(@client.base_url + @url)
59
+ end
60
+ end
@@ -0,0 +1,57 @@
1
+ ##
2
+ # Provides the interface to convert the JSON response from the API
3
+ # to a Ruby Object
4
+ #
5
+ module BusinessCentral::Response
6
+ class ResponseHandler
7
+ attr_accessor :dataset
8
+ attr_accessor :compiled_data
9
+
10
+ # Constructor
11
+ #
12
+ # @param dataset [Hash | Array] the result from the API operation
13
+ #
14
+ def initialize(dataset)
15
+ @compiled_data = []
16
+ @dataset = dataset
17
+ process
18
+ end
19
+
20
+ # Compiles the data in the @dataset to the supplied class
21
+ #
22
+ def process
23
+ @dataset.is_a?(Array) ? process_array : process_data(@dataset)
24
+ end
25
+
26
+ # If the supplied result from the API operation is an array, iterate over
27
+ # it and process each result into @compiled_data
28
+ #
29
+ def process_array
30
+ @dataset.each { |data| process_data(data) }
31
+ end
32
+
33
+ # Parse the JSON response from the API into an OpenStruct object. This will
34
+ # also parse any child objects, which allows the data to be accessed via
35
+ # regular chaining
36
+ #
37
+ # eg
38
+ # company.address.state
39
+ #
40
+ # @param data [JSON]
41
+ #
42
+ def process_data(data)
43
+ new_record = JSON.parse(sanitize(data), object_class: OpenStruct)
44
+
45
+ unless data["@odata.etag"].nil?
46
+ new_record.etag = data["@odata.etag"]
47
+ end
48
+ @compiled_data << new_record
49
+ end
50
+
51
+ # Ensures the data is in JSON format
52
+ #
53
+ def sanitize(data)
54
+ data.is_a?(Hash) ? data.to_json : data
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,9 @@
1
+ ##
2
+ # Provides access to the /retainedEarningsStatement API
3
+ #
4
+ module BusinessCentral
5
+ class RetainedEarningsStatement < BusinessCentral::Base
6
+ API_OBJECT = "retainedEarningsStatement"
7
+ SUPPORTED_METHODS = [:get]
8
+ end
9
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /salesCreditMemos API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesCreditMemo < BusinessCentral::Base
7
+ API_OBJECT = "salesCreditMemos"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ ##
2
+ # Provides access to the /salesCreditMemos/{Id}/salesCreditMemoLines API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesCreditMemoLine < BusinessCentral::Base
7
+ API_OBJECT_PARENT = "salesCreditMemos"
8
+ API_OBJECT = "salesCreditMemoLines"
9
+
10
+ def get(sales_credit_memo_id, sales_credit_memo_line_id = nil)
11
+ get_child(sales_credit_memo_id, sales_credit_memo_line_id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /salesInvoices API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesInvoice < BusinessCentral::Base
7
+ API_OBJECT = "salesInvoices"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,25 @@
1
+ ##
2
+ # Provides access to the /salesInvoices/{Id}/salesInvoiceLines API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesInvoiceLine < BusinessCentral::Base
7
+ API_OBJECT_PARENT = "salesInvoices"
8
+ API_OBJECT = "salesInvoiceLines"
9
+
10
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
11
+
12
+ def get(sales_invoice_id, sales_invoice_line_id = nil)
13
+ get_child(sales_invoice_id, sales_invoice_line_id)
14
+ end
15
+
16
+ def create(sales_invoice_id, data)
17
+ url = "/#{API_OBJECT_PARENT}(#{sales_invoice_id})/#{API_OBJECT}"
18
+
19
+ response = @client.post(url, data)
20
+ handle_error(response)
21
+ result = process(response)
22
+ return result.first
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,9 @@
1
+ ##
2
+ # Access the /salesOrders API on Business Central
3
+ #
4
+ module BusinessCentral
5
+ class SalesOrder < BusinessCentral::Base
6
+ API_OBJECT = "salesOrders"
7
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ ##
2
+ # Provides access to the /salesOrders/{Id}/salesOrdersLines api
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesOrderLine < BusinessCentral::Base
7
+ API_OBJECT_PARENT = "salesOrders"
8
+ API_OBEJCT = "salesOrderLines"
9
+
10
+ def get(sales_order_id, sales_order_line_id = nil)
11
+ get_child(sales_order_id, sales_order_line_id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /salesQuotes API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesQuote < BusinessCentral::Base
7
+ API_OBJECT = "salesQuotes"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ ##
2
+ # Provides access to the /salesQuotes/{Id}/salesQuotesLines API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class SalesQuoteLine < BusinessCentral::Base
7
+ API_OBJECT_PARENT = "salesQuotes"
8
+ API_OBJECT = "salesQuoteLines"
9
+
10
+ def get(sales_quote_id, sales_quote_line_id = nil)
11
+ get_child(sales_quote_id, sales_quote_line_id)
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /shipmentMethods API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class ShipmentMethod < BusinessCentral::Base
7
+ API_OBJECT = "shipmentMethods"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,63 @@
1
+ ##
2
+ # Access the /subscriptions API on BusinessCentral
3
+ #
4
+ # Allows the registration of Webhooks to receive notifications of updates to
5
+ # various resources
6
+ #
7
+ # The system uses a slightly different URL for the registration process. It
8
+ # doesn't include the TenantID (eg /companies(XXXX)) in the POST url
9
+
10
+ module BusinessCentral
11
+ class Subscription < BusinessCentral::Base
12
+ API_OBJECT = "subscriptions"
13
+ SUPPORTED_METHODS = [:post]
14
+
15
+ attr_reader :resource, :endpoint, :client
16
+
17
+ def initialize(client, resource, endpoint)
18
+ @client = client.nil? ? BusinessCentral::Client.new() : client
19
+ @resource = resource
20
+ @endpoint = endpoint
21
+ end
22
+
23
+ def get
24
+ request = Net::HTTP::Get.new(URI(request_url))
25
+ request.content_type = "application/json"
26
+ request.basic_auth(@client.api_username, @client.api_password)
27
+ response = perform_request(request)
28
+ JSON.parse(response.body)
29
+ end
30
+
31
+ def create
32
+ request = Net::HTTP::Post.new(URI(request_url))
33
+ request.content_type = "application/json"
34
+ request.basic_auth(@client.api_username, @client.api_password)
35
+ request.body = JSON.generate(post_data)
36
+ request
37
+
38
+ response = perform_request(request)
39
+
40
+ JSON.parse(response.body)
41
+ end
42
+
43
+ def perform_request(request)
44
+ Net::HTTP.start(request.uri.hostname, request.uri.port, use_ssl: true) do |http|
45
+ http.request(request)
46
+ end
47
+ end
48
+
49
+ def request_url
50
+ "#{@client.api_host}#{@client.api_version}#{@client.api_path}/subscriptions"
51
+ end
52
+
53
+ def post_data
54
+ {
55
+ "notificationUrl": @endpoint,
56
+ "resource": @resource
57
+ }
58
+ end
59
+
60
+ def build_request_object
61
+ end
62
+ end
63
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # PRovides access to the /taxAreas API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class TaxArea < BusinessCentral::Base
7
+ API_OBJECT = "taxAreas"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /taxGroups API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class TaxGroup < BusinessCentral::Base
7
+ API_OBJECT = "taxGroups"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /trialBalance API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class TrialBalance < BusinessCentral::Base
7
+ API_OBJECT = "trialBalance"
8
+ SUPPORTED_METHOD = [:get]
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /unitsOfMeasure API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class UnitOfMeasure < BusinessCentral::Base
7
+ API_OBJECT = "unitsOfMeasure"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,33 @@
1
+ ##
2
+ # Builds URLs for API access
3
+ #
4
+
5
+ module BusinessCentral
6
+ class URLBuilder
7
+ attr_reader :url
8
+ attr_reader :parent_path, :parent_id
9
+ attr_reader :child_path, :child_id, :sequence
10
+
11
+ # @param parent_path [String] The path for the parent object
12
+ # @param parent_id [String] The object ID
13
+ # @param options [Hash] any associated child object
14
+ #
15
+ def initialize(parent_path, parent_id, options = {})
16
+ @url = ""
17
+ @parent_path = parent_path
18
+ @parent_id = parent_id
19
+ @child_path = options.fetch(:child_path, nil)
20
+ @child_id = options.fetch(:child_id, nil)
21
+ @sequence = options.fetch(:sequence, nil)
22
+ build
23
+ end
24
+
25
+ # Creates the URL string from the provided options
26
+ #
27
+ def build
28
+ @url = "/#{@parent_path}(#{@parent_id})"
29
+ @url += "/#{@child_path}" unless @child_path.nil?
30
+ @url += "(#{@child_id})" unless @child_id.nil?
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /vendors API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class Vendor < BusinessCentral::Base
7
+ API_OBJECT = "vendor"
8
+ SUPPORTED_METHODS = [:get, :create, :update, :delete]
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ ##
2
+ # Provides access to the /vendorPurchases API
3
+ #
4
+
5
+ module BusinessCentral
6
+ class VendorPurchase < BusinessCentral::Base
7
+ API_OBJECT = "vendorPurchase"
8
+ SUPPORTED_METHODS = [:get]
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module BusinessCentral
2
+ VERSION = "0.9.3"
3
+ end
@@ -0,0 +1,67 @@
1
+ require 'net/http'
2
+ require 'json'
3
+
4
+ require 'business_central/api_methods'
5
+ require 'business_central/base'
6
+ require 'business_central/request_builder'
7
+ require 'business_central/url_builder'
8
+ require 'business_central/client'
9
+ require 'business_central/version'
10
+ require 'business_central/response/response_handler'
11
+
12
+ require 'business_central/account'
13
+ require 'business_central/aged_accounts_payable'
14
+ require 'business_central/aged_accounts_receivable'
15
+ require 'business_central/balance_sheet'
16
+ require 'business_central/cash_flow_statement'
17
+ require 'business_central/company'
18
+ require 'business_central/company_information'
19
+ require 'business_central/countries_region'
20
+ require 'business_central/currency'
21
+ require 'business_central/customer'
22
+ require 'business_central/customer_financial_details'
23
+ require 'business_central/customer_payment'
24
+ require 'business_central/customer_payments_journal'
25
+ require 'business_central/customer_sales'
26
+ require 'business_central/dimension'
27
+ require 'business_central/dimension_line'
28
+ require 'business_central/employee'
29
+ require 'business_central/general_ledger_entry'
30
+ require 'business_central/income_statement'
31
+ require 'business_central/irs_1099_code'
32
+ require 'business_central/item'
33
+ require 'business_central/item_category'
34
+ require 'business_central/journal'
35
+ require 'business_central/journal_line'
36
+ require 'business_central/payment_method'
37
+ require 'business_central/payment_term'
38
+ require 'business_central/picture'
39
+ require 'business_central/purchase_invoice'
40
+ require 'business_central/purchase_invoice_line'
41
+ require 'business_central/retained_earnings_statement'
42
+ require 'business_central/sales_credit_memo'
43
+ require 'business_central/sales_credit_memo_line'
44
+ require 'business_central/sales_invoice'
45
+ require 'business_central/sales_invoice_line'
46
+ require 'business_central/sales_order'
47
+ require 'business_central/sales_order_line'
48
+ require 'business_central/sales_quote'
49
+ require 'business_central/sales_quote_line'
50
+ require 'business_central/shipment_method'
51
+ require 'business_central/subscription'
52
+ require 'business_central/tax_area'
53
+ require 'business_central/tax_group'
54
+ require 'business_central/trial_balance'
55
+ require 'business_central/unit_of_measure'
56
+ require 'business_central/vendor'
57
+ require 'business_central/vendor_purchase'
58
+
59
+
60
+ module BusinessCentral
61
+ API_PATH = "/api/v1.0"
62
+ API_VERSION = "/v1.0"
63
+ ENDPOINT_TEST = "https://api.businesscentral.dynamics.com"
64
+ ENDPOINT_PRODUCTION = "https://api.businesscentral.dynamics.com"
65
+ end
66
+
67
+ ServiceUnavailableError = Class.new(StandardError)
@@ -0,0 +1,26 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::AccountTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api_account = BusinessCentral::Account.new(bc_client)
6
+ assert_not_nil api_account
7
+ end
8
+
9
+ def test_get_accounts
10
+ stub_get("accounts").
11
+ with(headers: stub_headers).
12
+ to_return( status: 200, body: fixture("get_accounts_200.json"))
13
+
14
+ accounts = BusinessCentral::Account.new(bc_client).get
15
+ assert accounts.length > 0
16
+ end
17
+
18
+ def test_get_account
19
+ stub_get("accounts(1234)").
20
+ with(headers: stub_headers).
21
+ to_return(status: 200, body: fixture("get_account_200.json"))
22
+
23
+ account = BusinessCentral::Account.new(bc_client).get("1234")
24
+ assert_equal "Depreciation, Equipment", account.displayName
25
+ end
26
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::AgedAccountsPayableTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::AgedAccountsPayable.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::AgedAccountsReceivableTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::AgedAccountsReceivable.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::BaseTest < Test::Unit::TestCase
4
+ def setup
5
+ BusinessCentral::Base.const_set("API_OBJECT", "bar")
6
+ BusinessCentral::Base.const_set("API_OBJECT_PARENT", "foo")
7
+ BusinessCentral::Base.const_set("SUPPORTED_METHODS", [:get])
8
+ end
9
+
10
+ test "should initialize with a client" do
11
+ base = BusinessCentral::Base.new(bc_client)
12
+ assert_not_nil base
13
+ assert_not_nil base.client
14
+ end
15
+
16
+ test "should build a URL with only a single parameter" do
17
+ base = BusinessCentral::Base.new(bc_client)
18
+ # base.const_set(API_OBJECT, "foo")
19
+ url = base.build_url("1234")
20
+ assert_equal '/foo(1234)/bar', url
21
+ end
22
+
23
+ test "should build a URL with multiple parameters" do
24
+ base = BusinessCentral::Base.new(bc_client)
25
+ url = base.build_url("1234", "4321")
26
+ assert_equal "/foo(1234)/bar(4321)", url
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CompanyInformationTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api = BusinessCentral::CompanyInformation.new(bc_client)
6
+ assert_not_nil api
7
+ end
8
+ end
@@ -0,0 +1,27 @@
1
+ require 'test_helper'
2
+
3
+ class BusinessCentral::CompanyTest < Test::Unit::TestCase
4
+ def test_initialize
5
+ api_company = BusinessCentral::Company.new(bc_client)
6
+ assert_not_nil api_company
7
+ end
8
+
9
+ def test_company_success
10
+ stub_get("companies(1234)").
11
+ with(headers: stub_headers).
12
+ to_return(status: 200, body: fixture("get_company_200.json"))
13
+
14
+ company = BusinessCentral::Company.new(bc_client).get("1234")
15
+ assert_equal "CRONUS AU", company.name
16
+ end
17
+
18
+ def test_companies_success
19
+ stub_get("companies").
20
+ with(headers: stub_headers).
21
+ to_return(status: 200, body: fixture("get_companies_200.json"))
22
+
23
+ companies = BusinessCentral::Company.new(bc_client).get
24
+ assert_equal 1, companies.length
25
+ assert_equal "CRONUS AU", companies.first.name
26
+ end
27
+ end