class FakeFlorence::Announcers::Routemaster

Attributes

name[R]

Public Class Methods

new(url, name: nil) click to toggle source
# File lib/fake_florence/announcers/routemaster.rb, line 8
def initialize(url, name: nil)
  @name = name
  @http = Faraday.new(url: url) do |f|
    f.use Faraday::Response::RaiseError
    f.request :json
    f.adapter Faraday.default_adapter
  end
end

Public Instance Methods

announce(hash) click to toggle source
# File lib/fake_florence/announcers/routemaster.rb, line 17
def announce(hash)
  t = Time.now.to_i

  events = []
  hash.each_pair do |type, features|
    features.each do |feature|
      events.push(
        topic: 'feature',
        type: type,
        url: Config.url_for(feature),
        t: t
      )
    end
  end

  res = @http.post do |req|
    req.body = events.to_json
  end

  count = events.size
  counter = "#{count} feature#{count == 1 ? '' : 's'}"
  Config.log.info "#{counter} announced to '#{@name}'."
  true

rescue Faraday::ConnectionFailed => e
  Config.log.error e.message
  false

rescue Faraday::Error::ClientError => e
  Config.log.warn "Could not announce to #{@name}: HTTP #{e.response[:status]}"
  false
end