Module: Yammer::Configurable

Included in:
Yammer, Client
Defined in:
lib/yammer/configurable.rb

Constant Summary collapse

ENDPOINT =
'https://www.yammer.com'
HTTP_ADAPTER =
Yammer::HttpAdapter

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#access_tokenObject

Returns the value of attribute access_token


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def access_token
  @access_token
end

#client_idObject

Returns the value of attribute client_id


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def client_secret
  @client_secret
end

#connection_optionsObject

Returns the value of attribute connection_options


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def connection_options
  @connection_options
end

#default_headersObject

Returns the value of attribute default_headers


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def default_headers
  @default_headers
end

#http_adapterObject

Returns the value of attribute http_adapter


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def http_adapter
  @http_adapter
end

#site_urlObject

Returns the value of attribute site_url


23
24
25
# File 'lib/yammer/configurable.rb', line 23

def site_url
  @site_url
end

Class Method Details

.default_optionsHash

Return a hash with the default options

Returns:

  • (Hash)

28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/yammer/configurable.rb', line 28

def self.default_options
  {
    :site_url           => ENDPOINT,
    :client_id          => ENV['YAMMER_CLIENT_ID'],
    :client_secret      => ENV['YAMMER_CLIENT_SECRET'],
    :access_token       => ENV['YAMMER_ACCESS_TOKEN'],
    :http_adapter       => HTTP_ADAPTER,
    :connection_options => { :max_redirects => 5, :verify_ssl => true },
    :default_headers    => {
      'Accept'     => 'application/json',
      'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
    }
  }
end

.keysArray<String>

Returns:

  • (Array<String>)

44
45
46
# File 'lib/yammer/configurable.rb', line 44

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:


61
62
63
64
# File 'lib/yammer/configurable.rb', line 61

def configure
  yield self if block_given?
  self
end

#disable_loggingObject


70
71
72
# File 'lib/yammer/configurable.rb', line 70

def disable_logging
  self.http_adapter.log = nil
end

#enable_logging(output = 'stdout') ⇒ Object


66
67
68
# File 'lib/yammer/configurable.rb', line 66

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

#optionsHash

Returns:

  • (Hash)

49
50
51
# File 'lib/yammer/configurable.rb', line 49

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

#reset!Object


53
54
55
56
57
58
# File 'lib/yammer/configurable.rb', line 53

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

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

Yields:

  • (_self)

Yield Parameters:


74
75
76
77
78
79
# File 'lib/yammer/configurable.rb', line 74

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