class Flickr::User

Todo: logged_in? if logged in: flickr.blogs.getList flickr.favorites.add flickr.favorites.remove flickr.groups.browse flickr.photos.getCounts flickr.photos.getNotInSet flickr.photos.getUntagged flickr.photosets.create flickr.photosets.orderSets flickr.test.login uploading

Attributes

client[R]
count[R]
firstdate[R]
firstdatetaken[R]
id[R]
location[R]
name[R]
photos_url[R]
url[R]

Public Class Methods

new(id_or_params_hash=nil, username=nil, email=nil, password=nil, api_key={}) click to toggle source

A Flickr::User can be instantiated in two ways. The old (deprecated) method is with an ordered series of values. The new method is with a params Hash, which is easier when a variable number of params are supplied, which is the case here, and also avoids having to constantly supply nil values for the email and password, which are now irrelevant as authentication is no longer done this way. An associated flickr client will also be generated if an api key is passed among the arguments or in the params hash. Alternatively, and most likely, an existing client object may be passed in the params hash (e.g. ‘client’ => some_existing_flickr_client_object), and this is what happends when users are initlialized as the result of a method called on the flickr client (e.g. flickr.users)

# File lib/flickr.rb, line 310
def initialize(id_or_params_hash=nil, username=nil, email=nil, password=nil, api_key={})
  if id_or_params_hash.is_a?(Hash)
    id_or_params_hash.each { |k,v| self.instance_variable_set("@#{k}", v) } # convert extra_params into instance variables
  else
    @id = id_or_params_hash
    @username = username
    @email = email
    @password = password
    @api_key = api_key
  end
  @client ||= Flickr.new(:api_key => @api_key, :shared_secret => @shared_secret, :auth_token => @auth_token) if @api_key
end

Public Instance Methods

contacts() click to toggle source

Implements flickr.contacts.getPublicList and flickr.contacts.getList

# File lib/flickr.rb, line 382
def contacts
  @client.contacts_getPublicList('user_id'=>@id)['contacts']['contact'].collect { |contact| User.new(contact['nsid'], contact['username'], nil, nil, @api_key) }
  #or
end
contactsPhotos() click to toggle source

Implements flickr.photos.getContactsPublicPhotos and flickr.photos.getContactsPhotos

# File lib/flickr.rb, line 408
def contactsPhotos
  @client.photos_request('photos.getContactsPublicPhotos', 'user_id' => @id)
end
favorites() click to toggle source

Implements flickr.favorites.getPublicList

# File lib/flickr.rb, line 388
def favorites
  @client.photos_request('favorites.getPublicList', 'user_id' => @id)
end
groups() click to toggle source

Implements flickr.people.getPublicGroups

# File lib/flickr.rb, line 359
def groups
  collection = @client.people_getPublicGroups('user_id'=>@id)['groups']['group']
  collection = [collection] if collection.is_a? Hash
  collection.collect { |group| Group.new( "id" => group['nsid'],
                                       "name" => group['name'],
                                       "eighteenplus" => group['eighteenplus'],
                                       "client" => @client) }
end
photos(options={}) click to toggle source

Implements flickr.people.getPublicPhotos. Options hash allows you to add extra restrictions as per flickr.people.getPublicPhotos docs, e.g. user.photos(‘per_page’ => ‘25’, ‘extras’ => ‘date_taken’)

# File lib/flickr.rb, line 371
def photos(options={})
  @client.photos_request('people.getPublicPhotos', {'user_id' => @id}.merge(options))
  # what about non-public photos?
end
photosets() click to toggle source

Implements flickr.photosets.getList

# File lib/flickr.rb, line 393
def photosets
  @client.photosets_getList('user_id'=>@id)['photosets']['photoset'].collect { |photoset| Photoset.new(photoset['id'], @api_key) }
end
pretty_url() click to toggle source
# File lib/flickr.rb, line 354
def pretty_url
  @pretty_url ||= @client.urls_getUserProfile('user_id'=>@id)['user']['url']
end
tag(tag) click to toggle source

Gets photos with a given tag

# File lib/flickr.rb, line 377
def tag(tag)
  @client.photos('user_id'=>@id, 'tags'=>tag)
end
tags() click to toggle source

Implements flickr.tags.getListUser

# File lib/flickr.rb, line 398
def tags
  @client.tags_getListUser('user_id'=>@id)['who']['tags']['tag'].collect { |tag| tag }
end
to_s() click to toggle source
# File lib/flickr.rb, line 412
def to_s
  @name
end
username() click to toggle source
# File lib/flickr.rb, line 323
def username
  @username.nil? ? getInfo.username : @username
end

Private Instance Methods

getInfo() click to toggle source

Implements flickr.people.getInfo, flickr.urls.getUserPhotos, and flickr.urls.getUserProfile

# File lib/flickr.rb, line 419
def getInfo
  info = @client.people_getInfo('user_id'=>@id)['person']
  @username = info['username']
  @name = info['realname']
  @location = info['location']
  @count = info['photos']['count']
  @firstdate = info['photos']['firstdate']
  @firstdatetaken = info['photos']['firstdatetaken']
  self
end