Class: Fleakr::Objects::User

Inherits:
Object
  • Object
show all
Includes:
Support::Object
Defined in:
lib/fleakr/objects/user.rb

Overview

User

Accessors

This class maps directly onto the flickr.people.* API methods and provides the following attributes for a user:

[id] The ID for this user (also referred to as the NSID in the API docs) [username] This user's username [name] This user's full name (if entered) [location] This user's location (if entered) [photos_url] The direct URL to this user's photostream [profile_url] The direct URL to this user's profile [photos_count] The number of photos that this user has uploaded [icon_url] This user's buddy icon (or a default one if an icon wasn't uploaded) [pro?] Does this user have a pro account? [admin?] Is this user an admin?

Associations

The User class is pretty central to many of the other data available across the system, so there are a few associations available to a user:

[sets] A list of this user's public sets (newest first). See Fleakr::Objects::Set for more information. [groups] A list of this user's public groups. See Fleakr::Objects::Group. [photos] A list of this user's public photos (newest first). See Fleakr::Objects::Photo. [contacts] A list of this user's contacts - these are simply User objects [tags] The tags associated with this user [collections] The top-level collections that this user has created. See Fleakr::Objects::Collection.

Examples

Access to a specific user is typically done through the Fleakr.user method:

user = Fleakr.user('brownout') user.id user.username user.sets user.contacts

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Support::Object

included

Class Method Details

.find_by_identifier(identifier) ⇒ Object



75
76
77
# File 'lib/fleakr/objects/user.rb', line 75

def self.find_by_identifier(identifier)
  user_id?(identifier) ? find_by_id(identifier) : find_by_username(identifier)
end

.user_id?(username_or_user_id) ⇒ Boolean

Returns:

  • (Boolean)


71
72
73
# File 'lib/fleakr/objects/user.rb', line 71

def self.user_id?(username_or_user_id)
  (username_or_user_id =~ /^\d+@N\d{2}$/) ? true : false
end

Instance Method Details

#admin? ⇒ Boolean

Is this user an admin?

Returns:

  • (Boolean)


85
86
87
# File 'lib/fleakr/objects/user.rb', line 85

def admin?
  (self.admin.to_i == 0) ? false : true
end

#icon_url ⇒ Object

This user's buddy icon



90
91
92
93
94
95
96
# File 'lib/fleakr/objects/user.rb', line 90

def icon_url
  if self.icon_server.to_i > 0
    "http://farm#{self.icon_farm}.static.flickr.com/#{self.icon_server}/buddyicons/#{self.id}.jpg"
  else
    'http://www.flickr.com/images/buddyicon.jpg'
  end
end

#load_info ⇒ Object

:nodoc:



98
99
100
101
# File 'lib/fleakr/objects/user.rb', line 98

def load_info # :nodoc:
  response = Fleakr::Api::MethodRequest.with_response!('people.getInfo', :user_id => self.id)
  self.populate_from(response.body)
end

#pro? ⇒ Boolean

Is this a pro account?

Returns:

  • (Boolean)


80
81
82
# File 'lib/fleakr/objects/user.rb', line 80

def pro?
  (self.pro.to_i == 0) ? false : true
end