diff --git a/lib/twitter/base.rb b/lib/twitter/base.rb index 8f92f1fb3..9da4ee548 100644 --- a/lib/twitter/base.rb +++ b/lib/twitter/base.rb @@ -308,6 +308,22 @@ def blocking(options={}) perform_get("/#{API_VERSION}/blocks/blocking.json", options) end + def saved_searches + perform_get("/#{API_VERSION}/saved_searches.json") + end + + def saved_search(id) + perform_get("/#{API_VERSION}/saved_searches/show/#{id}.json") + end + + def saved_search_create(query) + perform_post("/#{API_VERSION}/saved_searches/create.json", :body => {:query => query}) + end + + def saved_search_destroy(id) + perform_delete("/#{API_VERSION}/saved_searches/destroy/#{id}.json") + end + protected def self.mime_type(file) diff --git a/test/fixtures/saved_search.json b/test/fixtures/saved_search.json new file mode 100644 index 000000000..9dfd02c49 --- /dev/null +++ b/test/fixtures/saved_search.json @@ -0,0 +1,7 @@ +{ + "name": "great danes", + "position": null, + "created_at": "Wed Apr 21 19:33:43 +0000 2010", + "id": 7095598, + "query": "great danes" +} diff --git a/test/fixtures/saved_searches.json b/test/fixtures/saved_searches.json new file mode 100644 index 000000000..10e96b0af --- /dev/null +++ b/test/fixtures/saved_searches.json @@ -0,0 +1,16 @@ +[ + { + "name": "great danes", + "position": null, + "created_at": "Wed Apr 21 19:33:43 +0000 2010", + "id": 7095598, + "query": "great danes" + }, + { + "name": "rubyconf OR railsconf", + "position": null, + "created_at": "Wed Apr 21 19:34:04 +0000 2010", + "id": 7095610, + "query": "rubyconf OR railsconf" + } +] \ No newline at end of file diff --git a/test/twitter/base_test.rb b/test/twitter/base_test.rb index eefd23ed2..335031e96 100644 --- a/test/twitter/base_test.rb +++ b/test/twitter/base_test.rb @@ -215,6 +215,33 @@ class BaseTest < Test::Unit::TestCase user.name.should == 'John Nunemaker' # update_profile_background responds with the user end end + + context "when using saved searches" do + should "be able to retrieve my saved searches" do + stub_get('/1/saved_searches.json', 'saved_searches.json') + searches = @twitter.saved_searches + searches[0].query.should == "great danes" + searches[1].query.should == "rubyconf OR railsconf" + end + + should "be able to retrieve a saved search by id" do + stub_get('/1/saved_searches/show/7095598.json', 'saved_search.json') + search = @twitter.saved_search(7095598) + search.query.should == "great danes" + end + + should "be able to create a saved search" do + stub_post('/1/saved_searches/create.json', 'saved_search.json') + search = @twitter.saved_search_create('great danes') + search.query.should == "great danes" + end + + should "be able to delete a saved search" do + stub_delete('/1/saved_searches/destroy/7095598.json', 'saved_search.json') + search = @twitter.saved_search_destroy(7095598) + search.query.should == "great danes" + end + end context "when using lists" do