class BusinessCentral::Base

Attributes

client[R]

Public Class Methods

new(client) click to toggle source

The Base class used to provide functionality to subclasses

@param client [BusinessCentral::Client]

# File lib/business_central/base.rb, line 15
def initialize(client)
  @client = client.nil? ? BusinessCentral::Client.new() : client
end

Public Instance Methods

build_url(parent_id, child_id = nil) click to toggle source

Use the BusinessCentral::URLBuilder to create the URL to query the API

@param parent_id [String] the ID of the parent object @param child_id [String] any additional options

# File lib/business_central/base.rb, line 35
def build_url(parent_id, child_id = nil)
  options = { child_path: api_object }

  if !child_id.nil?
    options[:child_id] = child_id
  end

  BusinessCentral::URLBuilder.new(api_object_parent, parent_id, options).url
end
process(response) click to toggle source

Use a BusinessCentral::Response::ResponseHandler to proces the results from the API query

@param response [Net::HTTPResponse]

# File lib/business_central/base.rb, line 24
def process(response)
  BusinessCentral::Response::ResponseHandler.
    new(@client.dataset(response)).
    compiled_data
end

Private Instance Methods

handle_error(response) click to toggle source

Check to see if the response contains an error and raise an error if required

@param response [Net::HTTPResponse]

# File lib/business_central/base.rb, line 52
def handle_error(response)
  # raise ServiceUnavailableError unless ["200", "201", "204"].include?(response.code)
end