Module: Zaikio::Directory

Defined in:
lib/zaikio/directory.rb,
lib/zaikio/directory/base.rb,
lib/zaikio/directory/role.rb,
lib/zaikio/directory/site.rb,
lib/zaikio/directory/asset.rb,
lib/zaikio/directory/person.rb,
lib/zaikio/directory/machine.rb,
lib/zaikio/directory/version.rb,
lib/zaikio/directory/software.rb,
lib/zaikio/directory/connection.rb,
lib/zaikio/directory/membership.rb,
lib/zaikio/directory/specialist.rb,
lib/zaikio/directory/json_parser.rb,
lib/zaikio/directory/organization.rb,
lib/zaikio/directory/subscription.rb,
lib/zaikio/directory/test_account.rb,
lib/zaikio/directory/configuration.rb,
lib/zaikio/directory/current_person.rb,
lib/zaikio/directory/current_organization.rb,
lib/zaikio/directory/revoked_access_token.rb,
lib/zaikio/directory/basic_auth_middleware.rb,
lib/zaikio/directory/business_relationship.rb,
lib/zaikio/directory/organization_membership.rb,
lib/zaikio/directory/authorization_middleware.rb

Defined Under Namespace

Modules: Asset Classes: AuthorizationMiddleware, Base, BasicAuthMiddleware, BusinessRelationship, Configuration, Connection, CurrentOrganization, CurrentPerson, JSONParser, Machine, Membership, Organization, OrganizationMembership, Person, RevokedAccessToken, Role, Site, Software, Specialist, Subscription, TestAccount

Constant Summary collapse

VERSION =
"0.2.0".freeze

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationObject

Returns the value of attribute configuration.



32
33
34
# File 'lib/zaikio/directory.rb', line 32

def configuration
  @configuration
end

Class Method Details

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

Yields:



36
37
38
39
40
41
42
# File 'lib/zaikio/directory.rb', line 36

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

  Base.connection = create_connection
end

.create_connectionObject



66
67
68
69
70
71
72
73
74
75
76
# File 'lib/zaikio/directory.rb', line 66

def create_connection
  self.connection = Faraday.new(url: "#{configuration.host}/api/v1",
                                ssl: { verify: configuration.environment != :test }) do |c|
    c.request     :json
    c.response    :logger, configuration&.logger
    c.use         JSONParser
    c.use         AuthorizationMiddleware
    c.use         BasicAuthMiddleware
    c.adapter     Faraday.default_adapter
  end
end

.current_token_dataObject



58
59
60
61
62
63
64
# File 'lib/zaikio/directory.rb', line 58

def current_token_data
  return unless AuthorizationMiddleware.token

  payload = JWT.decode(AuthorizationMiddleware.token, nil, false).first

  create_token_data(payload)
end

.with_basic_auth(login, password) ⇒ Object



51
52
53
54
55
56
# File 'lib/zaikio/directory.rb', line 51

def with_basic_auth(, password)
  BasicAuthMiddleware.credentials = [, password]
  yield
ensure
  BasicAuthMiddleware.reset_credentials
end

.with_token(token) ⇒ Object



44
45
46
47
48
49
# File 'lib/zaikio/directory.rb', line 44

def with_token(token)
  AuthorizationMiddleware.token = token
  yield
ensure
  AuthorizationMiddleware.reset_token
end