module LibLynxAPI
Constants
- SCHEMA
- VERSION
Public Class Methods
Get a Client
configured to use HTTP Basic or header-based authentication.
@param api_key [String] The API key to use when connecting. @param options [Hash<Symbol,String>] Optionally, custom settings
to use with the client. Allowed options are `default_headers`, `cache`, `user` and `url`.
@return [Client] A client configured to use the API with HTTP Basic
or header-based authentication.
# 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
Get a Client
configured to use OAuth authentication.
@param oauth_token [String] The OAuth token to use with the API. @param options [Hash<Symbol,String>] Optionally, custom settings
to use with the client. Allowed options are `default_headers`, `cache` and `url`.
@return [Client] A client configured to use the API with OAuth
authentication.
# 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
Get a Client
configured to use OAuth2 client credentials authentication.
@param id [String] The client id to use with the API. @param secret [String] The client secret to use with the API. @return [Client] A client configured to use the API with OAuth2
authentication.
# 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
Get a Client
configured to use Token
authentication.
@param token [String] The token to use with the API. @param options [Hash<Symbol,String>] Optionally, custom settings
to use with the client. Allowed options are `default_headers`, `cache` and `url`.
@return [Client] A client configured to use the API with OAuth
authentication.
# 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
Private Class Methods
Get customized options.
# File lib/liblynx-api/client.rb, line 71 def self.custom_options(options) return default_options if options.nil? final_options = default_options if options[:default_headers] final_options[:default_headers].merge!(options[:default_headers]) end final_options[:cache] = options[:cache] || Moneta.new(:File, dir: "#{Dir.home}/.heroics/liblynx-api") final_options[:url] = options[:url] if options[:url] final_options[:user] = options[:user] if options[:user] final_options end
Get the default options.
# File lib/liblynx-api/client.rb, line 85 def self.default_options default_headers = {"Accept"=>"application/json", "User-Agent"=>"liblynx-api/1.2.1"} { default_headers: default_headers, url: "https://connect.liblynx.com" } end