Module: DeskApi::Configuration
Overview
Configuration allows to configure a Client. It exposes all available configuration options to the client and makes sure secrets are only readable by the client.
Instance Attribute Summary collapse
-
#connection_options ⇒ Object
Returns the value of attribute connection_options.
-
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
-
#consumer_secret ⇒ Object
writeonly
Sets the attribute consumer_secret.
-
#endpoint ⇒ String
Builds the endpoint using the subdomain if the endpoint isn't set.
-
#middleware ⇒ Proc
Returns the middleware proc to be used by Faraday.
-
#password ⇒ Object
writeonly
Sets the attribute password.
-
#subdomain ⇒ Object
Returns the value of attribute subdomain.
-
#token ⇒ Object
writeonly
Sets the attribute token.
-
#token_secret ⇒ Object
writeonly
Sets the attribute token_secret.
-
#username ⇒ Object
Returns the value of attribute username.
Class Method Summary collapse
-
.included(_base) ⇒ Object
Registers the middleware when the module is included.
-
.keys ⇒ Array
Returns an array of possible configuration options.
-
.register_middleware(type, sym, cls) ⇒ Object
Allows to register middleware for Faraday v0.8 and v0.9.
Instance Method Summary collapse
-
#configure {|DeskApi::Client| ... } ⇒ DeskApi::Client
Allows to configure the client by yielding self.
-
#credentials? ⇒ Boolean
Returns true if either all oauth values or all basic auth values are set.
-
#reset! ⇒ DeskApi::Client
(also: #setup)
Resets the client to the default settings.
Instance Attribute Details
#connection_options ⇒ Object
Returns the value of attribute connection_options.
55 56 57 |
# File 'lib/desk_api/configuration.rb', line 55 def @connection_options end |
#consumer_key ⇒ Object
Returns the value of attribute consumer_key.
55 56 57 |
# File 'lib/desk_api/configuration.rb', line 55 def consumer_key @consumer_key end |
#consumer_secret=(value) ⇒ Object (writeonly)
Sets the attribute consumer_secret
54 55 56 |
# File 'lib/desk_api/configuration.rb', line 54 def consumer_secret=(value) @consumer_secret = value end |
#endpoint ⇒ String
Builds the endpoint using the subdomain if the endpoint isn't set
102 103 104 |
# File 'lib/desk_api/configuration.rb', line 102 def endpoint @endpoint end |
#middleware ⇒ Proc
Returns the middleware proc to be used by Faraday
109 110 111 |
# File 'lib/desk_api/configuration.rb', line 109 def middleware @middleware end |
#password=(value) ⇒ Object (writeonly)
Sets the attribute password
54 55 56 |
# File 'lib/desk_api/configuration.rb', line 54 def password=(value) @password = value end |
#subdomain ⇒ Object
Returns the value of attribute subdomain.
55 56 57 |
# File 'lib/desk_api/configuration.rb', line 55 def subdomain @subdomain end |
#token=(value) ⇒ Object (writeonly)
Sets the attribute token
54 55 56 |
# File 'lib/desk_api/configuration.rb', line 54 def token=(value) @token = value end |
#token_secret=(value) ⇒ Object (writeonly)
Sets the attribute token_secret
54 55 56 |
# File 'lib/desk_api/configuration.rb', line 54 def token_secret=(value) @token_secret = value end |
#username ⇒ Object
Returns the value of attribute username.
55 56 57 |
# File 'lib/desk_api/configuration.rb', line 55 def username @username end |
Class Method Details
.included(_base) ⇒ Object
Registers the middleware when the module is included.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/desk_api/configuration.rb', line 87 def included(_base) register_middleware :request, :desk_encode_dates, :EncodeDates register_middleware :request, :desk_encode_json, :EncodeJson register_middleware :request, :desk_oauth, :OAuth register_middleware :request, :desk_retry, :Retry register_middleware :response, :desk_parse_dates, :ParseDates register_middleware :response, :desk_parse_json, :ParseJson register_middleware :response, :desk_raise_error, :RaiseError register_middleware :response, :desk_follow_redirects, :FollowRedirects end |
.keys ⇒ Array
Returns an array of possible configuration options.
63 64 65 66 67 68 69 70 |
# File 'lib/desk_api/configuration.rb', line 63 def keys @keys ||= [ :consumer_key, :consumer_secret, :token, :token_secret, :username, :password, :subdomain, :endpoint, :connection_options ] end |
.register_middleware(type, sym, cls) ⇒ Object
Allows to register middleware for Faraday v0.8 and v0.9
77 78 79 80 81 82 83 84 |
# File 'lib/desk_api/configuration.rb', line 77 def register_middleware(type, sym, cls) cls = DeskApi.const_get(type.capitalize).const_get(cls) if Faraday.respond_to?(:register_middleware) Faraday.register_middleware type, sym => cls else Faraday.const_get(type.capitalize).register_middleware sym => cls end end |
Instance Method Details
#configure {|DeskApi::Client| ... } ⇒ DeskApi::Client
Allows to configure the client by yielding self.
130 131 132 133 134 135 |
# File 'lib/desk_api/configuration.rb', line 130 def configure yield self validate_credentials! validate_endpoint! self end |
#credentials? ⇒ Boolean
Returns true if either all oauth values or all basic auth values are set.
152 153 154 |
# File 'lib/desk_api/configuration.rb', line 152 def credentials? oauth.values.all? || basic_auth.values.all? end |
#reset! ⇒ DeskApi::Client Also known as: setup
Resets the client to the default settings.
140 141 142 143 144 145 |
# File 'lib/desk_api/configuration.rb', line 140 def reset! DeskApi::Configuration.keys.each do |key| send("#{key}=", DeskApi::Default.[key]) end self end |