Class: EventsEmitter::Pixel
- Inherits:
-
Object
- Object
- EventsEmitter::Pixel
- Defined in:
- lib/events_emitter/pixel.rb
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.config ⇒ Object
34 35 36 |
# File 'lib/events_emitter/pixel.rb', line 34 def self.config @config ||= { url: "//example.com/pixel.gif", timeout: 1 } end |
Instance Method Details
#record(fragment, _) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/events_emitter/pixel.rb', line 6 def record(fragment, _) pixel_url = URI.parse("http:#{url(fragment)}") http = Net::HTTP.new(pixel_url.host, pixel_url.port) http.read_timeout = timeout request = Net::HTTP::Get.new(pixel_url.request_uri) response = http.request(request) return true rescue Timeout::Error => e notifier = self.class.config[:exception_notifier] if notifier notifier.notify(e, pixel_url) return false else raise e end end |
#timeout ⇒ Object
30 31 32 |
# File 'lib/events_emitter/pixel.rb', line 30 def timeout self.class.config[:timeout] end |
#url(fragment) ⇒ Object
26 27 28 |
# File 'lib/events_emitter/pixel.rb', line 26 def url(fragment) "#{self.class.config[:url]}?#{fragment}" end |