Parent

Included Modules

Twitter::Client

Used to query or post to the Twitter REST API to simplify code.

Attributes

login[RW]
oauth_consumer[RW]
oauth_access[RW]

Public Class Methods

config() click to toggle source

returns configuration object

     # File lib/twitter/config.rb, line 102
102:       def config
103:         @@config
104:       end
configure(&block) click to toggle source

Yields to given block to configure the Twitter4R API.

     # File lib/twitter/config.rb, line 107
107:       def configure(&block)
108:         raise ArgumentError, "Block must be provided to configure" unless block_given?
109:         yield config
110:       end
from_config(config_file, env = 'test') click to toggle source

Helper method mostly for irb shell prototyping.

Reads in login/password Twitter credentials from YAML file found at the location given by config_file that has the following format:

 envname:
   login: mytwitterlogin
   password: mytwitterpassword

Where envname is the name of the environment like ‘test’, ‘dev’ or ‘prod’. The env argument defaults to ‘test’.

To use this in the shell you would do something like the following examples:

 twitter = Twitter::Client.from_config('config/twitter.yml', 'dev')
 twitter = Twitter::Client.from_config('config/twitter.yml')
    # File lib/twitter/console.rb, line 24
24:       def from_config(config_file, env = 'test')
25:         yaml_hash = YAML.load(File.read(config_file))
26:         self.new yaml_hash[env]
27:       end

Public Instance Methods

account_info(type = :rate_limit_status) click to toggle source

Provides access to the Twitter rate limit status API.

You can find out information about your account status. Currently the only supported type of account status is the :rate_limit_status which returns a Twitter::RateLimitStatus object.

Example:

 account_status = client.account_info
 puts account_status.remaining_hits
    # File lib/twitter/client/account.rb, line 15
15:   def account_info(type = :rate_limit_status)
16:     response = rest_oauth_connect(:get, @@ACCOUNT_URIS[type])
17:     bless_models(Twitter::RateLimitStatus.unmarshal(response.body))
18:   end
authenticate?(login, password) click to toggle source

Provides access to the Twitter verify credentials API.

You can verify Twitter user credentials with minimal overhead using this method.

Example:

 client.authenticate?("osxisforlightweights", "l30p@rd_s^cks!")
    # File lib/twitter/client/auth.rb, line 12
12:   def authenticate?(login, password)
13:     verify_credentials(login, password)
14:   end
block(action, value) click to toggle source

Provides access to the Twitter Block API.

You can add and remove blocks to users using this method.

action can be any of the following values:

  • :add - to add a block, you would use this action value

  • :remove - to remove a block use this.

The value must be either the user screen name, integer unique user ID or Twitter::User object representation.

Examples:

 screen_name = 'dictionary'
 client.block(:add, 'dictionary')
 client.block(:remove, 'dictionary')
 id = 1260061
 client.block(:add, id)
 client.block(:remove, id)
 user = Twitter::User.find(id, client)
 client.block(:add, user)
 client.block(:remove, user)
    # File lib/twitter/client/blocks.rb, line 28
28:   def block(action, value)
29:     raise ArgumentError, "Invalid friend action provided: #{action}" unless @@BLOCK_URIS.keys.member?(action)
30:     value = value.to_i unless value.is_a?(String)
31:     uri = "#{@@BLOCK_URIS[action]}/#{value}.json"
32:     response = rest_oauth_connect(:get, uri)
33:     bless_model(Twitter::User.unmarshal(response.body))
34:   end
favorite(action, value) click to toggle source

Provides access to the Twitter add/remove favorite API.

You can add and remove favorite status using this method.

action can be any of the following values:

  • :add - to add a status to your favorites, you would use this action value

  • :remove - to remove an status from your existing favorites list use this.

The value must be either the status object to add or remove or the integer unique status ID.

Examples:

 id = 126006103423
 client.favorite(:add, id)
 client.favorite(:remove, id)
 status = Twitter::Status.find(id, client)
 client.favorite(:add, status)
 client.favorite(:remove, status)
    # File lib/twitter/client/favorites.rb, line 40
