Class: BusinessCentral::Base

Inherits:
Object
  • Object
show all
Includes:
ApiMethods
Defined in:
lib/business_central/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from ApiMethods

#create, #delete, #get, #get_child, #method_missing, #query, #query_child, #update

Constructor Details

#initialize(client) ⇒ Base

The Base class used to provide functionality to subclasses

Parameters:



15
16
17
# File 'lib/business_central/base.rb', line 15

def initialize(client)
  @client = client.nil? ? BusinessCentral::Client.new() : client
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class BusinessCentral::ApiMethods

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



9
10
11
# File 'lib/business_central/base.rb', line 9

def client
  @client
end

Instance Method Details

#build_url(parent_id, child_id = nil) ⇒ Object

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

Parameters:

  • parent_id (String)

    the ID of the parent object

  • child_id (String) (defaults to: nil)

    any additional options



35
36
37
38
39
40
41
42
43
# 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) ⇒ Object

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

Parameters:

  • response (Net::HTTPResponse)


24
25
26
27
28
# File 'lib/business_central/base.rb', line 24

def process(response)
  BusinessCentral::Response::ResponseHandler.
    new(@client.dataset(response)).
    compiled_data
end