Skip to content

Commit

Permalink
Support easy subdomains instead of full uris
Browse files Browse the repository at this point in the history
  • Loading branch information
raggi committed May 23, 2011
1 parent 245cb14 commit 7b5f7fa
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.rdoc
Expand Up @@ -25,7 +25,7 @@ default, on other rubies it will try for yajl, then for json.
keychain = OSXKeychain.new # optional part of example
token = keychain['campfire', ENV['USER']] # optional part of example

room = MicroFire.new 'https://raggi.campfirenow.com', token, 'ragville'
room = MicroFire.new 'raggi', token, 'ragville'
room.join
room.speak 'OHAI THERE'
room.watch do |event|
Expand Down
12 changes: 10 additions & 2 deletions lib/micro_fire.rb
Expand Up @@ -30,7 +30,6 @@ class << self
def initialize uri, token, room
@stream = self.class.stream
@json = self.class.json
@uri = URI.parse uri
@token = token
@http = Net::HTTP::Persistent.new
# Don't do anything if not supported by net/http/persistent version or
Expand All @@ -39,7 +38,8 @@ def initialize uri, token, room
@http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
end
@pass = 'x'
@room = find_room(room)
@uri = find_uri uri
@room = find_room room
end

def join &block
Expand All @@ -65,6 +65,14 @@ def find_room room
res ? res["id"].to_i : raise("Could not find room by #{room}")
end

def find_uri uri
if uri =~ %r{https?://.*\..*}
URI.parse uri
else
URI.parse "https://#{uri}.campfirenow.com"
end
end

def action action
"/room/#{room}/#{action}.json"
end
Expand Down

0 comments on commit 7b5f7fa

Please sign in to comment.