40:   def favorite(action, value)
41:     raise ArgumentError, "Invalid favorite action provided: #{action}" unless @@FAVORITES_URIS.keys.member?(action)
42:     value = value.to_i.to_s unless value.is_a?(String)
43:     uri = "#{@@FAVORITES_URIS[action]}/#{value}.json"
44:     case action
45:     when :add
46:       response = rest_oauth_connect(:post, uri)
47:     when :remove
48:       response = rest_oauth_connect(:delete, uri)
49:     end
50:     bless_model(Twitter::Status.unmarshal(response.body))
51:   end
favorites(options = nil) click to toggle source

Provides access to the Twitter list favorites API.

You can access the authenticated [Twitter] user’s favorites list using this method.

By default you will receive the last twenty statuses added to your favorites list. To get a previous page you can provide options to this method. For example,

 statuses = client.favorites(:page => 2)

The above one-liner will get the second page of favorites for the authenticated user.

    # File lib/twitter/client/favorites.rb, line 16
16:   def favorites(options = nil)
17:     uri = '/favorites.json'
18:     response = rest_oauth_connect(:get, uri, options)
19:     bless_models(Twitter::Status.unmarshal(response.body))
20:   end
friend(action, value) click to toggle source

Provides access to the Twitter Friendship API.

You can add and remove friends using this method.

action can be any of the following values:

  • :add - to add a friend, you would use this action value

  • :remove - to remove an existing friend from your friends list use this.

The value must be either the user to befriend or defriend’s screen name, integer unique user ID or Twitter::User object representation.

Examples:

 screen_name = 'dictionary'
 client.friend(:add, 'dictionary')
 client.friend(:remove, 'dictionary')
 id = 1260061
 client.friend(:add, id)
 client.friend(:remove, id)
 user = Twitter::User.find(id, client)
 client.friend(:add, user)
 client.friend(:remove, user)
    # File lib/twitter/client/friendship.rb, line 33
33:   def friend(action, value)
34:     raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIEND_URIS.keys.member?(action)
35:     value = value.to_i unless value.is_a?(String)
36:     uri = "#{@@FRIEND_URIS[action]}/#{value}.json"
37:     response = rest_oauth_connect(:post, uri)
38:     bless_model(Twitter::User.unmarshal(response.body))
39:   end
friendships(action) click to toggle source

Provides friendship information for the following scenarios:

  • :incoming - returns an array of numeric IDs for every user who has a pending request to follow the authenticating user.

  • :outgoing - returns an array of numeric IDs for every protected user for whom the authenticating user has a pending follow request.

Examples:

 client.friendships(:incoming) 
 #=> { :id_list => { :ids => [30592818, 21249843], :next_cursor => 1288724293877798413, :previous_cursor => -1300794057949944903 }}
    # File lib/twitter/client/friendship.rb, line 48
48:   def friendships(action)
49:     raise ArgumentError, "Invalid friend action provided: #{action}" unless @@FRIENDSHIP_URIS.keys.member?(action)
50:     uri = @@FRIENDSHIP_URIS[action]
51:     response = rest_oauth_connect(:get, uri)
52:     JSON.parse(response.body)
53:   end
graph(action, value = nil) click to toggle source

Provides access to the Twitter Social Graphing API.

You can retrieve the full graph of a user’s friends or followers in one method call.

action can be any of the following values:

  • :friends - retrieves ids of all friends of a given user.

  • :followers - retrieves ids of all followers of a given user.

The value must be either the user screen name, integer unique user ID or Twitter::User object representation.

Examples:

 screen_name = 'dictionary'
 client.graph(:friends, 'dictionary')
 client.graph(:followers, 'dictionary')
 id = 1260061
 client.graph(:friends, id)
 client.graph(:followers, id)
 user = Twitter::User.find(id, client)
 client.graph(:friends, user)
 client.graph(:followers, user)
    # File lib/twitter/client/graph.rb, line 28
28:   def graph(action, value = nil)
29:     raise ArgumentError, "Invalid friend action provided: #{action}" unless @@GRAPH_URIS.keys.member?(action)
30:     id = value.to_i unless value.nil? || value.is_a?(String)
31:     id ||= value
32:     id ||= @login
33:     uri = "#{@@GRAPH_URIS[action]}.json"
34:     response = rest_oauth_connect(:get, uri, :id => id)
35:     JSON.parse(response.body)
36:   end
inspect() click to toggle source
   # File lib/twitter/client/base.rb, line 4
