Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added buddy icon spec and implemented buddy_icon_url

  • Loading branch information...
commit 346a599e10307c27abe4ed94abfa659434b2b5ff 1 parent ed61362
Ben authored
Showing with 44 additions and 1 deletion.
  1. +18 −1 lib/flickr-wrapper/user.rb
  2. +26 −0 spec/user_spec.rb
View
19 lib/flickr-wrapper/user.rb
@@ -27,7 +27,7 @@ def realname
get_info.at(:realname).inner_text
end
- # The psyical location string as entered in flickr
+ # The location string as entered in flickr
def location
get_info.at(:location).inner_text || "Unknown"
end
@@ -37,6 +37,15 @@ def pro?
(get_info.at(:person)["ispro"] == "1") ? true : false
end
+ # Do they have a buddy icon or not?
+ def buddy_icon?
+ (icon_server > 0) ? true : false
+ end
+
+ def buddy_icon_url
+ buddy_icon? ? "http://farm#{icon_farm}.static.flickr.com/#{icon_server}/buddyicons/#{nsid}.jpg" : "http://www.flickr.com/images/buddyicon.jpg"
+ end
+
#
# ==== Private methods
#
@@ -47,4 +56,12 @@ def get_info
@info = Flickr::Query.new(@nsid).execute('flickr.people.getInfo', :user_id => nsid) unless @info
@info
end
+
+ def icon_server
+ get_info.at(:person)["iconserver"].to_i
+ end
+
+ def icon_farm
+ get_info.at(:person)["iconfarm"].to_i
+ end
end
View
26 spec/user_spec.rb
@@ -26,4 +26,30 @@
@user.pro?.should be_false
end
+ it "should have a buddyicon url" do
+ @user = Flickr::User.find_by_email 'ben.schwarz@gmail.com'
+ @user.buddy_icon_url.should be_kind_of String
+ end
+
+ # http://www.flickr.com/services/api/misc.buddyicons.html
+ it "should make the buddy icon url up in the correct format" do
+ # No buddy icon
+ @no_icon = Flickr::User.find_by_email 'ben.schwarz@gmail.com'
+ @no_icon.buddy_icon_url.should eql "http://www.flickr.com/images/buddyicon.jpg"
+
+ @icon = Flickr::User.find_by_username 'thirdglance'
+ @icon.buddy_icon_url.should_not eql "http://www.flickr.com/images/buddyicon.jpg"
+ end
+
+ it "should not have a buddy icon" do
+ @no_icon = Flickr::User.find_by_email 'ben.schwarz@gmail.com'
+ @no_icon.buddy_icon?.should be_false
+ end
+
+ it "should have a buddy icon" do
+ @icon = Flickr::User.find_by_username 'thirdglance'
+ puts @icon.buddy_icon_url
+ @icon.buddy_icon?.should be_true
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.