Sha256: 91fcbb8bbea507c76b233f9844fd4f4b5d424674070ef06f5dc9828eb3d6fbb9

Contents?: true

Size: 1.23 KB

Versions: 5

Compression:

Stored size: 1.23 KB

Contents

module Protolink
  class Channel
    attr_reader :id, :name, :description

    def initialize(connection, attributes = {})
      @connection  = connection
      @id          = attributes['id']
      @name        = attributes['name']
      @description = attributes['description']
      @loaded      = false
    end
    

    # Post a new message to the chat channel
    def speak(message, options = {})
      send_message(message)
    end

    def delete!
      connection.delete("/api/v1/channels/#{self.id}")
    end
    
    def listener
      users = connection.get("/api/v1/channels/#{self.id}/users")
      users && users.map do |user|
        User.new(connection, user)
      end
    end

    protected

      def load
        reload! unless @loaded
      end

      # does not work yet
      def reload!
        attributes = connection.get("/api/v1/channels/#{@id}.json")['channel']

        @id          = attributes['id']
        @name        = attributes['name']
        @description = attributes['description']
        @loaded      = true
      end

      def send_message(message)
        connection.post("/api/v1/meeps", :body => {:channel_id => self.id, :message => message})
      end

      def connection
        @connection
      end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
protolink-0.2.6 lib/protolink/channel.rb
protolink-0.2.5 lib/protolink/channel.rb
protolink-0.2.4 lib/protolink/channel.rb
protolink-0.2.3 lib/protolink/channel.rb
protolink-0.2.2 lib/protolink/channel.rb