4:   def inspect
5:     s = old_inspect
6:     s.gsub!(/@password=".*?"/, '@password="XXXX"')
7:     s.gsub!(/"secret"=>".*?"/, '"secret"=>"XXXX"')
8:     s
9:   end
Also aliased as: old_inspect
message(action, value, user = nil) click to toggle source

Provides access to Twitter’s Messaging API for sending and deleting direct messages to other users.

action can be:

  • :post - to send a new direct message, value, to user given.

  • :delete - to delete direct message with message ID value.

value should be:

  • String when action is :post. Will be the message text sent to given user.

  • Integer or Twitter::Message object when action is :delete. Will refer to the unique message ID to delete. When passing in an instance of Twitter::Message that Status will be

user should be:

  • Twitter::User, Integer or String object when action is :post. The Integer must be the unique ID of the Twitter user you wish to send the direct message to and any Strings passed in must be the screen name of the user you wish to send the direct message to.

  • totally ignore when action is :delete. It has no purpose in this use case scenario.

Examples: The example below sends the message text ‘Are you coming over at 6pm for the BBQ tonight?’ to user with screen name ‘myfriendslogin’…

 @twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', 'myfriendslogin')

The example below sends the same message text as above to user with unique integer ID of 1234567890... the example below sends the same message text as above to user represented by user object instance of Twitter::User

 @twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', user)
 message = @twitter.message(:post, 'Are you coming over at 6pm for the BBQ tonight?', 1234567890)

the example below delete’s the message send directly above to user with unique ID 1234567890...

 @twitter.message(:delete, message)

Or the following can also be done...

 @twitter.message(:delete, message.id)

In both scenarios (action is :post or :delete) a blessed Twitter::Message object is returned that represents the newly posted or newly deleted message.

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :post

  • :delete

An ArgumentError is also raised when no user argument is supplied when action is :post.

    # File lib/twitter/client/messaging.rb, line 64
64:   def message(action, value, user = nil)
65:     raise ArgumentError, "Invalid messaging action: #{action}" unless [:post, :delete].member?(action)
66:     raise ArgumentError, "User argument must be supplied for :post case" if action.eql?(:post) and user.nil?
67:     uri = @@MESSAGING_URIS[action]
68:     user = user.to_i if user and user.is_a?(Twitter::User)
69:     case action
70:     when :post
71:       response = rest_oauth_connect(:post, uri, {:text => value, :user => user, :source => self.class.config.source})
72:     when :delete
73:       response = rest_oauth_connect(:delete, uri, :id => value.to_i)
74:     end
75:     message = Twitter::Message.unmarshal(response.body)
76:     bless_model(message)
77:   end
messages(action, options = {}) click to toggle source

Provides access to Twitter’s Messaging API for received and sent direct messages.

Example:

 received_messages = @twitter.messages(:received)

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :received

  • :sent

    # File lib/twitter/client/messaging.rb, line 19
19:   def messages(action, options = {})
20:     raise ArgumentError, "Invalid messaging action: #{action}" unless [:sent, :received].member?(action)
21:     uri = @@MESSAGING_URIS[action]
22:     response = rest_oauth_connect(:get, uri, options)
23:     bless_models(Twitter::Message.unmarshal(response.body))
24:   end
my(action, options = {}) click to toggle source

Syntactic sugar for queries relating to authenticated user in Twitter’s User API

Where action is one of the following:

  • :info - Returns user instance for the authenticated user.

  • :friends - Returns Array of users that are authenticated user’s friends

  • :followers - Returns Array of users that are authenticated user’s followers

Where options is a Hash of options that can include:

  • :page - optional. Retrieves the next set of friends. There are 100 friends per page. Default: 1.

  • :lite - optional. Prevents the inline inclusion of current status. Default: false.

  • :since - optional. Only relevant for :friends action. Narrows the results to just those friends added after the date given as value of this option. Must be HTTP-formatted date.

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :info

  • :friends

  • :followers

    # File lib/twitter/client/user.rb, line 60
