Class: TrackerHookForwarder::Forwarding
- Inherits:
-
Object
- Object
- TrackerHookForwarder::Forwarding
- Includes:
- HTTParty
- Defined in:
- lib/tracker-hook-forwarder/forwarding.rb
Instance Attribute Summary collapse
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
- #forward(body) ⇒ Object
-
#initialize(url) ⇒ Forwarding
constructor
A new instance of Forwarding.
Constructor Details
#initialize(url) ⇒ Forwarding
Returns a new instance of Forwarding.
9 10 11 12 13 14 |
# File 'lib/tracker-hook-forwarder/forwarding.rb', line 9 def initialize(url) @url = url.freeze unless [URI::HTTP, URI::HTTPS].include? URI.parse(url).class raise ArgumentError, "Forwarding url must be either http or https!" end end |
Instance Attribute Details
#url ⇒ Object (readonly)
Returns the value of attribute url.
6 7 8 |
# File 'lib/tracker-hook-forwarder/forwarding.rb', line 6 def url @url end |
Instance Method Details
#forward(body) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tracker-hook-forwarder/forwarding.rb', line 16 def forward(body) response = Forwarding.post(url, :body => body, :headers => {"Content-Type" => 'application/xml'}).response if response.kind_of?(Net::HTTPSuccess) TrackerHookForwarder.logger.info "Forwarded to #{url}:\n#{body}" true else TrackerHookForwarder.logger.warn "Forwarding to #{url} failed with #{response.class}:\n#{body}" false end rescue => err TrackerHookForwarder.logger.error "Forwarding to #{url} caused an error #{err}:\n#{body}" false end |