module Crm

@api public

Public Class Methods

autoload_module(mod, mod_source) click to toggle source
# File lib/crm.rb, line 25
def self.autoload_module(mod, mod_source)
  mod_dir = mod_source.gsub(/\.rb$/, '')
  Dir.glob("#{mod_dir}/*.rb").each do |file|
    name = File.basename(file, ".rb")
    mod.autoload name.camelcase, file
  end
end
configure() { |config| ... } click to toggle source

Configures the JustRelate WebCRM SDK. The config keys tenant, login and api_key must be provided. @example

Crm.configure do |config|
  config.tenant  = 'my_tenant'
  config.login   = 'my_login'
  config.api_key = 'my_api_key'
end

@yieldparam config [Crm::Core::Configuration] @return [void] @api public

# File lib/crm.rb, line 18
def self.configure
  config = ::Crm::Core::Configuration.new
  yield config
  config.validate!
  Core::RestApi.instance = Core::RestApi.new(config.endpoint_uri, config.login, config.api_key)
end
find(*ids) click to toggle source

Fetches multiple items by ids. The base type of the items can be mixed (e.g. a {Crm::Contact} or {Crm::Account}). @example

Crm.find('e70a7123f499c5e0e9972ab4dbfb8fe3')
# => Crm::Contact

Crm.find('e70a7123f499c5e0e9972ab4dbfb8fe3', '2185dd25c2f4fa41fbef422c1b9cfc38')
# => Crm::Core::ItemEnumerator

Crm.find(['e70a7123f499c5e0e9972ab4dbfb8fe3', '2185dd25c2f4fa41fbef422c1b9cfc38'])
# => Crm::Core::ItemEnumerator

@param ids [String, Array<String>] A single ID or a list of IDs. @return [Crm::Core::BasicResource]

A {Crm::Core::BasicResource single item} if the method was called with a single ID.

@return [Crm::Core::ItemEnumerator]

An {Crm::Core::ItemEnumerator enumerator} if the method was called with multiple IDs.

@raise [Errors::ResourceNotFound] if at least one of the IDs could not be found. @api public

# File lib/crm.rb, line 51
def self.find(*ids)
  flattened_ids = ids.flatten
  if flattened_ids.compact.blank?
    raise Crm::Errors::ResourceNotFound.new(
        "Items could not be found.", flattened_ids)
  end
  enumerator = Core::ItemEnumerator.new(flattened_ids)

  if ids.size == 1 && !ids.first.kind_of?(Array)
    enumerator.first
  else
    enumerator
  end
end