# File lib/god/contacts/campfire.rb, line 26 def base_url scheme = @options[:ssl] ? 'https' : 'http' subdomain = @options[:subdomain] "#{scheme}://#{subdomain}.campfirenow.com" end
# File lib/god/contacts/campfire.rb, line 32 def find_room_id_by_name(room) url = URI.parse("#{base_url}/rooms.json") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if @options[:ssl] req = Net::HTTP::Get.new(url.path) req.basic_auth(@options[:token], 'X') res = http.request(req) case res when Net::HTTPSuccess rooms = JSON.parse(res.body) room = rooms['rooms'].select { |x| x['name'] == room } rooms.empty? ? nil : room.first['id'] else raise res.error! end end
# File lib/god/contacts/campfire.rb, line 52 def speak(room, message) room_id = find_room_id_by_name(room) raise "No such room: #{room}." unless room_id url = URI.parse("#{base_url}/room/#{room_id}/speak.json") http = Net::HTTP.new(url.host, url.port) http.use_ssl = true if @options[:ssl] req = Net::HTTP::Post.new(url.path) req.basic_auth(@options[:token], 'X') req.set_content_type('application/json') req.body = { 'message' => { 'body' => message } }.to_json res = http.request(req) case res when Net::HTTPSuccess true else raise res.error! end end
Generated with the Darkfish Rdoc Generator 2.