Module: DeskApi::Configuration

Extended by:
Forwardable
Included in:
DeskApi, Client
Defined in:
lib/desk_api/configuration.rb

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

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#connection_optionsObject

Returns the value of attribute connection_options.



55
56
57
# File 'lib/desk_api/configuration.rb', line 55

def connection_options
  @connection_options
end

#consumer_keyObject

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

Parameters:

  • value

    the value to set the attribute consumer_secret to.



54
55
56
# File 'lib/desk_api/configuration.rb', line 54

def consumer_secret=(value)
  @consumer_secret = value
end

#endpointString

Builds the endpoint using the subdomain if the endpoint isn't set

Returns:

  • (String)


102
103
104
# File 'lib/desk_api/configuration.rb', line 102

def endpoint
  @endpoint
end

#middlewareProc

Returns the middleware proc to be used by Faraday

Returns:

  • (Proc)


109
110
111
# File 'lib/desk_api/configuration.rb', line 109

def middleware
  @middleware
end

#password=(value) ⇒ Object (writeonly)

Sets the attribute password

Parameters:

  • value

    the value to set the attribute password to.



54
55
56
# File 'lib/desk_api/configuration.rb', line 54

def password=(value)
  @password = value
end

#subdomainObject

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

Parameters:

  • value

    the value to set the attribute token to.



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

Parameters:

  • value

    the value to set the attribute token_secret to.



54
55
56
# File 'lib/desk_api/configuration.rb', line 54

def token_secret=(value)
  @token_secret = value
end

#usernameObject

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

.keysArray

Returns an array of possible configuration options.

Returns:

  • (Array)


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

Parameters:

  • type (Symbol)

    either :request or :response

  • sym (Symbol)

    the symbol to register the middleware as

  • cls (Symbol)

    the class name of the middleware



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.

Yields:

Returns:



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.

Returns:

  • (Boolean)


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.

Returns:



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.options[key])
  end
  self
end