Class: FakeFlorence::Announcers::Routemaster
- Inherits:
-
Object
- Object
- FakeFlorence::Announcers::Routemaster
- Defined in:
- lib/fake_florence/announcers/routemaster.rb
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #announce(hash) ⇒ Object
-
#initialize(url, name: nil) ⇒ Routemaster
constructor
A new instance of Routemaster.
Constructor Details
#initialize(url, name: nil) ⇒ Routemaster
Returns a new instance of Routemaster.
8 9 10 11 12 13 14 15 |
# 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 |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/fake_florence/announcers/routemaster.rb', line 6 def name @name end |
Instance Method Details
#announce(hash) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# 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. false rescue Faraday::Error::ClientError => e Config.log.warn "Could not announce to #{@name}: HTTP #{e.response[:status]}" false end |