Class: Twitter::User
- Inherits:
-
Object
- Object
- Twitter::User
- Includes:
- ModelMixin
- Defined in:
- lib/vendor/twitter/lib/twitter/model.rb,
lib/vendor/twitter/lib/twitter/extras.rb
Overview
Represents a Twitter
user
Constant Summary collapse
- @@ATTRIBUTES =
[:id, :name, :description, :location, :screen_name, :url, :protected, :profile_image_url, :profile_background_color, :profile_text_color, :profile_link_color, :profile_sidebar_fill_color, :profile_sidebar_border_color, :profile_background_image_url, :profile_background_tile, :utc_offset, :time_zone, :following, :notifications, :favourites_count, :followers_count, :friends_count, :statuses_count, :created_at, ]
Class Method Summary collapse
-
.attributes ⇒ Object
Used as factory method callback.
-
.featured(client) ⇒ Object
Provides access to the Featured Twitter API via the Twitter4R Model interface.
-
.find(id, client) ⇒ Object
Returns user model object with given
id
using the configuration and credentials of theclient
object passed in.
Instance Method Summary collapse
-
#bless(client) ⇒ Object
Override of ModelMixin#bless method.
-
#friends ⇒ Object
Returns an Array of user objects that represents the authenticated user’s friends on Twitter.
-
#is_me? ⇒ Boolean
Returns whether this
Twitter::User
model object represents the authenticated user of theclient
that blessed it.
Methods included from ModelMixin
Class Method Details
.attributes ⇒ Object
Used as factory method callback
172 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 172 def attributes; @@ATTRIBUTES; end |
.featured(client) ⇒ Object
35 36 37 |
# File 'lib/vendor/twitter/lib/twitter/extras.rb', line 35 def featured(client) client.featured(:users) end |
.find(id, client) ⇒ Object
Returns user model object with given id
using the configuration and credentials of the client
object passed in.
You can pass in either the user’s unique integer ID or the user’s screen name.
179 180 181 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 179 def find(id, client) client.user(id) end |
Instance Method Details
#bless(client) ⇒ Object
Override of ModelMixin#bless method.
Adds #followers instance method when user object represents authenticated user. Otherwise just do basic bless.
This permits applications using Twitter4R
to write Rubyish code like this:
followers = user.followers if user.is_me?
Or:
followers = user.followers if user.respond_to?(:followers)
194 195 196 197 198 199 200 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 194 def bless(client) basic_bless(client) self.instance_eval(%{ self.class.send(:include, Twitter::AuthenticatedUserMixin) }) if self.is_me? and not self.respond_to?(:followers) self end |
#friends ⇒ Object
Returns an Array of user objects that represents the authenticated user’s friends on Twitter.
220 221 222 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 220 def friends @client.user(@id, :friends) end |
#is_me? ⇒ Boolean
Returns whether this Twitter::User
model object represents the authenticated user of the client
that blessed it.
205 206 207 208 209 210 211 212 213 214 215 216 |
# File 'lib/vendor/twitter/lib/twitter/model.rb', line 205 def is_me? # TODO: Determine whether we should cache this or not? # Might be dangerous to do so, but do we want to support # the edge case where this would cause a problem? i.e. # changing authenticated user after initial use of # authenticated API. # TBD: To cache or not to cache. That is the question! # Since this is an implementation detail we can leave this for # subsequent 0.2.x releases. It doesn't have to be decided before # the 0.2.0 launch. @screen_name == @client.instance_eval("@login") end |