Sha256: 67b6da59cdcab5335d61f97a42072801a7c077dda32a8665d60010f16ac4ac85

Contents?: true

Size: 1.36 KB

Versions: 1

Compression:

Stored size: 1.36 KB

Contents

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

    def initialize(connection, attributes = {})
      @connection  = connection
      @id          = attributes['id']
      @name        = attributes['name']
      @description = attributes['description']
      @global      = attributes['global']
      @uuid        = attributes['uuid']
      @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
    
    def listen
      
    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

1 entries across 1 versions & 1 rubygems

Version Path
protolink-0.2.8 lib/protolink/channel.rb