Module: Lexer::Identity

Defined in:
lib/lexer/identity.rb,
lib/lexer/identity/api.rb,
lib/lexer/identity/version.rb,
lib/lexer/identity/configuration.rb,
lib/lexer/identity/enriched_result.rb

Overview

:nordoc:

Defined Under Namespace

Classes: AuthenticationError, BadRequestError, Configuration, ConfigurationError, EnrichedResult, Error, HttpError, NotFoundError

Constant Summary collapse

VERSION =
'0.1.0'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



62
63
64
# File 'lib/lexer/identity.rb', line 62

def configuration
  @configuration
end

.loggerObject

Defines the modules logger Accessible via:

Lexer::Identity.logger


70
71
72
73
74
75
76
# File 'lib/lexer/identity.rb', line 70

def logger
  @logger ||= lambda do
    logger = Logger.new($stdout)
    logger.level = Logger::INFO
    logger
  end.call
end

Class Method Details

.configure {|configuration| ... } ⇒ Object

Creates or uses active configutation See Lexer::Identity.configuration for options

Yields:



81
82
83
84
85
86
# File 'lib/lexer/identity.rb', line 81

def self.configure
  self.configuration ||= Configuration.new
  yield(configuration)

  self.configuration
end

.enrich(links: {}, attributes: {}) ⇒ Object

The backbone of the Identity API. Enrich accepts links and attributes as per the API Documentation hosted at developer.lexer.io/

Options:

links - A hash of links to search for and link to the identity. Default: {}. attributes - A hash of attributes where keys are valid namespaces. Default: {}.

Response:

A hash containing the Lexer Identity ID and any attributes on the identity



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/lexer/identity/api.rb', line 21

def self.enrich(links: {}, attributes: {})
  # ensure the module is configured
  fail Lexer::Identity::ConfigurationError, 'Module has not been configured.' if configuration.nil?
  configuration.validate

  # produce the request body
  body = {}
  body[:links] = links
  body[:attributes] = attributes unless configuration.contributor_token.nil?
  body[:api_token] = configuration.api_token unless configuration.api_token.nil?
  body[:contributor_token] = configuration.contributor_token unless configuration.contributor_token.nil?
  body[:consumer_token] = configuration.consumer_token unless configuration.consumer_token.nil?

  post_request body
end