Permalink
Browse files

Add Room Search

  • Loading branch information...
choxi committed May 8, 2012
1 parent 9b0d90f commit d71a1f370df833f1361634383476bcb63acc231f
Showing with 32 additions and 1 deletion.
  1. +1 −1 lib/tinder.rb
  2. +19 −0 lib/tinder/room.rb
  3. +12 −0 spec/tinder/room_spec.rb
View
@@ -1,5 +1,5 @@
# encoding: UTF-8
-require 'active_support'
+require 'active_support/all'
require 'tinder/connection'
require 'tinder/campfire'
require 'tinder/room'
View
@@ -204,6 +204,25 @@ def transcript(transcript_date)
end
end
+ # Search transcripts for a specific term
+ #
+ # room.search("bobloblaw")
+ # #=> [{:message=>"foo!",
+ # :user_id=>"99999",
+ # :person=>"Brandon",
+ # :id=>"18659245",
+ # :timestamp=>=>Tue May 05 07:15:00 -0700 2009}]
+ #
+ def search(term)
+ encoded_term = URI.encode(term)
+ connection.get("/search/#{encoded_term}.json")["messages"].map do |room|
+ { :id => room['id'],
+ :user_id => room['user_id'],
+ :message => room['body'],
+ :timestamp => Time.parse(room['created_at']) }
+ end
+ end
+
def upload(file, content_type = nil, filename = nil)
require 'mime/types'
content_type ||= MIME::Types.type_for(filename || file)
View
@@ -62,6 +62,18 @@ module EventMachine; def self.run; yield end end
end
end
+ describe "search" do
+ before do
+ stub_connection(@connection) do |stub|
+ stub.get('/search/foo.json') {[200, {}, fixture("rooms/recent.json")]}
+ end
+ end
+
+ it "should GET the search endpoint with the search term" do
+ @room.search("foo")
+ end
+ end
+
describe "unlock" do
before do
stub_connection(@connection) do |stub|

0 comments on commit d71a1f3

Please sign in to comment.