Class: Embedly::Configuration

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

Overview

Configure the api

Available settings

  • debug

    Prints debugging information to logger. Default false. Errors still will be logged

  • logger

    Configure the logger; set this if you want to use a custom logger.

  • request_with

    Sets the desired library to perform requests. Default is Typhoeus

Usage

Embedly.configure do |config|
  # prints debug messages
  config.debug = true

  # customize the logger
  config.logger = MyAwesomeLogger.new(STDERR)

  # performs requests with net/http
  config.request_with :net_http
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

:nodoc:



27
28
29
# File 'lib/embedly/configuration.rb', line 27

def initialize # :nodoc:
  self.reset
end

Instance Attribute Details

#keyObject

:nodoc:



25
26
27
# File 'lib/embedly/configuration.rb', line 25

def key
  @key
end

#requesterObject

:nodoc:



25
26
27
# File 'lib/embedly/configuration.rb', line 25

def requester
  @requester
end

Instance Method Details

#add_requester(name, &block) ⇒ Object

Configures a new requester

To add a new requester class, you can do the following:

Embedly.configuration.add_requester :custom do |api|
  MyRequester.new(api)
end

The requester class should respond to get method, which performs the request for more details, see embedly/request/base.rb



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

def add_requester(name, &block)
  requesters[name] = block
end

#current_requesterObject

Returns the current configured request block



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

def current_requester
  requesters[requester]
end

#debug=(true_or_false) ⇒ Object

:nodoc:



35
36
37
# File 'lib/embedly/configuration.rb', line 35

def debug=(true_or_false) # :nodoc:
  set_logger_level(true_or_false)
end

#debug?Boolean

:nodoc:

Returns:

  • (Boolean)


31
32
33
# File 'lib/embedly/configuration.rb', line 31

def debug? # :nodoc:
  self.logger.debug?
end

#loggerObject

:nodoc:



39
40
41
# File 'lib/embedly/configuration.rb', line 39

def logger # :nodoc:
  @logger ||= default_logger
end

#logger=(log) ⇒ Object

:nodoc:



43
44
45
46
# File 'lib/embedly/configuration.rb', line 43

def logger=(log) # :nodoc:
  @logger = log
  set_logger_level(self.debug?)
end

#request_with(adapter_name) ⇒ Object

Sets api to use the desired requester class

When configuring the API, you can do the following:

Embedly.configure do |config|
  config.request_with :net_http
end

This way, the API will use the net_http class to perform requests



75
76
77
# File 'lib/embedly/configuration.rb', line 75

def request_with(adapter_name)
  self.requester = adapter_name
end

#requestersObject

:nodoc:



62
63
64
# File 'lib/embedly/configuration.rb', line 62

def requesters # :nodoc:
  @requesters ||= {}
end

#resetObject

reset configuration



85
86
87
88
89
# File 'lib/embedly/configuration.rb', line 85

def reset
  self.logger   = default_logger
  self.debug    = false
  self.request_with :net_http
end