Wrapper for the Twitter REST API
@note All methods have been separated into modules and follow the same grouping used in {dev.twitter.com/doc the Twitter API Documentation}. @see dev.twitter.com/pages/every_developer
@return [Boolean]
# File lib/twitter/rest/client.rb, line 89 def bearer_token? !!bearer_token end
@return [Hash]
# 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
@param connection_options [Hash] @return [Hash]
# 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
@return [Boolean]
# File lib/twitter/rest/client.rb, line 94 def credentials? super || bearer_token? end
Perform an HTTP GET request
# 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
@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 59 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
@params middleware [Faraday::RackBuilder] @return [Faraday::RackBuilder]
# 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
Perform an HTTP POST request
# 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
Generated with the Darkfish Rdoc Generator 2.