diff --git a/README.md b/README.md
index 99acc9638..3be642c7a 100644
--- a/README.md
+++ b/README.md
@@ -467,23 +467,6 @@ After configuration, requests can be made like so:
client.update("I'm tweeting with @gem!")
```
-### Middleware
-The Faraday middleware stack is fully configurable and is exposed as a
-`Faraday::RackBuilder` object. You can modify the default middleware in-place:
-
-```ruby
-client.middleware.insert_after Twitter::Response::RaiseError, CustomMiddleware
-```
-
-A custom adapter may be set as part of a custom middleware stack:
-
-```ruby
-client.middleware = Faraday::RackBuilder.new do |faraday|
- # Specify a middleware stack here
- faraday.adapter :some_other_adapter
-end
-```
-
## Usage Examples
All examples require an authenticated Twitter client. See the section on configuration.
diff --git a/Rakefile b/Rakefile
index 472940df7..490e83708 100644
--- a/Rakefile
+++ b/Rakefile
@@ -31,7 +31,7 @@ end
require 'yardstick/rake/verify'
Yardstick::Rake::Verify.new do |verify|
- verify.threshold = 59.7
+ verify.threshold = 59.9
end
task :default => [:spec, :rubocop, :verify_measurements]
diff --git a/etc/erd.dot b/etc/erd.dot
index f66a96deb..144980b59 100644
--- a/etc/erd.dot
+++ b/etc/erd.dot
@@ -5,8 +5,6 @@ digraph classes {
ArgumentError [label="ArgumentError"]
Array [label="Array"]
Exception [label="Exception"]
- Faraday__Middleware [label="Faraday::Middleware"]
- Faraday__Response__Middleware [label="Faraday::Response::Middleware"]
Naught__BasicObject [label="Naught::BasicObject"]
StandardError [label="StandardError"]
Twitter__Arguments [label="Twitter::Arguments"]
@@ -34,7 +32,6 @@ digraph classes {
Twitter__Error__InternalServerError [label="Twitter::Error::InternalServerError"]
Twitter__Error__NotAcceptable [label="Twitter::Error::NotAcceptable"]
Twitter__Error__NotFound [label="Twitter::Error::NotFound"]
- Twitter__Error__RequestTimeout [label="Twitter::Error::RequestTimeout"]
Twitter__Error__ServerError [label="Twitter::Error::ServerError"]
Twitter__Error__ServiceUnavailable [label="Twitter::Error::ServiceUnavailable"]
Twitter__Error__TooManyRequests [label="Twitter::Error::TooManyRequests"]
@@ -57,10 +54,6 @@ digraph classes {
Twitter__Place [label="Twitter::Place"]
Twitter__ProfileBanner [label="Twitter::ProfileBanner"]
Twitter__REST__Client [label="Twitter::REST::Client"]
- Twitter__REST__Request__MultipartWithFile [label="Twitter::REST::Request::MultipartWithFile"]
- Twitter__REST__Response__ParseErrorJson [label="Twitter::REST::Response::ParseErrorJson"]
- Twitter__REST__Response__ParseJson [label="Twitter::REST::Response::ParseJson"]
- Twitter__REST__Response__RaiseError [label="Twitter::REST::Response::RaiseError"]
Twitter__RateLimit [label="Twitter::RateLimit"]
Twitter__Relationship [label="Twitter::Relationship"]
Twitter__Request [label="Twitter::Request"]
@@ -88,8 +81,6 @@ digraph classes {
ArgumentError -> StandardError
Array -> Object
Exception -> Object
- Faraday__Middleware -> Object
- Faraday__Response__Middleware -> Faraday__Middleware
Naught__BasicObject -> Object
StandardError -> Exception
Twitter__Arguments -> Array
@@ -117,7 +108,6 @@ digraph classes {
Twitter__Error__InternalServerError -> Twitter__Error__ServerError
Twitter__Error__NotAcceptable -> Twitter__Error__ClientError
Twitter__Error__NotFound -> Twitter__Error__ClientError
- Twitter__Error__RequestTimeout -> Twitter__Error__ClientError
Twitter__Error__ServerError -> Twitter__Error
Twitter__Error__ServiceUnavailable -> Twitter__Error__ServerError
Twitter__Error__TooManyRequests -> Twitter__Error__ClientError
@@ -140,10 +130,6 @@ digraph classes {
Twitter__Place -> Twitter__Base
Twitter__ProfileBanner -> Twitter__Base
Twitter__REST__Client -> Twitter__Client
- Twitter__REST__Request__MultipartWithFile -> Faraday__Middleware
- Twitter__REST__Response__ParseErrorJson -> Twitter__REST__Response__ParseJson
- Twitter__REST__Response__ParseJson -> Faraday__Response__Middleware
- Twitter__REST__Response__RaiseError -> Faraday__Response__Middleware
Twitter__RateLimit -> Twitter__Base
Twitter__Relationship -> Twitter__Base
Twitter__Request -> Object
diff --git a/etc/erd.png b/etc/erd.png
index 3f695573b..4f92390d8 100644
Binary files a/etc/erd.png and b/etc/erd.png differ
diff --git a/lib/twitter/cursor.rb b/lib/twitter/cursor.rb
index 9eccb28e7..2d6782095 100644
--- a/lib/twitter/cursor.rb
+++ b/lib/twitter/cursor.rb
@@ -43,7 +43,7 @@ def last?
# @return [Hash]
def fetch_next_page
- response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor)).body
+ response = @client.send(@request_method, @path, @options.merge(:cursor => next_cursor))
self.attrs = response
end
diff --git a/lib/twitter/error.rb b/lib/twitter/error.rb
index bf4ede5ed..8ffc5560f 100644
--- a/lib/twitter/error.rb
+++ b/lib/twitter/error.rb
@@ -32,11 +32,11 @@ module Code
class << self
# Create a new error from an HTTP response
#
- # @param response [Faraday::Response]
+ # @param response [HTTP::Response]
# @return [Twitter::Error]
def from_response(response)
- message, code = parse_error(response.body)
- new(message, response.response_headers, code)
+ message, code = parse_error(response.parse)
+ new(message, response.headers, code)
end
# @return [Hash]
@@ -47,7 +47,6 @@ def errors
403 => Twitter::Error::Forbidden,
404 => Twitter::Error::NotFound,
406 => Twitter::Error::NotAcceptable,
- 408 => Twitter::Error::RequestTimeout,
422 => Twitter::Error::UnprocessableEntity,
429 => Twitter::Error::TooManyRequests,
500 => Twitter::Error::InternalServerError,
@@ -68,7 +67,7 @@ def forbidden_messages
private
def parse_error(body)
- if body.nil?
+ if body.nil? || body.empty?
['', nil]
elsif body[:error]
[body[:error], nil]
@@ -129,9 +128,6 @@ class NotFound < ClientError; end
# Raised when Twitter returns the HTTP status code 406
class NotAcceptable < ClientError; end
- # Raised when Twitter returns the HTTP status code 408
- class RequestTimeout < ClientError; end
-
# Raised when Twitter returns the HTTP status code 422
class UnprocessableEntity < ClientError; end
diff --git a/lib/twitter/request.rb b/lib/twitter/request.rb
index f8d8d4ded..730f69569 100644
--- a/lib/twitter/request.rb
+++ b/lib/twitter/request.rb
@@ -19,7 +19,7 @@ def initialize(client, request_method, path, options = {})
# @return [Hash]
def perform
- @client.send(@request_method, @path, @options).body
+ @client.send(@request_method, @path, @options)
end
# @param klass [Class]
diff --git a/lib/twitter/rest/client.rb b/lib/twitter/rest/client.rb
index ea856a940..658647e64 100644
--- a/lib/twitter/rest/client.rb
+++ b/lib/twitter/rest/client.rb
@@ -1,14 +1,10 @@
require 'base64'
-require 'faraday'
-require 'faraday/request/multipart'
+require 'http'
require 'json'
require 'timeout'
require 'twitter/client'
require 'twitter/error'
require 'twitter/rest/api'
-require 'twitter/rest/request/multipart_with_file'
-require 'twitter/rest/response/parse_json'
-require 'twitter/rest/response/raise_error'
module Twitter
module REST
@@ -22,51 +18,16 @@ class Client < Twitter::Client
attr_writer :connection_options, :middleware
ENDPOINT = 'https://api.twitter.com'
- def connection_options
- @connection_options ||= {
- :builder => middleware,
- :headers => {
- :accept => 'application/json',
- :user_agent => user_agent,
- },
- :request => {
- :open_timeout => 10,
- :timeout => 30,
- },
- }
- 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 https://github.com/technoweenie/faraday#advanced-middleware-usage
- # @see http://mislav.uniqpath.com/2011/07/faraday-advanced-http/
- # @return [Faraday::RackBuilder]
- 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
-
# Perform an HTTP GET request
def get(path, params = {})
- headers = request_headers(:get, path, params)
- request(:get, path, params, headers)
+ header = auth_header(:get, path, params)
+ request(:get, path, {:params => params}, :authorization => header)
end
# Perform an HTTP POST request
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)
+ header = params.values.any? { |value| value.respond_to?(:to_io) } ? auth_header(:post, path, params, {}) : auth_header(:post, path, params)
+ request(:post, path, {:form => params}, :authorization => header)
end
# @return [Boolean]
@@ -81,32 +42,30 @@ def credentials?
private
- # Returns a Faraday::Connection object
- #
- # @return [Faraday::Connection]
- def connection
- @connection ||= Faraday.new(ENDPOINT, connection_options)
+ def request(method, path, params = {}, headers = {})
+ response = HTTP.with(headers).send(method, ENDPOINT + path, params)
+ error = error(response)
+ fail(error) if error
+ response.parse
end
- def request(method, path, params = {}, headers = {})
- connection.send(method.to_sym, path, params) { |request| request.headers.update(headers) }.env
- rescue Faraday::Error::TimeoutError, Timeout::Error => error
- raise(Twitter::Error::RequestTimeout.new(error))
- rescue Faraday::Error::ClientError, JSON::ParserError => error
- fail(Twitter::Error.new(error))
+ def error(response)
+ klass = Twitter::Error.errors[response.code]
+ if klass == Twitter::Error::Forbidden
+ forbidden_error(response)
+ elsif !klass.nil?
+ klass.from_response(response)
+ end
end
- def request_headers(method, path, params = {}, signature_params = params)
- bearer_token_request = params.delete(:bearer_token_request)
- headers = {}
- if bearer_token_request
- headers[:accept] = '*/*'
- headers[:authorization] = bearer_token_credentials_auth_header
- headers[:content_type] = 'application/x-www-form-urlencoded; charset=UTF-8'
+ def forbidden_error(response)
+ error = Twitter::Error::Forbidden.from_response(response)
+ klass = Twitter::Error.forbidden_messages[error.message]
+ if klass
+ klass.from_response(response)
else
- headers[:authorization] = auth_header(method, path, params, signature_params)
+ error
end
- headers
end
def auth_header(method, path, params = {}, signature_params = params)
@@ -118,23 +77,10 @@ def auth_header(method, path, params = {}, signature_params = params)
end
end
- # Generates authentication header for a bearer token request
- #
- # @return [String]
- def bearer_token_credentials_auth_header
- basic_auth_token = strict_encode64("#{@consumer_key}:#{@consumer_secret}")
- "Basic #{basic_auth_token}"
- end
-
def bearer_auth_header
token = bearer_token.is_a?(Twitter::Token) && bearer_token.bearer? ? bearer_token.access_token : bearer_token
"Bearer #{token}"
end
-
- # Base64.strict_encode64 is not available on Ruby 1.8.7
- def strict_encode64(str)
- Base64.encode64(str).gsub("\n", '')
- end
end
end
end
diff --git a/lib/twitter/rest/friends_and_followers.rb b/lib/twitter/rest/friends_and_followers.rb
index 3d4dcfcbf..02a55330b 100644
--- a/lib/twitter/rest/friends_and_followers.rb
+++ b/lib/twitter/rest/friends_and_followers.rb
@@ -273,7 +273,7 @@ def friends(*args)
# @return [Array]
# @param options [Hash] A customizable set of options.
def no_retweet_ids(options = {})
- get('/1.1/friendships/no_retweets/ids.json', options).body.collect(&:to_i)
+ get('/1.1/friendships/no_retweets/ids.json', options).collect(&:to_i)
end
alias_method :no_retweets_ids, :no_retweet_ids
end
diff --git a/lib/twitter/rest/help.rb b/lib/twitter/rest/help.rb
index 1c9638fb7..764b182ba 100644
--- a/lib/twitter/rest/help.rb
+++ b/lib/twitter/rest/help.rb
@@ -38,7 +38,7 @@ def languages(options = {})
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [String]
def privacy(options = {})
- get('/1.1/help/privacy.json', options).body[:privacy]
+ get('/1.1/help/privacy.json', options)[:privacy]
end
# Returns {https://twitter.com/tos Twitter's Terms of Service}
@@ -49,7 +49,7 @@ def privacy(options = {})
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [String]
def tos(options = {})
- get('/1.1/help/tos.json', options).body[:tos]
+ get('/1.1/help/tos.json', options)[:tos]
end
end
end
diff --git a/lib/twitter/rest/oauth.rb b/lib/twitter/rest/oauth.rb
index ff913503d..0a2f2111b 100644
--- a/lib/twitter/rest/oauth.rb
+++ b/lib/twitter/rest/oauth.rb
@@ -1,6 +1,5 @@
require 'twitter/request'
require 'twitter/rest/utils'
-require 'twitter/rest/response/parse_error_json'
require 'twitter/token'
module Twitter
@@ -24,9 +23,12 @@ module OAuth
# client = Twitter::REST::Client.new(:consumer_key => "abc", :consumer_secret => 'def')
# bearer_token = client.token
def token(options = {})
- options[:bearer_token_request] = true
options[:grant_type] ||= 'client_credentials'
- perform_with_object(:post, '/oauth2/token', options, Twitter::Token)
+ headers = {}
+ headers[:accept] = '*/*'
+ headers[:authorization] = "Basic #{strict_encode64("#{@consumer_key}:#{@consumer_secret}")}"
+ response = HTTP.with(headers).post('https://api.twitter.com/oauth2/token', :form => options)
+ Twitter::Token.new(response.parse)
end
alias_method :bearer_token, :token
@@ -53,12 +55,17 @@ def invalidate_token(access_token, options = {})
# @raise [Twitter::Error::Unauthorized] Error raised when supplied user credentials are not valid.
# @return [String] The token string.
def reverse_token
- conn = connection.dup
- conn.builder.swap(4, Twitter::REST::Response::ParseErrorJson)
- response = conn.post('/oauth/request_token?x_auth_mode=reverse_auth') do |request|
- request.headers[:authorization] = oauth_auth_header(:post, 'https://api.twitter.com/oauth/request_token', :x_auth_mode => 'reverse_auth').to_s
- end
- response.body
+ uri = 'https://api.twitter.com/oauth/request_token'
+ options = {:x_auth_mode => 'reverse_auth'}
+ headers = {:authorization => oauth_auth_header(:post, uri, options).to_s}
+ HTTP.with(headers).post(uri, :params => options).to_s
+ end
+
+ private
+
+ # Base64.strict_encode64 is not available on Ruby 1.8.7
+ def strict_encode64(str)
+ Base64.encode64(str).gsub("\n", '')
end
end
end
diff --git a/lib/twitter/rest/request/multipart_with_file.rb b/lib/twitter/rest/request/multipart_with_file.rb
deleted file mode 100644
index 41cdbbb2c..000000000
--- a/lib/twitter/rest/request/multipart_with_file.rb
+++ /dev/null
@@ -1,40 +0,0 @@
-require 'faraday'
-
-module Twitter
- module REST
- module Request
- class MultipartWithFile < Faraday::Middleware
- CONTENT_TYPE = 'Content-Type'
- GIF_REGEX = /\.gif$/i
- JPEG_REGEX = /\.jpe?g/i
- PNG_REGEX = /\.png$/i
-
- def call(request)
- request.body.each do |key, value|
- if value.respond_to?(:to_io)
- request.body[key] = Faraday::UploadIO.new(value, mime_type(value.path), value.path)
- end
- end if request.body.is_a?(::Hash)
- @app.call(request)
- end
-
- private
-
- def mime_type(path)
- case path
- when GIF_REGEX
- 'image/gif'
- when JPEG_REGEX
- 'image/jpeg'
- when PNG_REGEX
- 'image/png'
- else
- 'application/octet-stream'
- end
- end
- end
- end
- end
-end
-
-Faraday::Request.register_middleware :multipart_with_file => Twitter::REST::Request::MultipartWithFile
diff --git a/lib/twitter/rest/response/parse_error_json.rb b/lib/twitter/rest/response/parse_error_json.rb
deleted file mode 100644
index c1d0ef07f..000000000
--- a/lib/twitter/rest/response/parse_error_json.rb
+++ /dev/null
@@ -1,13 +0,0 @@
-require 'twitter/rest/response/parse_json'
-
-module Twitter
- module REST
- module Response
- class ParseErrorJson < Twitter::REST::Response::ParseJson
- def unparsable_status_codes
- super + [200]
- end
- end
- end
- end
-end
diff --git a/lib/twitter/rest/response/parse_json.rb b/lib/twitter/rest/response/parse_json.rb
deleted file mode 100644
index 639ee0d08..000000000
--- a/lib/twitter/rest/response/parse_json.rb
+++ /dev/null
@@ -1,31 +0,0 @@
-require 'faraday'
-require 'json'
-
-module Twitter
- module REST
- module Response
- class ParseJson < Faraday::Response::Middleware
- WHITESPACE_REGEX = /\A^\s*$\z/
-
- def parse(body)
- case body
- when WHITESPACE_REGEX, nil
- nil
- else
- JSON.parse(body, :symbolize_names => true)
- end
- end
-
- def on_complete(response)
- response.body = parse(response.body) if respond_to?(:parse) && !unparsable_status_codes.include?(response.status)
- end
-
- def unparsable_status_codes
- [204, 301, 302, 304]
- end
- end
- end
- end
-end
-
-Faraday::Response.register_middleware :parse_json => Twitter::REST::Response::ParseJson
diff --git a/lib/twitter/rest/response/raise_error.rb b/lib/twitter/rest/response/raise_error.rb
deleted file mode 100644
index 7a0ebfcfa..000000000
--- a/lib/twitter/rest/response/raise_error.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-require 'faraday'
-require 'twitter/error'
-
-module Twitter
- module REST
- module Response
- class RaiseError < Faraday::Response::Middleware
- def on_complete(response)
- status_code = response.status.to_i
- klass = Twitter::Error.errors[status_code]
- if klass
- error = if klass == Twitter::Error::Forbidden
- handle_forbidden_errors(response)
- else
- klass.from_response(response)
- end
- fail(error)
- end
- end
-
- private
-
- def handle_forbidden_errors(response)
- error = Twitter::Error::Forbidden.from_response(response)
- klass = Twitter::Error.forbidden_messages[error.message]
- if klass
- klass.from_response(response)
- else
- error
- end
- end
- end
- end
- end
-end
-
-Faraday::Response.register_middleware :raise_error => Twitter::REST::Response::RaiseError
diff --git a/lib/twitter/rest/search.rb b/lib/twitter/rest/search.rb
index 18d7c5670..2a30bfcb8 100644
--- a/lib/twitter/rest/search.rb
+++ b/lib/twitter/rest/search.rb
@@ -29,7 +29,7 @@ module Search
def search(q, options = {})
options[:count] ||= MAX_TWEETS_PER_REQUEST
request = Twitter::Request.new(self, :get, '/1.1/search/tweets.json', options.merge(:q => q))
- response = get(request.path, request.options).body
+ response = get(request.path, request.options)
Twitter::SearchResults.new(response, request)
end
end
diff --git a/lib/twitter/rest/trends.rb b/lib/twitter/rest/trends.rb
index 0ae200b81..ba585a3ce 100644
--- a/lib/twitter/rest/trends.rb
+++ b/lib/twitter/rest/trends.rb
@@ -20,7 +20,7 @@ module Trends
# @return [Array]
def trends(id = 1, options = {})
options[:id] = id
- response = get('/1.1/trends/place.json', options).body.first
+ response = get('/1.1/trends/place.json', options).first
Twitter::TrendResults.new(response)
end
alias_method :local_trends, :trends
diff --git a/lib/twitter/rest/tweets.rb b/lib/twitter/rest/tweets.rb
index c0ab2c5d1..4d0591f49 100644
--- a/lib/twitter/rest/tweets.rb
+++ b/lib/twitter/rest/tweets.rb
@@ -299,7 +299,7 @@ def parallel_tweets_from_response(request_method, path, args)
end
def post_retweet(tweet, options)
- response = post("/1.1/statuses/retweet/#{extract_id(tweet)}.json", options).body
+ response = post("/1.1/statuses/retweet/#{extract_id(tweet)}.json", options)
retweeted_status = response.delete(:retweeted_status)
retweeted_status[:retweeted_status] = response
Twitter::Tweet.new(retweeted_status)
diff --git a/lib/twitter/rest/undocumented.rb b/lib/twitter/rest/undocumented.rb
index 9787e4e27..1eb148073 100644
--- a/lib/twitter/rest/undocumented.rb
+++ b/lib/twitter/rest/undocumented.rb
@@ -41,8 +41,7 @@ def following_followers_of(*args)
# @param uri [String, URI] A URI.
# @param options [Hash] A customizable set of options.
def tweet_count(uri, options = {})
- connection = Faraday.new('https://cdn.api.twitter.com', connection_options.merge(:builder => middleware))
- connection.get('/1/urls/count.json', options.merge(:url => uri.to_s)).body[:count]
+ HTTP.get('https://cdn.api.twitter.com/1/urls/count.json', :params => options.merge(:url => uri.to_s)).parse[:count]
end
end
end
diff --git a/lib/twitter/rest/users.rb b/lib/twitter/rest/users.rb
index 4a3015ad2..26e36057f 100644
--- a/lib/twitter/rest/users.rb
+++ b/lib/twitter/rest/users.rb
@@ -32,7 +32,7 @@ module Users
# @option options [String] :lang The language which Twitter should render in for this user. The language must be specified by the appropriate two letter ISO 639-1 representation. Currently supported languages are provided by {https://dev.twitter.com/docs/api/1.1/get/help/languages GET help/languages}.
def settings(options = {})
request_method = options.size.zero? ? :get : :post
- response = send(request_method.to_sym, '/1.1/account/settings.json', options).body
+ response = send(request_method.to_sym, '/1.1/account/settings.json', options)
# https://dev.twitter.com/issues/59
response.update(:trend_location => Array(response[:trend_location]).first)
Twitter::Settings.new(response)
@@ -335,7 +335,7 @@ def contributors(*args)
# @return [nil]
# @param options [Hash] A customizable set of options.
def remove_profile_banner(options = {})
- post('/1.1/account/remove_profile_banner.json', options).body
+ post('/1.1/account/remove_profile_banner.json', options)
true
end
deprecate_alias :profile_banner_remove, :remove_profile_banner
@@ -358,7 +358,7 @@ def remove_profile_banner(options = {})
# @option options [Integer] :offset_left The number of pixels by which to offset the uploaded image from the left. Use with height, width, and offset_top to select the desired region of the image to use.
# @option options [Integer] :offset_top The number of pixels by which to offset the uploaded image from the top. Use with height, width, and offset_left to select the desired region of the image to use.
def update_profile_banner(banner, options = {})
- post('/1.1/account/update_profile_banner.json', options.merge(:banner => banner)).body
+ post('/1.1/account/update_profile_banner.json', options.merge(:banner => banner))
true
end
diff --git a/lib/twitter/search_results.rb b/lib/twitter/search_results.rb
index 362912247..ab654d89e 100644
--- a/lib/twitter/search_results.rb
+++ b/lib/twitter/search_results.rb
@@ -50,7 +50,7 @@ def next_page
# @return [Hash]
def fetch_next_page
- response = @client.send(@request_method, @path, next_page).body
+ response = @client.send(@request_method, @path, next_page)
self.attrs = response
end
diff --git a/spec/helper.rb b/spec/helper.rb
index 401098dd7..314430f40 100644
--- a/spec/helper.rb
+++ b/spec/helper.rb
@@ -8,7 +8,7 @@
SimpleCov.start do
add_filter '/spec/'
- minimum_coverage(99.39)
+ minimum_coverage(99.36)
end
require 'twitter'
diff --git a/spec/twitter/error_spec.rb b/spec/twitter/error_spec.rb
index 53bf97e0f..6eacc3861 100644
--- a/spec/twitter/error_spec.rb
+++ b/spec/twitter/error_spec.rb
@@ -27,10 +27,10 @@
end
end
- [nil, 'error', 'errors'].each do |key|
- context "when JSON body contains #{key.inspect}" do
+ %w[error errors].each do |key|
+ context "when JSON body contains #{key}" do
before do
- body = "{\"#{key}\":\"Internal Server Error\"}" unless body.nil?
+ body = "{\"#{key}\":\"Internal Server Error\"}"
stub_get('/1.1/statuses/user_timeline.json').with(:query => {:screen_name => 'sferik'}).to_return(:status => 500, :body => body)
end
it 'raises an exception with the proper message' do
diff --git a/spec/twitter/rest/client_spec.rb b/spec/twitter/rest/client_spec.rb
index 4c0028ee7..e2817c39f 100644
--- a/spec/twitter/rest/client_spec.rb
+++ b/spec/twitter/rest/client_spec.rb
@@ -76,16 +76,6 @@
end
end
- describe '#connection' do
- it 'looks like Faraday connection' do
- expect(@client.send(:connection)).to respond_to(:run_request)
- end
- it 'memoizes the connection' do
- c1, c2 = @client.send(:connection), @client.send(:connection)
- expect(c1.object_id).to eq(c2.object_id)
- end
- end
-
describe '#request' do
it 'encodes the entire body when no uploaded media is present' do
stub_post('/1.1/statuses/update.json').with(:body => {:status => 'Update'}).to_return(:body => fixture('status.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
@@ -97,22 +87,6 @@
@client.update_with_media('Update', fixture('pbjt.gif'))
expect(a_post('/1.1/statuses/update_with_media.json')).to have_been_made
end
- it 'catches and reraises Faraday timeout errors' do
- allow(@client).to receive(:connection).and_raise(Faraday::Error::TimeoutError.new('execution expired'))
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
- end
- it 'catches and reraises Timeout errors' do
- allow(@client).to receive(:connection).and_raise(Timeout::Error.new('execution expired'))
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error::RequestTimeout)
- end
- it 'catches and reraises Faraday client errors' do
- allow(@client).to receive(:connection).and_raise(Faraday::Error::ClientError.new('connection failed'))
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
- end
- it 'catches and reraises JSON::ParserError errors' do
- allow(@client).to receive(:connection).and_raise(JSON::ParserError.new('unexpected token'))
- expect { @client.send(:request, :get, '/path') }.to raise_error(Twitter::Error)
- end
end
describe '#oauth_auth_header' do
@@ -167,11 +141,4 @@
expect(authorization).to eq('Bearer BT')
end
end
-
- describe '#bearer_token_credentials_auth_header' do
- it 'creates the correct auth header with supplied consumer_key and consumer_secret' do
- authorization = @client.send(:bearer_token_credentials_auth_header)
- expect(authorization).to eq('Basic Q0s6Q1M=')
- end
- end
end
diff --git a/spec/twitter/rest/oauth_spec.rb b/spec/twitter/rest/oauth_spec.rb
index baa7de2bd..2c401aebf 100644
--- a/spec/twitter/rest/oauth_spec.rb
+++ b/spec/twitter/rest/oauth_spec.rb
@@ -8,13 +8,11 @@
describe '#token' do
before do
- # Faraday treats Basic Auth differently so we have to use the full URL with credentials
- @oauth2_token_url = 'https://CK:CS@api.twitter.com/oauth2/token'
- stub_request(:post, @oauth2_token_url).with(:body => {'grant_type' => 'client_credentials'}).to_return(:body => fixture('bearer_token.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
+ stub_post('/oauth2/token').with(:body => {'grant_type' => 'client_credentials'}).to_return(:body => fixture('bearer_token.json'), :headers => {:content_type => 'application/json; charset=utf-8'})
end
it 'requests the correct resource' do
@client.token
- expect(a_request(:post, @oauth2_token_url).with(:body => {:grant_type => 'client_credentials'}, :headers => {:content_type => 'application/x-www-form-urlencoded; charset=UTF-8', :accept => '*/*'})).to have_been_made
+ expect(a_post('/oauth2/token').with(:body => {:grant_type => 'client_credentials'}, :headers => {:authorization => 'Basic Q0s6Q1M=', :content_type => 'application/x-www-form-urlencoded', :accept => '*/*'})).to have_been_made
end
it 'returns the bearer token' do
bearer_token = @client.token
diff --git a/twitter.gemspec b/twitter.gemspec
index cb5842f02..b5c5aacb8 100644
--- a/twitter.gemspec
+++ b/twitter.gemspec
@@ -6,8 +6,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'addressable', '~> 2.3'
spec.add_dependency 'buftok', '~> 0.2.0'
spec.add_dependency 'equalizer', '~> 0.0.9'
- spec.add_dependency 'faraday', '~> 0.9.0'
- spec.add_dependency 'http', '~> 0.5.0'
+ spec.add_dependency 'http', '~> 0.6.0.pre'
spec.add_dependency 'http_parser.rb', '~> 0.6.0'
spec.add_dependency 'json', '~> 1.8'
spec.add_dependency 'memoizable', '~> 0.4.0'