Module: Plangrade::Configurable

Included in:
Plangrade, Client
Defined in:
lib/plangrade/configurable.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def access_token
  @access_token
end

#client_idObject

Returns the value of attribute client_id.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def client_secret
  @client_secret
end

#connection_optionsObject

Returns the value of attribute connection_options.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def connection_options
  @connection_options
end

#default_headersObject

Returns the value of attribute default_headers.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def default_headers
  @default_headers
end

#http_adapterObject

Returns the value of attribute http_adapter.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def http_adapter
  @http_adapter
end

#site_urlObject

Returns the value of attribute site_url.



9
10
11
# File 'lib/plangrade/configurable.rb', line 9

def site_url
  @site_url
end

Class Method Details

.default_optionsHash

Return a hash with the default options

Returns:

  • (Hash)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/plangrade/configurable.rb', line 14

def self.default_options
  {
    :site_url           => ENDPOINT,
    :client_id          => ENV['PLANGRADE_CLIENT_ID'],
    :client_secret      => ENV['PLANGRADE_CLIENT_SECRET'],
    :access_token       => ENV['PLANGRADE_ACCESS_TOKEN'],
    :http_adapter       => HTTP_ADAPTER,
    :connection_options => { :max_redirects => 5, :verify_ssl => true },
    :default_headers    => {
      'Accept'     => 'application/json',
      'User-Agent' => "Plangrade Ruby Gem #{Plangrade::Ruby::VERSION}"
    }
  }
end

.keysArray<String>

Returns:

  • (Array<String>)


30
31
32
# File 'lib/plangrade/configurable.rb', line 30

def self.keys
  self.default_options.keys
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Convenience method to allow configuration options to be set in a block

Yields:

  • (_self)

Yield Parameters:



47
48
49
50
# File 'lib/plangrade/configurable.rb', line 47

def configure
  yield self if block_given?
  self
end

#disable_loggingObject



56
57
58
# File 'lib/plangrade/configurable.rb', line 56

def disable_logging
  self.http_adapter.log = nil
end

#enable_logging(output = 'stdout') ⇒ Object



52
53
54
# File 'lib/plangrade/configurable.rb', line 52

def enable_logging(output='stdout')
  self.http_adapter.log = output
end

#optionsHash

Returns:

  • (Hash)


35
36
37
# File 'lib/plangrade/configurable.rb', line 35

def options
  Hash[Plangrade::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}]
end

#reset!Object



39
40
41
42
43
44
# File 'lib/plangrade/configurable.rb', line 39

def reset!
  Plangrade::Configurable.keys.each do |key|
    instance_variable_set(:"@#{key}", Plangrade::Configurable.default_options[key.to_sym])
  end
  self
end

#with_logging(output) {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



60
61
62
63
64
65
# File 'lib/plangrade/configurable.rb', line 60

def with_logging(output)
  cached_output = self.http_adapter.log
  enable_logging(output)
  yield self if block_given?
  self.http_adapter.log = cached_output
end