Module: LibLynxAPI

Defined in:
lib/liblynx-api.rb,
lib/liblynx-api/client.rb,
lib/liblynx-api/version.rb

Defined Under Namespace

Classes: Account, Client, Identification, Idp, Samlidp, Token

Constant Summary collapse

VERSION =
'1.1.2'

Class Method Summary collapse

Class Method Details

.connect(api_key, options = nil) ⇒ Client

Get a Client configured to use HTTP Basic or header-based authentication.

Parameters:

  • api_key (String)

    The API key to use when connecting.

  • options (Hash<Symbol,String>) (defaults to: nil)

    Optionally, custom settings to use with the client. Allowed options are ‘default_headers`, `cache`, `user` and `url`.

Returns:

  • (Client)

    A client configured to use the API with HTTP Basic or header-based authentication.



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/liblynx-api/client.rb', line 23

def self.connect(api_key, options=nil)
  options = custom_options(options)
  uri = URI.parse(options[:url])

  if options[:user]
    uri.user = URI.encode_www_form_component options[:user]
  end

  if api_key
    uri.user ||= 'user'
    uri.password = api_key
  end

  client = Heroics.client_from_schema(SCHEMA, uri.to_s, options)
  Client.new(client)
end

.connect_oauth(oauth_token, options = nil) ⇒ Client

Get a Client configured to use OAuth authentication.

Parameters:

  • oauth_token (String)

    The OAuth token to use with the API.

  • options (Hash<Symbol,String>) (defaults to: nil)

    Optionally, custom settings to use with the client. Allowed options are ‘default_headers`, `cache` and `url`.

Returns:

  • (Client)

    A client configured to use the API with OAuth authentication.



48
49
50
51
52
53
# File 'lib/liblynx-api/client.rb', line 48

def self.connect_oauth(oauth_token, options=nil)
  options = custom_options(options)
  url = options[:url]
  client = Heroics.oauth_client_from_schema(oauth_token, SCHEMA, url, options)
  Client.new(client)
end

.connect_oauth2(id, secret) ⇒ Client

Get a Client configured to use OAuth2 client credentials authentication.

Parameters:

  • id (String)

    The client id to use with the API.

  • secret (String)

    The client secret to use with the API.

Returns:

  • (Client)

    A client configured to use the API with OAuth2 authentication.



14
15
16
17
18
19
20
21
# File 'lib/liblynx-api.rb', line 14

def self.connect_oauth2(id, secret)
  client = connect(secret, user: id)
  token = client
    .token
    .create(grant_type: :client_credentials)
    .dig('access_token')
  connect_oauth(token)
end

.connect_token(token, options = nil) ⇒ Client

Get a Client configured to use Token authentication.

Parameters:

  • token (String)

    The token to use with the API.

  • options (Hash<Symbol,String>) (defaults to: nil)

    Optionally, custom settings to use with the client. Allowed options are ‘default_headers`, `cache` and `url`.

Returns:

  • (Client)

    A client configured to use the API with OAuth authentication.



63
64
65
66
67
68
# File 'lib/liblynx-api/client.rb', line 63

def self.connect_token(token, options=nil)
  options = custom_options(options)
  url = options[:url]
  client = Heroics.token_client_from_schema(token, SCHEMA, url, options)
  Client.new(client)
end