Class: Pharos::Channel

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/pharos/channel.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, base_uri, client = Pharos) ⇒ Channel

Returns a new instance of Channel.



11
12
13
14
15
16
# File 'lib/pharos/channel.rb', line 11

def initialize(name, base_uri, client = Pharos)
  @name = name
  @path = base_uri + "/push/#{name}/"
  @client = client
  @auth = { username: 'pharos', password: client.secret }
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/pharos/channel.rb', line 9

def name
  @name
end

Instance Method Details

#push(receivers, data) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pharos/channel.rb', line 18

def push(receivers, data)
  body = case data
  when String
    data # In this case we send a javascript instruction
  else
    begin
      MultiJson.encode(data)
    rescue MultiJson::DecodeError => e
      raise e
    end
  end

  options = { body: { to: receivers, message: body }, basic_auth: @auth}
  self.class.post(@path, options)
end