Sha256: 055c44aeb17893e874ae5d41a28f74ef4750266d35ec19f1102d2f63a6b03f1d

Contents?: true

Size: 1.06 KB

Versions: 1

Compression:

Stored size: 1.06 KB

Contents

module Npush
  require 'net/http'
  require 'uri'
  
  class Engine < ::Rails::Engine
    #adds socket.io.min.js from /vendor to asset pipeline
  end

  class << self
    def push(user, event, obj)
      uri = URI.parse(ENV['npush_server'])
      http = Net::HTTP.new(uri.host, uri.port)
      request = Net::HTTP::Post.new(uri.request_uri)
      request.content_type = 'application/json'
      @body = {}
      @body["secret"] = ENV['npush_secret']
      @body["user"] = user
      @body["event"] = event
      @body["obj"] = obj
      request.body = @body.to_json
      response = http.request(request)
    end
    
    def broadcast(channel, event, obj)
      uri = URI.parse(ENV['npush_server'])
      http = Net::HTTP.new(uri.host, uri.port)
      request = Net::HTTP::Post.new(uri.request_uri)
      request.content_type = 'application/json'
      @body = {}
      @body["secret"] = ENV['npush_secret']
      @body["channel"] = channel
      @body["event"] = event
      @body["obj"] = obj
      request.body = @body.to_json
      response = http.request(request)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
npush-rails-0.1 lib/npush-rails.rb