60:   def my(action, options = {})
61:     raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
62:     params = options.merge(:id => @login)
63:     uri = @@USER_URIS[action]
64:     response = rest_oauth_connect(:get, uri, params)
65:     users = Twitter::User.unmarshal(response.body)
66:     bless_models(users)
67:   end
old_inspect() click to toggle source
Alias for: inspect
profile(action, attributes) click to toggle source

Provides access to the Twitter Profile API.

You can update profile information. You can update the types of profile information:

  • :info (name, email, url, location, description)

  • :colors (background_color, text_color, link_color, sidebar_fill_color,

sidebar_border_color)

  • :device (set device to either “sms”, “im” or “none”)

Example:

 user = client.profile(:info, :location => "University Library")
 puts user.inspect
    # File lib/twitter/client/profile.rb, line 20
20:   def profile(action, attributes)
21:     response = rest_oauth_connect(:post, @@PROFILE_URIS[action], attributes)
22:     bless_models(Twitter::User.unmarshal(response.body))
23:   end
search(options = {}) click to toggle source

Provides access to Twitter’s Search API.

Example:

 # For keyword search
 iterator = @twitter.search(:q => "coworking")
 while (tweet = iterator.next)
   puts tweet.text
 end

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :received

  • :sent

    # File lib/twitter/client/search.rb, line 19
19:   def search(options = {})
20:     uri = @@SEARCH_URIS[:basic]
21:     response = search_oauth_connect(:get, uri, options)
22:     json = JSON.parse(response.body)
23:     bless_models(Twitter::Status.unmarshal(JSON.dump(json["results"])))
24:   end
status(action, value = nil) click to toggle source

Provides access to individual statuses via Twitter’s Status APIs

action can be of the following values:

  • :get to retrieve status content. Assumes value given responds to :to_i message in meaningful way to yield intended status id.

  • :post to publish a new status

  • :delete to remove an existing status. Assumes value given responds to :to_i message in meaningful way to yield intended status id.

  • :reply to reply to an existing status. Assumes value given is Hash which contains :in_reply_to_status_id and :status

value should be set to:

  • the status identifier for :get case

  • the status text message for :post case

  • none necessary for :delete case

Examples:

 twitter.status(:get, 107786772)
 twitter.status(:post, "New Ruby open source project Twitter4R version 0.2.0 released.")
 twitter.status(:delete, 107790712)
 twitter.status(:reply, :in_reply_to_status_id => 1390482942342, :status => "@t4ruby This new v0.7.0 release is da bomb! #ruby #twitterapi #twitter4r")
 twitter.status(:post, "My brand new status in all its glory here tweeted from Greenwich (the real one). #withawesomehashtag #booyah", :lat => 0, :long => 0)

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :get

  • :post

  • :delete

The third argument options sends on a Hash to the Twitter API with the following keys allowed:

  • :lat - latitude (for posting geolocation)

  • :long - longitude (for posting geolocation)

  • :place_id - using a place ID give by geo/reverse_geocode

  • :display_coordinates - whether or not to put a pin in the exact coordinates

    # File lib/twitter/client/status.rb, line 40
40:   def status(action, value = nil)
41:     return self.timeline_for(action, value || {}) if :replies == action
42:     raise ArgumentError, "Invalid status action: #{action}" unless @@STATUS_URIS.keys.member?(action)
43:     return nil unless value
44:     uri = @@STATUS_URIS[action]
45:     response = nil
46:     case action
47:     when :get
48:       response = rest_oauth_connect(:get, uri, {:id => value.to_i})
49:     when :post
50:       if value.is_a?(Hash)
51:         params = value.delete_if { |k, v|
52:           ![:status, :lat, :long, :place_id, :display_coordinates].member?(k)
53:         }
54:       else
55:         params = {:status => value}
56:       end
57:       response = rest_oauth_connect(:post, uri, params.merge(:source => self.class.config.source))
58:     when :delete
59:       response = rest_oauth_connect(:delete, uri, {:id => value.to_i})
60:     when :reply
61:       return nil if (!value.is_a?(Hash) || !value[:status] || !value[:in_reply_to_status_id])
62:       params = value.merge(:source => self.class.config.source)
63:       response = rest_oauth_connect(:post, uri, params)
64:     end
65:     bless_model(Twitter::Status.unmarshal(response.body))
66:   end
timeline_for(type, options = {}, &block) click to toggle source

