Class: Flail::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/flail/configuration.rb

Constant Summary collapse

HTTP_ERRORS =

for the default handler

[Timeout::Error,
Errno::EINVAL,
Errno::ECONNRESET,
EOFError,
Net::HTTPBadResponse,
Net::HTTPHeaderSyntaxError,
Net::ProtocolError,
Errno::ECONNREFUSED].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#endpointObject (readonly)

endpoint for default handler (used with flail-web)



17
18
19
# File 'lib/flail/configuration.rb', line 17

def endpoint
  @endpoint
end

#envObject (readonly)

environment of application



20
21
22
# File 'lib/flail/configuration.rb', line 20

def env
  @env
end

#handlerObject (readonly)

custom handler for payloads



14
15
16
# File 'lib/flail/configuration.rb', line 14

def handler
  @handler
end

#hostnameObject (readonly)

hostname sending the error



23
24
25
# File 'lib/flail/configuration.rb', line 23

def hostname
  @hostname
end

#secure_endpointObject (readonly)

is the endpoint ssl?



26
27
28
# File 'lib/flail/configuration.rb', line 26

def secure_endpoint
  @secure_endpoint
end

#tagObject (readonly)

api key to use with payloads



29
30
31
# File 'lib/flail/configuration.rb', line 29

def tag
  @tag
end

Instance Method Details

#defaults!Object



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/flail/configuration.rb', line 56

def defaults!
  # configure some defaults
  @secure_endpoint = false

  handle do |payload|

    url = URI.parse(Flail.configuration.endpoint)

    http = Net::HTTP.new(url.host, url.port)

    http.read_timeout = 5
    http.open_timeout = 2

    if Flail.configuration.secure_endpoint
      http.use_ssl      = true
      http.verify_mode  = OpenSSL::SSL::VERIFY_PEER
    else
      http.use_ssl      = false
    end

    begin
      http.post(url.path, payload, {'Content-type' => 'application/json', 'Accept' => 'application/json'})
    rescue *HTTP_ERRORS => e
      nil
    end
  end

  self
end

#environment(value) ⇒ Object



44
45
46
# File 'lib/flail/configuration.rb', line 44

def environment(value)
  @env = value
end

#handle(&block) ⇒ Object



32
33
34
# File 'lib/flail/configuration.rb', line 32

def handle(&block)
  @handler = block
end

#host(value) ⇒ Object



48
49
50
# File 'lib/flail/configuration.rb', line 48

def host(value)
  @hostname = value
end

#secureObject



40
41
42
# File 'lib/flail/configuration.rb', line 40

def secure
  @secure_endpoint = true
end

#tagged(value) ⇒ Object



52
53
54
# File 'lib/flail/configuration.rb', line 52

def tagged(value)
  @tag = value
end

#url(endpoint) ⇒ Object



36
37
38
# File 'lib/flail/configuration.rb', line 36

def url(endpoint)
  @endpoint = endpoint
end