Sha256: 75587c645d2896dd25d60cc6aaa3a4303d10450b8579752810247940223ed489

Contents?: true

Size: 1.47 KB

Versions: 1

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, :default_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 },
        :default_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

1 entries across 1 versions & 1 rubygems

Version Path
yammer-client-0.1.7 lib/yammer/configurable.rb