Skip to content

Commit

Permalink
Adding support for managing saved searches
Browse files Browse the repository at this point in the history
  • Loading branch information
zmoazeni committed Apr 21, 2010
1 parent c5361ed commit d5f0b58
Show file tree
Hide file tree
Showing 4 changed files with 66 additions and 0 deletions.
16 changes: 16 additions & 0 deletions lib/twitter/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/saved_search.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"name": "great danes",
"position": null,
"created_at": "Wed Apr 21 19:33:43 +0000 2010",
"id": 7095598,
"query": "great danes"
}
16 changes: 16 additions & 0 deletions test/fixtures/saved_searches.json
Original file line number Diff line number Diff line change
@@ -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"
}
]
27 changes: 27 additions & 0 deletions test/twitter/base_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit d5f0b58

Please sign in to comment.