Class: ActionPusher
- Inherits:
-
AbstractController::Base
- Object
- AbstractController::Base
- ActionPusher
- Includes:
- AbstractController::AssetPaths, AbstractController::Helpers, AbstractController::Rendering, AbstractController::Translation, ApplicationHelper
- Defined in:
- lib/pushable/action_pusher.rb
Constant Summary collapse
- NET_HTTP_EXCEPTIONS =
[Timeout::Error, Errno::ETIMEDOUT, Errno::EINVAL, Errno::ECONNRESET, Errno::ECONNREFUSED, EOFError, Net::HTTPBadResponse, Net::HTTPHeaderSyntaxError, Net::ProtocolError]
Instance Method Summary collapse
Instance Method Details
#push(event, channel, object) ⇒ 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 |
# File 'lib/pushable/action_pusher.rb', line 17 def push(event, channel, object) url = URI.parse("#{Pushable::Rails::Faye.address}/faye") req = Net::HTTP::Post.new(url.path) req.form_data = { message: { channel: "/sync/#{channel}", data: { object: render_for_push(object), event: event } }.to_json } req.basic_auth url.user, url.password if url.user http = Net::HTTP.new(url.host, url.port) if url.scheme == "https" http.use_ssl = true http.verify_mode = OpenSSL::SSL::VERIFY_NONE end http.start do |https| https.request(req) end rescue *NET_HTTP_EXCEPTIONS => exception ::Rails.logger.error("") ::Rails.logger.error("ActionPusher encountered an exception:") ::Rails.logger.error(exception.class.name) ::Rails.logger.error(exception.) ::Rails.logger.error(exception.backtrace.join("\n")) ::Rails.logger.error("") end |
#render_for_push(object) ⇒ Object
44 45 46 |
# File 'lib/pushable/action_pusher.rb', line 44 def render_for_push(object) render_to_hash(partial: "#{object.class.name.underscore.pluralize}/#{object.class.name.underscore}", object: object) end |