Module: Frodo::Concerns::Base

Included in:
AbstractClient
Defined in:
lib/frodo/concerns/base.rb

Constant Summary collapse

MIME_TYPES =
{
  json:  'application/json'
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



6
7
8
# File 'lib/frodo/concerns/base.rb', line 6

def options
  @options
end

Instance Method Details

#initialize(opts = {}) {|builder| ... } ⇒ Object

Public: Creates a new client instance

opts - A hash of options to be passed in (default: {}).

:oauth_token             - The String oauth access token to authenticate
                           API calls (required unless password
                           authentication is used).
:refresh_token           - The String refresh token to obtain fresh
                           OAuth access tokens (required if oauth
                           authentication is used).
:instance_url            - The String base url for all api requests
                           (required if oauth authentication is used).

:client_id               - The oauth client id to use. Needed for both
                           password and oauth authentication
:client_secret           - The oauth client secret to use. Required for
                           client_credentials auth flow
:tenant_id               - The Azure AD tenant id. Required for
                           client_credentials and password auth flows
:username                - User's dynamics username for password auth flow
:password                - User's dynamics password for password auth flow

:host                    - The String hostname to use during
                           authentication requests
                           (default: 'login.microsoftonline.com').

:base_path              - The base path for the REST api. (default: '/')

:authentication_retries  - The number of times that client
                           should attempt to reauthenticate
                           before raising an exception (default: 3).

:compress                - Set to true to have Dynamics compress the
                           response (default: false).
:raw_json                 - Set to true to skip the conversion of
                           Entities responses (default: false).
:timeout                 - Faraday connection request read/open timeout.
                           (default: nil).

:proxy_uri               - Proxy URI: 'http://proxy.example.com:port' or
                           'http://user@pass:proxy.example.com:port'

:authentication_callback - A Proc that is called with the response body
                           after a successful authentication.

:request_headers         - A hash containing custom headers that will be
                           appended to each request

:with_metadata           - Flag to specify if we need to use metadata

Yields:

  • (builder)

Raises:

  • (ArgumentError)


62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/frodo/concerns/base.rb', line 62

def initialize(opts = {})
  raise ArgumentError, 'Please specify a hash of options' unless opts.is_a?(Hash)

  # allow injecting the service for performance purpose such as
  # when you have already a local schema
  @service = opts.delete(:service)

  @options = Hash[Frodo.configuration.options.map do |option|
    [option, Frodo.configuration.send(option)]
  end]

  @options.merge! opts
  yield builder if block_given?
end

#inspectObject



86
87
88
# File 'lib/frodo/concerns/base.rb', line 86

def inspect
  "#<#{self.class} @options=#{@options.inspect}>"
end

#instance_urlObject



77
78
79
80
# File 'lib/frodo/concerns/base.rb', line 77

def instance_url
  authenticate! unless options[:instance_url]
  options[:instance_url]
end

#serviceObject



82
83
84
# File 'lib/frodo/concerns/base.rb', line 82

def service
  @service ||= Frodo::Service.new(instance_url, strict: false, metadata_document: , with_metadata: options[:with_metadata] )
end