Provides access to Twitter’s Timeline APIs

Returns timeline for given type.

type can take the following values:

  • public

  • friends or friend

  • user or me

:id is on key applicable to be defined in options:

  • the id or screen name (aka login) for :friends

  • the id or screen name (aka login) for :user

  • meaningless for the :me case, since twitter.timeline_for(:user, 'mylogin') and twitter.timeline_for(:me) are the same assuming ‘mylogin’ is the authenticated user’s screen name (aka login).

Examples:

 # returns the public statuses since status with id of 6543210
 twitter.timeline_for(:public, id => 6543210)
 # returns the statuses for friend with user id 43210
 twitter.timeline_for(:friend, :id => 43210)
 # returns the statuses for friend with screen name (aka login) of 'otherlogin'
 twitter.timeline_for(:friend, :id => 'otherlogin')
 # returns the statuses for user with screen name (aka login) of 'otherlogin'
 twitter.timeline_for(:user, :id => 'otherlogin')

options can also include the following keys:

  • :id is the user ID, screen name of Twitter::User representation of a Twitter user.

  • :since is a Time object specifying the date-time from which to return results for. Applicable for the :friend, :friends, :user and :me cases.

  • :count specifies the number of statuses to retrieve at a time. Only applicable for the :user case.

  • :page specifies page number to retrieve.

  • since_id is the status id of the public timeline from which to retrieve statuses for :public. Only applicable for the :public case.

  • include_rts flags whether to retrieve native retweets in the timeline or not. True values are true, t or 1.

You can also pass this method a block, which will iterate through the results of the requested timeline and apply the block logic for each status returned.

Example:

 twitter.timeline_for(:public) do |status|
   puts status.user.screen_name, status.text
 end
 
 twitter.timeline_for(:friend, :id => 'myfriend', :since => 30.minutes.ago) do |status|
   puts status.user.screen_name, status.text
 end
 
 timeline = twitter.timeline_for(:me) do |status|
   puts status.text
 end

An ArgumentError will be raised if an invalid type is given. Valid types are:

  • :public

  • :friends

  • :friend

  • :user

  • :me

  • :mentions

  • :replies

  • :retweetsbyme

  • :retweetstome

  • :retweetsofme

    # File lib/twitter/client/timeline.rb, line 76
76:   def timeline_for(type, options = {}, &block)
77:     raise ArgumentError, "Invalid timeline type: #{type}" unless @@TIMELINE_URIS.keys.member?(type)
78:     uri = @@TIMELINE_URIS[type]
79:     response = rest_oauth_connect(:get, uri, options)
80:     timeline = Twitter::Status.unmarshal(response.body)
81:     timeline.each {|status| bless_model(status); yield status if block_given? }
82:     timeline
83:   end
user(id, action = :info, options = {}) click to toggle source

Provides access to Twitter’s User APIs

Returns user instance for the id given. The id can either refer to the numeric user ID or the user’s screen name.

For example,

 @twitter.user(234943) #=> Twitter::User object instance for user with numeric id of 234943
 @twitter.user('mylogin') #=> Twitter::User object instance for user with screen name 'mylogin'

Where options is a Hash of options that can include:

  • :page - optional. Retrieves the next set of friends. There are 100 friends per page. Default: 1.

  • :lite - optional. Prevents the inline inclusion of current status. Default: false.

  • :since - optional. Only relevant for :friends action. Narrows the results to just those friends added after the date given as value of this option. Must be HTTP-formatted date.

An ArgumentError will be raised if an invalid action is given. Valid actions are:

  • :info

  • :friends

Note: You should not use this method to attempt to retrieve the authenticated user’s followers. Please use any of the following ways of accessing this list:

 followers = client.my(:followers)

OR

 followers = client.my(:info).followers
    # File lib/twitter/client/user.rb, line 33
