Sha256: 14d38a6d956e13a8448ab8381f669f33068b6fcd4a4fc0d8cc16c7c7574a9883

Contents?: true

Size: 919 Bytes

Versions: 2

Compression:

Stored size: 919 Bytes

Contents

module Kindling
  
  class Campfire
    
    attr_accessor :api_token, :subdomain, :ssl

    def initialize(api_token, subdomain, ssl=false)
      @api_token = api_token
      @subdomain = subdomain            
      @ssl = ssl
    end

    def rooms
      Kindling::Request.rooms(self)
    end
    
    def speak(room, message)
      if is_campfire_id?(room)
        Kindling::Request.speak(message, self, room)
      else
        Kindling::Request.speak(message, self, map_room_name(room))
      end
    end
    
    def credentials
      {:username => @api_token, :password => 'x'}
    end
  
    private  
  
    def is_campfire_id?(s)
      s.to_s.match(/\A[+-]?\d+?(\.\d+)?\Z/) == nil ? false : true
    end  
  
    def map_room_name(name)
      rms = rooms.select{|r| r["name"] == name}
      unless rms.empty?
        rms[0]["id"]
      else
        raise InvalidRoomName.new(name)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
kindling-0.0.5 lib/kindling/campfire.rb
kindling-0.0.4 lib/kindling/campfire.rb