Sha256: 3b9db64b1384aa107da7823841ab6e32621b07514206838bd26e2390cecb2b70

Contents?: true

Size: 1.47 KB

Versions: 4

Compression:

Stored size: 1.47 KB

Contents

require 'yammer/http_adapter'

module Yammer
  module Configurable

    ENDPOINT = 'https://www.yammer.com' unless defined? ENDPOINT
    HTTP_ADAPTER = Yammer::HttpAdapter unless defined? HTTP_CONNECTION

    attr_accessor :client_id, :client_secret, :access_token, :site_url,
    :connection_options, :headers, :http_adapter

    # Return a hash with the default options
    # @return [Hash]
    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 },
        :headers            => {
          'Accept'     => 'application/json',
          'User-Agent' => "Yammer Ruby Gem #{Yammer::Version}"
        }
      }
    end

    # @return [Array<String>]
    def self.keys
      self.default_options.keys
    end

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

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

    # Convenience method to allow configuration options to be set in a block
    def configure
      yield self if block_given?
      self
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
yammer-client-0.1.6 lib/yammer/configurable.rb
yammer-client-0.1.5 lib/yammer/configurable.rb
yammer-client-0.1.4 lib/yammer/configurable.rb
yammer-client-0.1.3 lib/yammer/configurable.rb