33:   def user(id, action = :info, options = {})
34:     raise ArgumentError, "Invalid user action: #{action}" unless @@USER_URIS.keys.member?(action)
35:     id = id.to_i if id.is_a?(Twitter::User)
36:     id_param = id.is_a?(String) ? :screen_name : :user_id
37:     params = options.merge(id_param => id)
38:     uri = @@USER_URIS[action]
39:     response = rest_oauth_connect(:get, uri, params)
40:     bless_models(Twitter::User.unmarshal(response.body))
41:   end

Protected Instance Methods

bless_model(model) click to toggle source

“Blesses” model object with client information

    # File lib/twitter/client/base.rb, line 39
39:     def bless_model(model)
40:         model.bless(self) if model
41:     end
bless_models(list) click to toggle source
    # File lib/twitter/client/base.rb, line 43
43:     def bless_models(list)
44:       return bless_model(list) if list.respond_to?(:client=)
45:         list.collect { |model| bless_model(model) } if list.respond_to?(:collect)
46:     end
rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true) click to toggle source

Returns the response of the OAuth/HTTP(s) request for REST API requests (not Search)

    # File lib/twitter/client/base.rb, line 15
15:     def rest_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
16:       atoken = rest_access_token
17:       uri = rest_request_uri(path, params)
18:       if [:get, :delete].include?(method)
19:         response = atoken.send(method, uri, http_header.merge(headers))
20:       else
21:         response = atoken.send(method, uri, params, http_header.merge(headers))
22:       end
23:         handle_rest_response(response)
24:         response
25:     end
search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true) click to toggle source

Returns the response of the OAuth/HTTP(s) request for Search API requests (not REST)

    # File lib/twitter/client/base.rb, line 28
28:     def search_oauth_connect(method, path, params = {}, headers = {}, require_auth = true)
29:       atoken = search_access_token
30:       uri = search_request_uri(path, params)
31:       if method == :get
32:         response = atoken.send(method, uri, http_header.merge(headers))
33:       end
34:         handle_rest_response(response)
35:         response
36:     end

Private Instance Methods

construct_proxy_url() click to toggle source
     # File lib/twitter/client/base.rb, line 170
170:     def construct_proxy_url
171:       cfg = self.class.config
172:       proxy_user, proxy_pass = cfg.proxy_user, cfg.proxy_pass
173:       proxy_host, proxy_port = cfg.proxy_host, cfg.proxy_port
174:       protocol = ((cfg.proxy_protocol == :ssl) ? :https : cfg.proxy_protocol).to_s
175:       url = nil
176:       if proxy_host
177:         url = "#{protocol}://"
178:         if proxy_user
179:           url << "#{proxy_user}:#{proxy_pass}@"
180:         end
181:         url << "#{proxy_host}:#{proxy_port.to_s}"
182:       else
183:         url
184:       end
185:     end
construct_site_url(service = :rest) click to toggle source
     # File lib/twitter/client/base.rb, line 165
165:     def construct_site_url(service = :rest)
166:       protocol, host, port, path_prefix = uri_components(service)
167:       "#{(protocol == :ssl ? :https : protocol).to_s}://#{host}:#{port}"
168:     end
handle_rest_response(response, uri = nil) click to toggle source
     # File lib/twitter/client/base.rb, line 122
122:     def handle_rest_response(response, uri = nil)
123:       unless response.is_a?(Net::HTTPSuccess)
124:         raise_rest_error(response, uri)
125:       end
126:     end
http_header() click to toggle source
     # File lib/twitter/client/base.rb, line 128
128:     def http_header
129:       # can cache this in class variable since all "variables" used to 
130:       # create the contents of the HTTP header are determined by other 
131:       # class variables that are not designed to change after instantiation.
132:       @@http_header ||= { 
133:         'User-Agent' => "Twitter4R v#{Twitter::Version.to_version} [#{self.class.config.user_agent}]",
134:         'Accept' => 'text/x-json',
135:         'X-Twitter-Client' => self.class.config.application_name,
136:         'X-Twitter-Client-Version' => self.class.config.application_version,
137:         'X-Twitter-Client-URL' => self.class.config.application_url,
138:       }
139:       @@http_header
140:     end
raise_rest_error(response, uri = nil) click to toggle source
     # File lib/twitter/client/base.rb, line 113
