Sha256: 2adbdebfeba46f595573143a77102510a3a1158c6330629c07b30f9ec7af0112

Contents?: true

Size: 1.07 KB

Versions: 2

Compression:

Stored size: 1.07 KB

Contents

module Trumpet
  class Channel < Trumpet::Resource
    
    def self.create(options)
      Channel.new(Trumpet::Request.post('/channels', options))
    end
    
    def self.find(name, options={})
      Channel.new(Trumpet::Request.get("/channels/#{name}", options))
    end
    
    def self.all(options={})
      Trumpet::Request.get('/channels', options).map { |attributes| Channel.new(attributes) }
    end
    
    def self.all_by_user(name, options={})
      channels = Trumpet::Request.get("/users/#{name}/channels", options)
      channels.map { |attributes| Channel.new(attributes) }
    end
        
    def broadcast(message, options={})
      options[:credentials] ||= @credentials
      !!Trumpet::Request.post("/channels/#{@name}/messages", :parameters => message.to_h, :parse_response => false, :credentials => options[:credentials])
    end
    
    def messages(options={})
      options[:credentials] ||= @credentials
      messages = Trumpet::Request.get("/channels/#{@name}/messages", options)
      messages.map { |attributes| Message.new(attributes) }
    end
    
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
trumpet-trumpet-0.1.0 lib/trumpet/channel.rb
trumpet-trumpet-0.1.1 lib/trumpet/channel.rb