Class: Flickr::User

Inherits:
Object
  • Object
show all
Defined in:
lib/flickr.rb

Overview

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id_or_params_hash = nil, username = nil, email = nil, password = nil, api_key = nil) ⇒ User

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)



278
279
280
281
282
283
284
285
286
287
288
289
290
# File 'lib/flickr.rb', line 278

def initialize(id_or_params_hash=nil, username=nil, email=nil, password=nil, api_key=nil)
  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
  @client.(@email, @password) if @email and @password # this is now irrelevant as Flickr API no longer supports authentication this way
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



264
265
266
# File 'lib/flickr.rb', line 264

def client
  @client
end

#countObject (readonly)

Returns the value of attribute count.



264
265
266
# File 'lib/flickr.rb', line 264

def count
  @count
end

#firstdateObject (readonly)

Returns the value of attribute firstdate.



264
265
266
# File 'lib/flickr.rb', line 264

def firstdate
  @firstdate
end

#firstdatetakenObject (readonly)

Returns the value of attribute firstdatetaken.



264
265
266
# File 'lib/flickr.rb', line 264

def firstdatetaken
  @firstdatetaken
end

#idObject (readonly)

Returns the value of attribute id.



264
265
266
# File 'lib/flickr.rb', line 264

def id
  @id
end

#locationObject (readonly)

Returns the value of attribute location.



264
265
266
# File 'lib/flickr.rb', line 264

def location
  @location
end

#nameObject (readonly)

Returns the value of attribute name.



264
265
266
# File 'lib/flickr.rb', line 264

def name
  @name
end

#photos_urlObject (readonly)

Returns the value of attribute photos_url.



264
265
266
# File 'lib/flickr.rb', line 264

def photos_url
  @photos_url
end

#urlObject (readonly)

Builds url for user’s profile page as per www.flickr.com/services/api/misc.urls.html



317
318
319
# File 'lib/flickr.rb', line 317

def url
  @url
end

Instance Method Details

#contactsObject

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



349
350
351
352
# File 'lib/flickr.rb', line 349

def contacts
  @client.contacts_getPublicList('user_id'=>@id)['contacts']['contact'].collect { |contact| User.new(contact['nsid'], contact['username'], nil, nil, @api_key) }
  #or
end

#contactsPhotosObject

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



375
376
377
# File 'lib/flickr.rb', line 375

def contactsPhotos
  @client.photos_request('photos.getContactsPublicPhotos', 'user_id' => @id)
end

#favoritesObject

Implements flickr.favorites.getPublicList



355
356
357
# File 'lib/flickr.rb', line 355

def favorites
  @client.photos_request('favorites.getPublicList', 'user_id' => @id)
end

#groupsObject

Implements flickr.people.getPublicGroups



326
327
328
329
330
331
332
333
# File 'lib/flickr.rb', line 326

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 = {}) ⇒ Object

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’)



338
339
340
341
# File 'lib/flickr.rb', line 338

def photos(options={})
  @client.photos_request('people.getPublicPhotos', {'user_id' => @id}.merge(options))
  # what about non-public photos?
end

#photosetsObject

Implements flickr.photosets.getList



360
361
362
# File 'lib/flickr.rb', line 360

def photosets
  @client.photosets_getList('user_id'=>@id)['photosets']['photoset'].collect { |photoset| Photoset.new(photoset['id'], @api_key) }
end

Implements flickr.tags.getListUserPopular



370
371
372
# File 'lib/flickr.rb', line 370

def popular_tags(count = 10)
	@client.tags_getListUserPopular('user_id'=>@id, 'count'=> count)['who']['tags']['tag'].each { |tag_score| tag_score["tag"] = tag_score.delete("content") }
end

#pretty_urlObject



321
322
323
# File 'lib/flickr.rb', line 321

def pretty_url
  @pretty_url ||= @client.urls_getUserProfile('user_id'=>@id)['user']['url']
end

#tag(tag) ⇒ Object

Gets photos with a given tag



344
345
346
# File 'lib/flickr.rb', line 344

def tag(tag)
  @client.photos('user_id'=>@id, 'tags'=>tag)
end

#tagsObject

Implements flickr.tags.getListUser



365
366
367
# File 'lib/flickr.rb', line 365

def tags
  @client.tags_getListUser('user_id'=>@id)['who']['tags']['tag'].collect { |tag| tag }
end

#to_sObject



379
380
381
# File 'lib/flickr.rb', line 379

def to_s
  @name
end

#usernameObject



292
293
294
# File 'lib/flickr.rb', line 292

def username
  @username.nil? ? getInfo.username : @username
end