Skip to content

Commit

Permalink
Adding the Social Graph API methods w/ tests.
Browse files Browse the repository at this point in the history
Signed-off-by: John Nunemaker <nunemaker@gmail.com>
  • Loading branch information
queso authored and jnunemaker committed Feb 11, 2009
1 parent 82bad40 commit b70718c
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
14 changes: 14 additions & 0 deletions lib/twitter/base.rb
Expand Up @@ -35,6 +35,13 @@ def friends_for(id, options={})
friends(options.merge({:id => id}))
end

# Returns an array of user ids who are friends for the account or the option id/username passed in
def friend_ids(id_or_screenname = nil)
path = id_or_screenname ? "friends/ids/#{id_or_screenname}.xml" : "friends/ids.xml"
doc = request(path, :auth => true)
(doc/:id).inject([]) {|ids, id| ids << id.innerHTML; ids}
end

# Returns an array of users who are following you
def followers(options={})
users(call(:followers, {:args => parse_options(options)}))
Expand All @@ -44,6 +51,13 @@ def followers_for(id, options={})
followers(options.merge({:id => id}))
end

# Returns an array of user ids who are followers for the account or the option id/username passed in
def follower_ids(id_or_screenname = nil)
path = id_or_screenname ? "followers/ids/#{id_or_screenname}.xml" : "followers/ids.xml"
doc = request(path, :auth => true)
(doc/:id).inject([]) {|ids, id| ids << id.innerHTML; ids}
end

# Returns a single status for a given id
def status(id)
statuses(call("show/#{id}")).first
Expand Down
12 changes: 12 additions & 0 deletions spec/base_spec.rb
Expand Up @@ -54,6 +54,12 @@
@base.friends(:lite => true).size.should == 15
end

it "should be able to get friend ids" do
data = open(File.dirname(__FILE__) + '/fixtures/friend_ids.xml').read
@base.should_receive(:request).and_return(Hpricot::XML(data))
@base.friend_ids.size.should == 8
end

it "should be able to get friends for another user" do
data = open(File.dirname(__FILE__) + '/fixtures/friends_for.xml').read
@base.should_receive(:request).and_return(Hpricot::XML(data))
Expand All @@ -70,6 +76,12 @@
timeline.first.name.should == 'Blaine Cook'
end

it "should be able to get follower ids" do
data = open(File.dirname(__FILE__) + '/fixtures/follower_ids.xml').read
@base.should_receive(:request).and_return(Hpricot::XML(data))
@base.follower_ids.size.should == 8
end

it "should be able to create a friendship" do
data = open(File.dirname(__FILE__) + '/fixtures/friendship_created.xml').read
@base.should_receive(:request).and_return(Hpricot::XML(data))
Expand Down
11 changes: 11 additions & 0 deletions spec/fixtures/follower_ids.xml
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<ids>
<id>1192</id>
<id>750823</id>
<id>813198</id>
<id>10718</id>
<id>13046</id>
<id>79543</id>
<id>813775</id>
<id>681473</id>
</ids>
12 changes: 12 additions & 0 deletions spec/fixtures/friend_ids.xml
@@ -0,0 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<ids>
<id>1192</id>
<id>780561</id>
<id>10718</id>
<id>750823</id>
<id>643443</id>
<id>813198</id>
<id>13046</id>
<id>147093</id>
</ids>

0 comments on commit b70718c

Please sign in to comment.