Class: BusinessCentral::Client
- Inherits:
-
Object
- Object
- BusinessCentral::Client
- Defined in:
- lib/business_central/client.rb
Instance Attribute Summary collapse
-
#api_company_id ⇒ Object
readonly
Returns the value of attribute api_company_id.
-
#api_host ⇒ Object
readonly
Returns the value of attribute api_host.
-
#api_password ⇒ Object
readonly
Returns the value of attribute api_password.
-
#api_path ⇒ Object
readonly
Returns the value of attribute api_path.
-
#api_tenant ⇒ Object
readonly
Returns the value of attribute api_tenant.
-
#api_username ⇒ Object
readonly
Returns the value of attribute api_username.
-
#api_version ⇒ Object
readonly
Returns the value of attribute api_version.
Instance Method Summary collapse
-
#base_url ⇒ Object
Returns the URL used for interacting with the API.
- #dataset(response) ⇒ Object
-
#delete(url, etag) ⇒ Object
Performs a DELETE operation.
-
#get(url) ⇒ Object
Performs a GET operation.
-
#initialize(opts = {}) ⇒ Client
constructor
Creates an instance of the BusinessCentral::Client.
-
#patch(url, etag, data) ⇒ Object
Performs a PATCH operation.
-
#post(url, data) ⇒ Object
Performs a POST operation.
Constructor Details
#initialize(opts = {}) ⇒ Client
Creates an instance of the BusinessCentral::Client.
Pass in a Hash of the various options:
api_version: The path of the API Version - eg "/v1.0"
api_path: Appended after the API Version - eg "/api/v1.0"
api_username: Used for Basic Auth
api_password: Used for Basic Auth
api_tenant: The tenant domain for your BusinessCentral installation
api_company_id: The company that will be queried
22 23 24 25 26 27 28 29 30 |
# File 'lib/business_central/client.rb', line 22 def initialize(opts = {}) @api_version = opts[:api_version] ||= BusinessCentral::API_VERSION @api_path = opts[:api_path] ||= BusinessCentral::API_PATH @api_tenant = opts[:api_tenant] ||= ENV['BC_TENANT'] @api_username = opts[:api_username] ||= ENV['BC_USERNAME'] @api_password = opts[:api_password] ||= ENV['BC_PASSWORD'] @api_company_id = opts[:api_company_id] ||= ENV['BC_COMPANY_ID'] @api_host = opts[:api_host] ||= ENV['BC_HOST'] end |
Instance Attribute Details
#api_company_id ⇒ Object (readonly)
Returns the value of attribute api_company_id.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_company_id @api_company_id end |
#api_host ⇒ Object (readonly)
Returns the value of attribute api_host.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_host @api_host end |
#api_password ⇒ Object (readonly)
Returns the value of attribute api_password.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_password @api_password end |
#api_path ⇒ Object (readonly)
Returns the value of attribute api_path.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_path @api_path end |
#api_tenant ⇒ Object (readonly)
Returns the value of attribute api_tenant.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_tenant @api_tenant end |
#api_username ⇒ Object (readonly)
Returns the value of attribute api_username.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_username @api_username end |
#api_version ⇒ Object (readonly)
Returns the value of attribute api_version.
7 8 9 |
# File 'lib/business_central/client.rb', line 7 def api_version @api_version end |
Instance Method Details
#base_url ⇒ Object
Returns the URL used for interacting with the API
36 37 38 39 40 41 42 |
# File 'lib/business_central/client.rb', line 36 def base_url url = "#{@api_host}#{@api_version}/#{@api_tenant}#{@api_path}" unless @api_company_id.nil? url += "/companies(#{@api_company_id})" end url end |
#dataset(response) ⇒ Object
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/business_central/client.rb', line 88 def dataset(response) json = JSON.parse(response.body) if !json["value"].nil? json["value"] else json end # rescue # {} end |
#delete(url, etag) ⇒ Object
Performs a DELETE operation
83 84 85 86 |
# File 'lib/business_central/client.rb', line 83 def delete(url, etag) request = build_request({ verb: "Delete", url: url, etag: etag }) perform_request(request) end |
#get(url) ⇒ Object
Performs a GET operation
49 50 51 52 |
# File 'lib/business_central/client.rb', line 49 def get(url) request = build_request({ verb: "Get", url: url }) perform_request(request) end |
#patch(url, etag, data) ⇒ Object
Performs a PATCH operation
72 73 74 75 |
# File 'lib/business_central/client.rb', line 72 def patch(url, etag, data) request = build_request({ verb: "Patch", url: url, data: data, etag: etag }) perform_request(request) end |
#post(url, data) ⇒ Object
Performs a POST operation
60 61 62 63 |
# File 'lib/business_central/client.rb', line 60 def post(url, data) request = build_request({ verb: "Post", url: url, data: data }) perform_request(request) end |