Class: Asana::Client::Configuration Private

Inherits:
Object
  • Object
show all
Defined in:
lib/asana/client/configuration.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Represents a configuration DSL for an Asana::Client.

Examples:

config = Configuration.new
config.authentication :access_token, 'personal_access_token'
config.adapter :typhoeus
config.configure_faraday { |conn| conn.use MyMiddleware }
config.to_h
# => { authentication: #<Authentication::TokenAuthentication>,
       faraday_adapter: :typhoeus,
       faraday_configuration: #<Proc> }

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initializes an empty configuration object.



20
21
22
23
24
# File 'lib/asana/client/configuration.rb', line 20

def initialize
  @configuration = {
    log_asana_change_warnings: true
  }
end

Instance Method Details

#authentication(type, value) ⇒ void

This method returns an undefined value.

Sets an authentication strategy.

Parameters:

  • type (:oauth2, :api_token)

    the kind of authentication strategy to use

  • value (::OAuth2::AccessToken, String, Hash)

    the configuration for the chosen authentication strategy.

Raises:

  • ArgumentError if the arguments are invalid.



35
36
37
38
39
40
41
42
# File 'lib/asana/client/configuration.rb', line 35

def authentication(type, value)
  auth = case type
         when :oauth2 then oauth2(value)
         when :access_token then from_bearer_token(value)
         else error "unsupported authentication type #{type}"
         end
  @configuration[:authentication] = auth
end

#configure_faraday(&config) ⇒ void

This method returns an undefined value.

Sets a custom configuration block for the Faraday connection.

Parameters:

  • config (Proc)

    the configuration block.



58
59
60
# File 'lib/asana/client/configuration.rb', line 58

def configure_faraday(&config)
  @configuration[:faraday_configuration] = config
end

#debug_modevoid

This method returns an undefined value.

Configures the client in debug mode, which will print verbose information on STDERR.



66
67
68
# File 'lib/asana/client/configuration.rb', line 66

def debug_mode
  @configuration[:debug_mode] = true
end

#default_headers(value) ⇒ void

This method returns an undefined value.

Configures the client to always send the given headers



80
81
82
# File 'lib/asana/client/configuration.rb', line 80

def default_headers(value)
  @configuration[:default_headers] = value
end

#faraday_adapter(adapter) ⇒ void

This method returns an undefined value.

Sets a custom network adapter for Faraday.

Parameters:

  • adapter (Symbol, Proc)

    the adapter.



49
50
51
# File 'lib/asana/client/configuration.rb', line 49

def faraday_adapter(adapter)
  @configuration[:faraday_adapter] = adapter
end

#log_asana_change_warnings(value) ⇒ void

This method returns an undefined value.

Configures the client to log Asana-Change warnings on STDERR.



73
74
75
# File 'lib/asana/client/configuration.rb', line 73

def log_asana_change_warnings(value)
  @configuration[:log_asana_change_warnings] = !!value
end

#to_hHash

Returns the configuration Hash.

Returns:

  • (Hash)

    Returns the configuration Hash.



86
87
88
# File 'lib/asana/client/configuration.rb', line 86

def to_h
  @configuration
end