Sha256: ededcdb266d6b9f7db01ca75b3ce288d32b547e845af39797ad1277e38da78e9

Contents?: true

Size: 1.42 KB

Versions: 3

Compression:

Stored size: 1.42 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, options)
    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, option)
        connection.post("/api/v1/meeps", :body => {:channel_id => self.id, :message => message, :text_extension => option[:text_extension]})
      end

      def connection
        @connection
      end

  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
protolink-0.2.11 lib/protolink/channel.rb
protolink-0.2.10 lib/protolink/channel.rb
protolink-0.2.9 lib/protolink/channel.rb