Class: Trumpet::Channel

Inherits:
Resource show all
Defined in:
lib/trumpet/channel.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.all(options = {}) ⇒ Object



12
13
14
# File 'lib/trumpet/channel.rb', line 12

def self.all(options={})
  Trumpet::Request.get('/channels', options).map { |attributes| Channel.new(attributes) }
end

.all_by_user(name, options = {}) ⇒ Object



16
17
18
19
# File 'lib/trumpet/channel.rb', line 16

def self.all_by_user(name, options={})
  channels = Trumpet::Request.get("/users/#{name}/channels", options)
  channels.map { |attributes| Channel.new(attributes) }
end

.create(options) ⇒ Object



4
5
6
# File 'lib/trumpet/channel.rb', line 4

def self.create(options)
  Channel.new(Trumpet::Request.post('/channels', options))
end

.find(name, options = {}) ⇒ Object



8
9
10
# File 'lib/trumpet/channel.rb', line 8

def self.find(name, options={})
  Channel.new(Trumpet::Request.get("/channels/#{name}", options))
end

Instance Method Details

#broadcast(message, options = {}) ⇒ Object



21
22
23
24
# File 'lib/trumpet/channel.rb', line 21

def broadcast(message, options={})
  options[:credentials] ||= @credentials
  !!Trumpet::Request.post("/channels/#{@name}/messages", :parameters => message.to_h, :parse_response => false, :credentials => options[:credentials])
end

#messages(options = {}) ⇒ Object



26
27
28
29
30
# File 'lib/trumpet/channel.rb', line 26

def messages(options={})
  options[:credentials] ||= @credentials
  messages = Trumpet::Request.get("/channels/#{@name}/messages", options)
  messages.map { |attributes| Message.new(attributes) }
end