Class: Yt::Configuration

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

Overview

Provides an object to store global configuration settings.

This class is typically not used directly, but by calling Yt.configure, which creates and updates a single instance of Models::Configuration.

An alternative way to set global configuration settings is by storing them in the following environment variables:

  • YT_CLIENT_ID to store the Client ID for web/device apps

  • YT_CLIENT_SECRET to store the Client Secret for web/device apps

  • YT_API_KEY to store the API key for server/browser apps

  • YT_LOG_LEVEL to store the verbosity level of the logs

In case both methods are used together, Yt.configure takes precedence.

Examples:

Set the API client id/secret for a web-client YouTube app:

Yt.configure do |config|
  config.client_id = 'ABCDEFGHIJ1234567890'
  config.client_secret = 'ABCDEFGHIJ1234567890'
end

Set the API client id/secret for a web-client YouTube app:

ENV['YT_CLIENT_ID'] = 'ABCDEFGHIJ1234567890'
ENV['YT_CLIENT_SECRET'] = 'ABCDEFGHIJ1234567890'

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Initialize the global configuration settings, using the values of the specified following environment variables by default.



55
56
57
58
59
60
# File 'lib/yt/configuration.rb', line 55

def initialize
  @client_id = ENV['YT_CLIENT_ID']
  @client_secret = ENV['YT_CLIENT_SECRET']
  @api_key = ENV['YT_API_KEY']
  @log_level = ENV['YT_LOG_LEVEL']
end

Instance Attribute Details

#access_tokenString

Returns the access token to act on behalf of a YouTube account.

Returns:

  • (String)

    the access token to act on behalf of a YouTube account.



48
49
50
# File 'lib/yt/configuration.rb', line 48

def access_token
  @access_token
end

#api_keyString

Returns the API key for server/browser YouTube applications.

Returns:

  • (String)

    the API key for server/browser YouTube applications.

See Also:



42
43
44
# File 'lib/yt/configuration.rb', line 42

def api_key
  @api_key
end

#client_idString

Returns the Client ID for web/device YouTube applications.

Returns:

  • (String)

    the Client ID for web/device YouTube applications.

See Also:



34
35
36
# File 'lib/yt/configuration.rb', line 34

def client_id
  @client_id
end

#client_secretString

Returns the Client Secret for web/device YouTube applications.

Returns:

  • (String)

    the Client Secret for web/device YouTube applications.

See Also:



38
39
40
# File 'lib/yt/configuration.rb', line 38

def client_secret
  @client_secret
end

#log_levelString

Returns the level of output to print for debugging purposes.

Returns:

  • (String)

    the level of output to print for debugging purposes.



45
46
47
# File 'lib/yt/configuration.rb', line 45

def log_level
  @log_level
end

#refresh_tokenString

Returns the token to refresh an expired access token.

Returns:

  • (String)

    the token to refresh an expired access token.



51
52
53
# File 'lib/yt/configuration.rb', line 51

def refresh_token
  @refresh_token
end

Instance Method Details

#debugging?Boolean

Returns whether the logging output is verbose. Useful when debugging (e.g., to print the curl of failing requests).

Returns:

  • (Boolean)

    whether the logging output is verbose. Useful when debugging (e.g., to print the curl of failing requests).



70
71
72
# File 'lib/yt/configuration.rb', line 70

def debugging?
  %w(devel debug).include? log_level.to_s
end

#developing?Boolean

Returns whether the logging output is extra-verbose. Useful when developing (e.g., to print the curl of every request).

Returns:

  • (Boolean)

    whether the logging output is extra-verbose. Useful when developing (e.g., to print the curl of every request).



64
65
66
# File 'lib/yt/configuration.rb', line 64

def developing?
  %w(devel).include? log_level.to_s
end