Module: Carriots::Configurable
Overview
Instance Attribute Summary collapse
-
#api_endpoint ⇒ String
Base URL for API requests.
-
#connection_options ⇒ Hash
Configure connection options for Faraday.
-
#default_media_type ⇒ String
Configure preferred media type (for API versioning, for example).
-
#login ⇒ Object
Returns the value of attribute login.
-
#user_agent ⇒ String
Configure User-Agent header for requests.
-
#web_endpoint ⇒ String
Base URL for generated web URLs.
- #write_api_key ⇒ Object
Class Method Summary collapse
-
.keys ⇒ Array
List of configurable keys for Client.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Set configuration options using a block.
-
#reset! ⇒ Object
(also: #setup)
Reset configuration options to default values.
-
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options.
Instance Attribute Details
#api_endpoint ⇒ String
Returns Base URL for API requests. default: api.carriots.com/.
23 |
# File 'lib/carriots/configurable.rb', line 23 attr_accessor :default_media_type, :connection_options, :user_agent, :login |
#connection_options ⇒ Hash
Returns Configure connection options for Faraday.
23 |
# File 'lib/carriots/configurable.rb', line 23 attr_accessor :default_media_type, :connection_options, :user_agent, :login |
#default_media_type ⇒ String
Returns Configure preferred media type (for API versioning, for example).
23 24 25 |
# File 'lib/carriots/configurable.rb', line 23 def default_media_type @default_media_type end |
#login ⇒ Object
Returns the value of attribute login.
23 24 25 |
# File 'lib/carriots/configurable.rb', line 23 def login @login end |
#user_agent ⇒ String
Returns 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_endpoint ⇒ String
Base URL for generated web URLs
23 |
# File 'lib/carriots/configurable.rb', line 23 attr_accessor :default_media_type, :connection_options, :user_agent, :login |
#write_api_key ⇒ Object
75 76 77 |
# File 'lib/carriots/configurable.rb', line 75 def write_api_key @write_api_key.to_s end |
Class Method Details
.keys ⇒ Array
List of configurable keys for Carriots::Client
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
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.[key]) end self end |
#same_options?(opts) ⇒ Boolean
Compares client options to a Hash of requested options
60 61 62 |
# File 'lib/carriots/configurable.rb', line 60 def (opts) opts.hash == .hash end |