113:     def raise_rest_error(response, uri = nil)
114:       map = JSON.parse(response.body)
115:       error = Twitter::RESTError.registry[response.code]
116:       raise error.new(:code => response.code, 
117:                       :message => response.message,
118:                       :error => map["error"],
119:                       :uri => uri)        
120:     end
rest_access_token() click to toggle source
    # File lib/twitter/client/base.rb, line 70
70:     def rest_access_token
71:       unless @rest_access_token
72:         access = @oauth_access
73:         if access
74:           key = access[:key] || access["key"]
75:           secret = access[:secret] || access["secret"]
76:         else
77:           raise Error, "No access tokens are set"
78:         end
79:         @rest_access_token = OAuth::AccessToken.new(rest_consumer, key, secret)
80:       end
81:       @rest_access_token
82:     end
rest_consumer() click to toggle source
    # File lib/twitter/client/base.rb, line 51
51:     def rest_consumer
52:       unless @rest_consumer
53:         consumer = @oauth_consumer
54:         if consumer
55:           key = consumer[:key] || consumer["key"]
56:           secret = consumer[:secret] || consumer["secret"]
57:         end
58:         cfg = self.class.config
59:         key ||= cfg.oauth_consumer_token
60:         secret ||= cfg.oauth_consumer_secret
61:         @rest_consumer = OAuth::Consumer.new(key, secret, 
62:                                              :site => construct_site_url,
63:                                              :proxy => construct_proxy_url)
64:         http = @rest_consumer.http
65:         http.read_timeout = cfg.timeout
66:       end
67:       @rest_consumer
68:     end
rest_request_uri(path, params = nil) click to toggle source
     # File lib/twitter/client/base.rb, line 142
142:     def rest_request_uri(path, params = nil)
143:       uri = "#{self.class.config.path_prefix}#{path}"
144:       uri << "?#{params.to_http_str}" if params
145:       uri
146:     end
search_access_token() click to toggle source
     # File lib/twitter/client/base.rb, line 104
104:     def search_access_token
105:       unless @search_access_token
106:         key = @oauth_access[:key] || @oauth_access["key"]
107:         secret = @oauth_access[:secret] || @oauth_access["secret"]
108:         @search_access_token = OAuth::AccessToken.new(search_consumer, key, secret)
109:       end
110:       @search_access_token
111:     end
search_consumer() click to toggle source
     # File lib/twitter/client/base.rb, line 84
 84:     def search_consumer
 85:       unless @search_consumer
 86:         cfg = self.class.config
 87:         consumer = @oauth_consumer
 88:         if consumer
 89:           key = consumer[:key] || consumer["key"] 
 90:           secret = consumer[:secret] || consumer["secret"]
 91:         end
 92:         cfg = self.class.config
 93:         key ||= cfg.oauth_consumer_token
 94:         secret ||= cfg.oauth_consumer_secret
 95:         @search_consumer = OAuth::Consumer.new(key, secret, 
 96:                                                :site => construct_site_url(:search),
 97:                                                :proxy => construct_proxy_url)
 98:         http = @search_consumer.http
 99:         http.read_timeout = cfg.timeout
100:       end
101:       @search_consumer
102:     end
search_request_uri(path, params = nil) click to toggle source
     # File lib/twitter/client/base.rb, line 148
148:     def search_request_uri(path, params = nil)
149:       uri = "#{self.class.config.search_path_prefix}#{path}"
150:       uri << "?#{params.to_http_str}" if params
151:       uri
152:     end
uri_components(service = :rest) click to toggle source
     # File lib/twitter/client/base.rb, line 154
154:     def uri_components(service = :rest)
155:       case service
156:       when :rest
157:         return self.class.config.protocol, self.class.config.host, self.class.config.port, 
158:           self.class.config.path_prefix
159:       when :search
160:         return self.class.config.search_protocol, self.class.config.search_host, 
161:           self.class.config.search_port, self.class.config.search_path_prefix
162:       end
163:     end
verify_credentials(username, passwd) click to toggle source
    # File lib/twitter/client/auth.rb, line 17
17:   def verify_credentials(username, passwd)
18:     response = rest_oauth_connect(:get, "#{@@AUTHENTICATION_URIS[:verify]}.json")
19:     response.is_a?(Net::HTTPSuccess) ? true : false
20:   end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.