Module: Npush

Defined in:
lib/npush-rails.rb,
lib/npush-rails/version.rb,
lib/generators/npush/toheroku_generator.rb

Defined Under Namespace

Classes: Engine, ToherokuGenerator

Constant Summary collapse

VERSION =
"0.1"

Class Method Summary collapse

Class Method Details

.broadcast(channel, event, obj) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/npush-rails.rb', line 24

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

.push(user, event, obj) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/npush-rails.rb', line 10

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