Class: GuardrailNotifier::Sender
- Inherits:
-
Object
- Object
- GuardrailNotifier::Sender
- Defined in:
- lib/guardrail_notifier/sender.rb
Instance Attribute Summary collapse
-
#configuration ⇒ Object
readonly
Returns the value of attribute configuration.
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(configuration) ⇒ Sender
constructor
A new instance of Sender.
- #port ⇒ Object
- #protocol ⇒ Object
- #send_to_guardrail(data) ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(configuration) ⇒ Sender
Returns a new instance of Sender.
5 6 7 |
# File 'lib/guardrail_notifier/sender.rb', line 5 def initialize(configuration) @configuration = configuration end |
Instance Attribute Details
#configuration ⇒ Object (readonly)
Returns the value of attribute configuration.
3 4 5 |
# File 'lib/guardrail_notifier/sender.rb', line 3 def configuration @configuration end |
Instance Method Details
#host ⇒ Object
17 18 19 |
# File 'lib/guardrail_notifier/sender.rb', line 17 def host 'api.guardrailapp.com' end |
#port ⇒ Object
13 14 15 |
# File 'lib/guardrail_notifier/sender.rb', line 13 def port self.configuration.secure? ? 443 : 80 end |
#protocol ⇒ Object
9 10 11 |
# File 'lib/guardrail_notifier/sender.rb', line 9 def protocol self.configuration.secure? ? 'https' : 'http' end |
#send_to_guardrail(data) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/guardrail_notifier/sender.rb', line 25 def send_to_guardrail(data) uri = self.uri http = Net::HTTP.new(uri.host, uri.port) http.open_timeout = self.configuration.timeout_in_seconds http.use_ssl = self.configuration.secure? http.verify_mode = OpenSSL::SSL::VERIFY_NONE request = Net::HTTP::Post.new(uri.request_uri) request.set_form_data(data) begin response = http.request(request) rescue Exception => ex warn "Could not submit guardrailapp notification: #{ex.class} - #{ex.}" end end |
#uri ⇒ Object
21 22 23 |
# File 'lib/guardrail_notifier/sender.rb', line 21 def uri URI.parse("#{protocol}://#{host}:#{port}").merge('/') end |