class Twitter::REST::Client
Constants
- BASE_URL
- ENDPOINT
- URL_PREFIX
Attributes
bearer_token[RW]
Public Instance Methods
bearer_token?()
click to toggle source
@return [Boolean]
# File lib/twitter/rest/client.rb, line 84 def bearer_token? !!bearer_token end
connection()
click to toggle source
Returns a Faraday::Connection object
@return [Faraday::Connection]
# File lib/twitter/rest/client.rb, line 96 def connection @connection ||= Faraday.new(BASE_URL, connection_options) end
connection_options()
click to toggle source
@return [Hash]
# 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)
click to toggle source
@param #connection_options [Hash] @return [Hash]
# 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?()
click to toggle source
@return [Boolean]
Calls superclass method
Twitter::Client#credentials?
# File lib/twitter/rest/client.rb, line 89 def credentials? super || bearer_token? end
get(path, options = {})
click to toggle source
Perform an HTTP GET request
# 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
middleware()
click to toggle source
@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. @see github.com/technoweenie/faraday#advanced-middleware-usage @see mislav.uniqpath.com/2011/07/faraday-advanced-http/ @return [Faraday::RackBuilder]
# 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)
click to toggle source
@params middleware [Faraday::RackBuilder] @return [Faraday::RackBuilder]
# 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 = {})
click to toggle source
Perform an HTTP POST request
# 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