Module: Breacan::Configurable

Included in:
Breacan, Client
Defined in:
lib/breacan/configurable.rb

Constant Summary collapse

OPTIONS_KEYS =
i(
  access_token
  team
  api_endpoint
  web_endpoint
  user_agent
  media_type
  connection_options
  proxy
  middleware
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.keysObject



20
21
22
# File 'lib/breacan/configurable.rb', line 20

def keys
  @keys ||= OPTIONS_KEYS
end

Instance Method Details

#api_endpointObject



29
30
31
# File 'lib/breacan/configurable.rb', line 29

def api_endpoint
  File.join(@api_endpoint, '')
end

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

Yields:

  • (_self)

Yield Parameters:



25
26
27
# File 'lib/breacan/configurable.rb', line 25

def configure
  yield self
end

#optionsObject



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

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

#reset!Object Also known as: setup



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/breacan/configurable.rb', line 37

def reset!
  builder = if defined? Faraday::RackBuilder
      Faraday::RackBuilder
    else
      Faraday::Builder
    end

  @access_token       = ENV['BREACAN_ACCESS_TOKEN']
  @team               = ENV['BREACAN_TEAM']
  @api_endpoint       = ENV['BREACAN_API_ENDPOINT'] || 'https://slack.com/api/'
  @web_endpoint       = ENV['BREACAN_WEB_ENDPOINT'] || "https://#{@team}.slack.com/"
  @user_agent         = "Breacan Ruby Gem #{Breacan::VERSION}"
  @media_type         = 'application/json'
  @connection_options = { headers: { accept: media_type, user_agent: user_agent } }
  @proxy              = ENV['BREACAN_PROXY']
  @middleware         = builder.new { |c|
    c.adapter Faraday.default_adapter
    c.response :breacan_custom
  }

  self
end

#web_endpointObject



33
34
35
# File 'lib/breacan/configurable.rb', line 33

def web_endpoint
  File.join(@web_endpoint, '')
end