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
  serializer
  auto_paginate
)

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.keysObject



22
23
24
# File 'lib/breacan/configurable.rb', line 22

def keys
  @keys ||= OPTIONS_KEYS
end

Instance Method Details

#api_endpointObject



31
32
33
# File 'lib/breacan/configurable.rb', line 31

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

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

Yields:

  • (_self)

Yield Parameters:



27
28
29
# File 'lib/breacan/configurable.rb', line 27

def configure
  yield self
end

#default_builderObject



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/breacan/configurable.rb', line 61

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

  builder.new do |c|
    c.response :breacan_custom
    c.adapter Faraday.default_adapter
  end
end

#default_serializerObject



57
58
59
# File 'lib/breacan/configurable.rb', line 57

def default_serializer
  Sawyer::Serializer.any_json
end

#optionsObject



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

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

#reset!Object Also known as: setup



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

def reset!

  @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         = default_builder
  @serializer         = default_serializer
  @auto_paginate      = !!ENV['BREACAN_AUTO_PAGINATE']

  self
end

#web_endpointObject



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

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