module Api::Configurable

Configuration options for {Client}, defaulting to values in {Default}

Attributes

access_token[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
access_token_prefix[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
api_endpoint[W]
api_version[W]
auto_paginate[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
basic_login[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
basic_password[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
connection_options[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
per_page[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
sawyer_options[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30
user_agent[RW]

@!attribute [w] access_token

@return [String] access token for authentication

@!attribute [w] access_token_prefix

@return [String] access token prefix used before token in Authorization header

@!attribute api_endpoint

@return [String] Base URL for API requests.

@!attribute api_version

@return [String] Version of the api. default: v1

@!attribute [w] basic_login

@return [String] login for basic authentication

@!attribute [w] basic_password

@return [String] password for basic authentication

@!attribute connection_options

@see https://github.com/lostisland/faraday
@return [Hash] Configure connection options for Faraday

@!attribute sawyer_options

@see https://github.com/lostisland/sawyer
@return [Hash] Configure sawyer options

@!attribute user_agent

@return [String] Configure User-Agent header for requests.

@!attribute auto_paginate

@return [Boolean] Auto fetch next page of results until rate limit reached. Will only work with an Hypermedia API.

@!attribute per_page

@return [String] Configure page size for paginated results. API default: 30

Public Class Methods

keys() click to toggle source

List of configurable keys for {Api::Client} @return [Array] of option keys

# File lib/api/configurable.rb, line 38
def keys
  @keys ||= [
    :access_token,
    :access_token_prefix,
    :api_endpoint,
    :api_version,
    :auto_paginate,
    :basic_login,
    :basic_password,
    :connection_options,
    :sawyer_options,
    :per_page,
    :user_agent,
  ]
end

Public Instance Methods

api_endpoint() click to toggle source
# File lib/api/configurable.rb, line 78
def api_endpoint
  File.join(@api_endpoint, "")
end
api_version() click to toggle source
# File lib/api/configurable.rb, line 82
def api_version
  if @api_version.nil?
    ""
  else
    File.join(@api_version, "")
  end
end
configure() { |self| ... } click to toggle source

Set configuration options using a block

# File lib/api/configurable.rb, line 56
def configure
  yield self
end
reset!(options = {}) click to toggle source

Reset configuration options to default values

# File lib/api/configurable.rb, line 69
def reset!(options = {})
  default_class = module_defaults || class_defaults
  Api::Configurable.keys.each do |key|
    value = options[key] || default_class.options[key] || Api::Default.options[key]
    instance_variable_set(:"@#{key}", value)
  end
  self
end
same_options?(opts) click to toggle source

Compares client options to a Hash of requested options

@param opts [Hash] Options to compare with current client options @return [Boolean]

# File lib/api/configurable.rb, line 64
def same_options?(opts)
  opts.hash == options.hash
end

Private Instance Methods

class_defaults() click to toggle source
# File lib/api/configurable.rb, line 100
def class_defaults
  try_defaults("#{self.class.to_s.split("::").first}::Default")
end
module_defaults() click to toggle source
# File lib/api/configurable.rb, line 96
def module_defaults
  try_defaults("#{self}::Default")
end
options() click to toggle source
# File lib/api/configurable.rb, line 92
def options
  Hash[Api::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
end
try_defaults(object_name) click to toggle source
# File lib/api/configurable.rb, line 104
def try_defaults(object_name)
  Object.const_get(object_name)
rescue NameError => _e
  nil
end