Class: Twitter::REST::Client

Inherits:
Client
  • Object
show all
Includes:
API
Defined in:
lib/twitter/rest/client.rb

Constant Summary collapse

BASE_URL =
'https://api.twitter.com'.freeze
URL_PREFIX =
BASE_URL
ENDPOINT =
BASE_URL

Constants included from Users

Users::MAX_USERS_PER_REQUEST

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

Constants included from Tweets

Tweets::MAX_TWEETS_PER_REQUEST

Constants included from Timelines

Timelines::DEFAULT_TWEETS_PER_REQUEST, Timelines::MAX_TWEETS_PER_REQUEST

Constants included from Search

Search::MAX_TWEETS_PER_REQUEST

Constants included from Lists

Lists::MAX_USERS_PER_REQUEST, Lists::URI_SUBSTRING

Instance Attribute Summary collapse

Attributes inherited from Client

#access_token, #access_token_secret, #consumer_key, #consumer_secret, #proxy, #user_agent

Instance Method Summary collapse

Methods included from Users

#block, #block?, #blocked, #blocked_ids, #contributees, #contributors, #mute, #muted, #muted_ids, #profile_banner, #remove_profile_banner, #settings, #unblock, #unmute, #update_delivery_device, #update_profile, #update_profile_background_image, #update_profile_banner, #update_profile_colors, #update_profile_image, #user, #user?, #user_search, #users, #verify_credentials

Methods included from Utils

flat_pmap, pmap

Methods included from Undocumented

#following_followers_of, #tweet_count

Methods included from Tweets

#destroy_status, #oembed, #oembeds, #retweet, #retweet!, #retweeters_ids, #retweeters_of, #retweets, #status, #statuses, #update, #update!, #update_with_media

Methods included from Trends

#trends, #trends_available, #trends_closest

Methods included from Timelines

#home_timeline, #mentions_timeline, #retweeted_by_me, #retweeted_by_user, #retweeted_to_me, #retweets_of_me, #user_timeline

Methods included from SuggestedUsers

#suggest_users, #suggestions

Methods included from SpamReporting

#report_spam

Methods included from Search

#search

Methods included from SavedSearches

#create_saved_search, #destroy_saved_search, #saved_search, #saved_searches

Methods included from PlacesAndGeo

#geo_search, #place, #reverse_geocode, #similar_places

Methods included from OAuth

#invalidate_token, #reverse_token, #token

Methods included from Media

#upload

Methods included from Lists

#add_list_member, #add_list_members, #create_list, #destroy_list, #list, #list_member?, #list_members, #list_subscribe, #list_subscriber?, #list_subscribers, #list_timeline, #list_unsubscribe, #list_update, #lists, #memberships, #owned_lists, #remove_list_member, #remove_list_members, #subscriptions

Methods included from Help

#configuration, #languages, #privacy, #tos

Methods included from FriendsAndFollowers

#follow, #follow!, #follower_ids, #followers, #friend_ids, #friends, #friendship, #friendship?, #friendship_update, #friendships, #friendships_incoming, #friendships_outgoing, #no_retweet_ids, #unfollow

Methods included from Favorites

#favorite, #favorite!, #favorites, #unfavorite

Methods included from DirectMessages

#create_direct_message, #destroy_direct_message, #direct_message, #direct_messages, #direct_messages_received, #direct_messages_sent

Methods inherited from Client

#credentials, #initialize, #user_token?

Constructor Details

This class inherits a constructor from Twitter::Client

Instance Attribute Details

#bearer_tokenObject

Returns the value of attribute bearer_token.



18
19
20
# File 'lib/twitter/rest/client.rb', line 18

def bearer_token
  @bearer_token
end

Instance Method Details

#bearer_token?Boolean

Returns:

  • (Boolean)


84
85
86
# File 'lib/twitter/rest/client.rb', line 84

def bearer_token?
  !!bearer_token
end

#connectionFaraday::Connection

Returns a Faraday::Connection object

Returns:

  • (Faraday::Connection)


96
97
98
# File 'lib/twitter/rest/client.rb', line 96

def connection
  @connection ||= Faraday.new(BASE_URL, connection_options)
end

#connection_optionsHash

Returns:

  • (Hash)


28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/twitter/rest/client.rb', line 28

def connection_options
  @connection_options ||= {
    :builder => middleware,
    :headers => {
      :accept => 'application/json',
      :user_agent => user_agent,
    },
    :request => {
      :open_timeout => 10,
      :timeout => 30,
    },
    :proxy => proxy,
  }
end

#connection_options=(connection_options) ⇒ Hash

Parameters:

  • connection_options (Hash)

Returns:

  • (Hash)


22
23
24
25
# File 'lib/twitter/rest/client.rb', line 22

def connection_options=(connection_options)
  warn "#{Kernel.caller.first}: [DEPRECATION] #{self.class.name}##{__method__} is deprecated and will be removed."
  @connection_options = connection_options
end

#credentials?Boolean

Returns:

  • (Boolean)


89
90
91
# File 'lib/twitter/rest/client.rb', line 89

def credentials?
  super || bearer_token?
end

#get(path, options = {}) ⇒ Object

Perform an HTTP GET request



72
73
74
75
# File 'lib/twitter/rest/client.rb', line 72

def get(path, options = {})
  warn "#{Kernel.caller.first}: [DEPRECATION] #{self.class.name}##{__method__} is deprecated. Use Twitter::REST::Request#perform instead."
  perform_get(path, options)
end

#middlewareFaraday::RackBuilder

Note:

Faraday's middleware stack implementation is comparable to that of Rack middleware. The order of middleware is important: the first middleware on the list wraps all others, while the last middleware is the innermost one.



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/twitter/rest/client.rb', line 54

def middleware
  @middleware ||= Faraday::RackBuilder.new do |faraday|
    # Convert file uploads to Faraday::UploadIO objects
    faraday.request :twitter_multipart_with_file
    # Checks for files in the payload, otherwise leaves everything untouched
    faraday.request :multipart
    # Encodes as "application/x-www-form-urlencoded" if not already encoded
    faraday.request :url_encoded
    # Handle error responses
    faraday.response :twitter_raise_error
    # Parse JSON response bodies
    faraday.response :twitter_parse_json
    # Set default HTTP adapter
    faraday.adapter :net_http
  end
end

#middleware=(middleware) ⇒ Faraday::RackBuilder

Returns:

  • (Faraday::RackBuilder)


45
46
47
48
# File 'lib/twitter/rest/client.rb', line 45

def middleware=(middleware)
  warn "#{Kernel.caller.first}: [DEPRECATION] #{self.class.name}##{__method__} is deprecated and will be removed."
  @middleware = middleware
end

#post(path, options = {}) ⇒ Object

Perform an HTTP POST request



78
79
80
81
# File 'lib/twitter/rest/client.rb', line 78

def post(path, options = {})
  warn "#{Kernel.caller.first}: [DEPRECATION] #{self.class.name}##{__method__} is deprecated. Use Twitter::REST::Request#perform instead."
  perform_post(path, options)
end