Class: Twitter::REST::Client

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

Overview

Note:

All methods have been separated into modules and follow the same grouping used in the Twitter API Documentation.

Wrapper for the Twitter REST API

Constant Summary

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

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



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

def bearer_token
  @bearer_token
end

Instance Method Details

#bearer_token?Boolean



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

def bearer_token?
  !!bearer_token
end

#connection_optionsHash



33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/twitter/rest/client.rb', line 33

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



27
28
29
30
# File 'lib/twitter/rest/client.rb', line 27

def connection_options=(connection_options)
  warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::REST::Client#connection_options= is deprecated and will be removed in version 6.0.0."
  @connection_options = connection_options
end

#credentials?Boolean



94
95
96
# File 'lib/twitter/rest/client.rb', line 94

def credentials?
  super || bearer_token?
end

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

Perform an HTTP GET request



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

def get(path, params = {})
  headers = request_headers(:get, URL_PREFIX + path, params)
  request(:get, path, params, headers)
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.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/twitter/rest/client.rb', line 59

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



50
51
52
53
# File 'lib/twitter/rest/client.rb', line 50

def middleware=(middleware)
  warn "#{Kernel.caller.first}: [DEPRECATION] Twitter::REST::Client#middleware= is deprecated and will be removed in version 6.0.0."
  @middleware = middleware
end

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

Perform an HTTP POST request



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

def post(path, params = {})
  headers = params.values.any? { |value| value.respond_to?(:to_io) } ? request_headers(:post, URL_PREFIX + path, params, {}) : request_headers(:post, URL_PREFIX + path, params)
  request(:post, path, params, headers)
end