Module: Carriots::Configurable

Included in:
Carriots, Client
Defined in:
lib/carriots/configurable.rb

Overview

Configuration options for Client, defaulting to values in Default

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_endpointString

Returns Base URL for API requests. default: api.carriots.com/.

Returns:



23
# File 'lib/carriots/configurable.rb', line 23

attr_accessor :default_media_type, :connection_options, :user_agent, :login

#connection_optionsHash

Returns Configure connection options for Faraday.

Returns:

  • (Hash)

    Configure connection options for Faraday

See Also:



23
# File 'lib/carriots/configurable.rb', line 23

attr_accessor :default_media_type, :connection_options, :user_agent, :login

#default_media_typeString

Returns Configure preferred media type (for API versioning, for example).

Returns:

  • (String)

    Configure preferred media type (for API versioning, for example)

See Also:



23
24
25
# File 'lib/carriots/configurable.rb', line 23

def default_media_type
  @default_media_type
end

#loginObject

Returns the value of attribute login.



23
24
25
# File 'lib/carriots/configurable.rb', line 23

def 
  @login
end

#user_agentString

Returns Configure User-Agent header for requests.

Returns:

  • (String)

    Configure User-Agent header for requests.



23
# File 'lib/carriots/configurable.rb', line 23

attr_accessor :default_media_type, :connection_options, :user_agent, :login

#web_endpointString

Base URL for generated web URLs

Returns:



23
# File 'lib/carriots/configurable.rb', line 23

attr_accessor :default_media_type, :connection_options, :user_agent, :login

#write_api_keyObject



75
76
77
# File 'lib/carriots/configurable.rb', line 75

def write_api_key
  @write_api_key.to_s
end

Class Method Details

.keysArray

List of configurable keys for Carriots::Client

Returns:

  • (Array)

    of option keys



29
30
31
32
33
34
35
36
37
38
39
# File 'lib/carriots/configurable.rb', line 29

def keys
  @keys ||= [
    :api_endpoint,
    :connection_options,
    :default_media_type,
    :user_agent,
    :web_endpoint,
    :login,
    :write_api_key
  ]
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Set configuration options using a block

Yields:

  • (_self)

Yield Parameters:



43
44
45
# File 'lib/carriots/configurable.rb', line 43

def configure
  yield self
end

#reset!Object Also known as: setup

Reset configuration options to default values



48
49
50
51
52
53
# File 'lib/carriots/configurable.rb', line 48

def reset!
  Carriots::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", Carriots::Default.options[key])
  end
  self
end

#same_options?(opts) ⇒ Boolean

Compares client options to a Hash of requested options

Parameters:

  • opts (Hash)

    Options to compare with current client options

Returns:

  • (Boolean)


60
61
62
# File 'lib/carriots/configurable.rb', line 60

def same_options?(opts)
  opts.hash == options.hash
end