Class: Flickr::Person
- Inherits:
-
Object
- Object
- Flickr::Person
- Includes:
- Proxy
- Defined in:
- lib/simple-flickr/person.rb
Overview
Represents a Flickr Person.
You can find a Flickr::Person by email or by username, using Flickr::Person#find.
Instance Attribute Summary
Attributes included from Proxy
Class Method Summary collapse
-
.find(query, client) ⇒ Object
Find a person on Flickr using their flickr username or email address.
-
.find_by_id(user_id, client) ⇒ Object
Find a user using their flickr user id.
Instance Method Summary collapse
-
#favorites(options) ⇒ Object
Return the most recent photos from a persons favorites.
- #groups ⇒ Object
-
#initialize(xml, client) ⇒ Person
constructor
:nodoc:.
-
#photos(options = {}) ⇒ Object
Return the most recent photos from a persons photostream.
-
#photosets ⇒ Object
Return the persons photosets.
Methods included from Proxy
#id, included, #method_missing
Constructor Details
#initialize(xml, client) ⇒ Person
:nodoc:
10 11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/simple-flickr/person.rb', line 10 def initialize( xml, client ) # :nodoc: super( xml, client ) @attributes.merge!( 'id' => xml[ 'nsid' ], 'profileurl' => xml.search('profileurl').text, 'photosurl' => xml.search('photosurl').text, 'location' => xml.search('location').text, 'realname' => xml.search('realname').text, 'username' => xml.search('username').text ) end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Flickr::Proxy
Class Method Details
.find(query, client) ⇒ Object
Find a person on Flickr using their flickr username or email address.
Parameters
- :query<String>
-
The Flickr username or email address of the person.
- :client<Flickr::Client>
-
A Flickr::Client to use for communication with flickr.
Returns
- Flickr::Person
-
An instance of Flickr::Person representing the person, or nil
if no people can be found.
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/simple-flickr/person.rb', line 69 def self.find( query, client ) return nil unless query.is_a? String begin if query.include? '@' xml = client.request( 'people.findByEmail', :find_email => query ) else xml = client.request( 'people.findByUsername', :username => query ) end rescue => e return nil if e.respond_to? :status and e.status == 1 raise e end find_by_id( xml.at('user')['nsid'], client ) end |
.find_by_id(user_id, client) ⇒ Object
Find a user using their flickr user id. Use this if you already know the NSID of a user, instead of #find.
Parameters
- :user_id<String>
-
The Flickr User id (NSID).
- :client<Flickr::Client>
-
A Flickr::Client to use for communication with flickr.
Returns
- Flickr::Person
-
An instance of Flickr::Person representing the person, or nil
if no people can be found.
96 97 98 99 100 101 102 103 104 105 |
# File 'lib/simple-flickr/person.rb', line 96 def self.find_by_id( user_id, client ) begin userxml = client.request( 'people.getInfo', :user_id => user_id ) rescue => e return nil if e.respond_to? :status and e.status == 1 raise e end new( userxml.at('person'), client ) end |
Instance Method Details
#favorites(options) ⇒ Object
Return the most recent photos from a persons favorites.
Arguments
- :options<Hash>
-
This is a hash of options that will be passed to flickr. For more details
on what you can pass, please check out www.flickr.com/services/api/flickr.favorites.getPublicList.html
Returns
- [Flickr::Photo]
-
An array of Flickr::Photo objects.
56 57 58 |
# File 'lib/simple-flickr/person.rb', line 56 def favorites( ) Photo.api_query( 'favorites.getPublicList', @client, .merge(:user_id => id) ) end |
#groups ⇒ Object
35 36 37 38 |
# File 'lib/simple-flickr/person.rb', line 35 def groups xml = @client.request( 'people.getPublicGroups', :user_id => id ) return xml.search('group').collect { |g| Flickr::Group.new(g, @client) } end |
#photos(options = {}) ⇒ Object
Return the most recent photos from a persons photostream.
Arguments
- :options<Hash>
-
This is a hash of options that will be passed to flickr. For more details
on what you can pass, please check out www.flickr.com/services/api/flickr.people.getPublicPhotos.html
Returns
- [Flickr::Photo]
-
An array of Flickr::Photo objects.
31 32 33 |
# File 'lib/simple-flickr/person.rb', line 31 def photos( = {} ) Photo.api_query( 'people.getPublicPhotos', @client, .merge(:user_id => id) ) end |
#photosets ⇒ Object
Return the persons photosets.
Returns
- [Flickr::PhotoSet]
-
An array of Flickr::PhotoSet objects.
44 45 46 |
# File 'lib/simple-flickr/person.rb', line 44 def photosets PhotoSet.api_query( 'photosets.getList', @client, :user_id => id ) end |