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

See Also:

Constant Summary

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

Constants included from Users

Users::MAX_USERS_PER_REQUEST

Constants included from Utils

Utils::DEFAULT_CURSOR, Utils::URI_SUBSTRING

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

Instance Method Summary (collapse)

Methods included from Users

#block, #block?, #blocked_ids, #blocking, #contributees, #contributors, #profile_banner, #remove_profile_banner, #settings, #unblock, #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, pmap_with_index

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 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_agent, #user_token?

Constructor Details

This class inherits a constructor from Twitter::Client

Instance Attribute Details

- (Object) bearer_token

Returns the value of attribute bearer_token



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

def bearer_token
  @bearer_token
end

- (Object) connection_options



25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/twitter/rest/client.rb', line 25

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

- (Faraday::RackBuilder) middleware

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.



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/twitter/rest/client.rb', line 43

def middleware
  @middleware ||= Faraday::RackBuilder.new do |faraday|
    # Convert file uploads to Faraday::UploadIO objects
    faraday.request :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 :raise_error
    # Parse JSON response bodies
    faraday.response :parse_json
    # Set default HTTP adapter
    faraday.adapter :net_http
  end
end

Instance Method Details

- (Boolean) bearer_token?

Returns:

  • (Boolean)


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

def bearer_token?
  !!bearer_token
end

- (Boolean) credentials?

Returns:

  • (Boolean)


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

def credentials?
  super || bearer_token?
end

- (Object) get(path, params = {})

Perform an HTTP GET request



61
62
63
64
# File 'lib/twitter/rest/client.rb', line 61

def get(path, params = {})
  headers = request_headers(:get, path, params)
  request(:get, path, params, headers)
end

- (Object) post(path, params = {})

Perform an HTTP POST request



67
68
69
70
# File 'lib/twitter/rest/client.rb', line 67

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