diff --git a/lib/faraday/request/phoenix.rb b/lib/faraday/request/phoenix.rb new file mode 100644 index 000000000..9d75b9f49 --- /dev/null +++ b/lib/faraday/request/phoenix.rb @@ -0,0 +1,18 @@ +require 'faraday' + +module Faraday + class Request::Phoenix < Faraday::Middleware + def call(env) + # Not sure what what the X-Phx (Phoenix?) header is for but it's + # required to access certain undocumented resources + # e.g. GET urls/resolve + env[:request_headers]['X-Phx'] = 'true' + + @app.call(env) + end + + def initialize(app) + @app = app + end + end +end diff --git a/lib/twitter/connection.rb b/lib/twitter/connection.rb index ae7607e20..fa5995f8f 100644 --- a/lib/twitter/connection.rb +++ b/lib/twitter/connection.rb @@ -1,4 +1,5 @@ require 'faraday_middleware' +require 'faraday/request/phoenix' require 'faraday/request/multipart_with_file' require 'faraday/request/gateway' require 'faraday/request/twitter_oauth' @@ -14,11 +15,7 @@ def connection(format=format, temp_api_endpoint=nil) options = { :headers => { 'Accept' => "application/#{format}", - 'User-Agent' => user_agent, - # Not sure what what the X-Phx (Phoenix?) header is for but it's - # required to access certain undocumented resources - # e.g. GET urls/resolve - 'X-Phx' => 'true', + 'User-Agent' => user_agent }, :proxy => proxy, :ssl => {:verify => false}, @@ -27,6 +24,7 @@ def connection(format=format, temp_api_endpoint=nil) options[:url] = temp_api_endpoint ? temp_api_endpoint : api_endpoint Faraday.new(options) do |builder| + builder.use Faraday::Request::Phoenix builder.use Faraday::Request::MultipartWithFile builder.use Faraday::Request::TwitterOAuth, authentication if authenticated? builder.use Faraday::Request::Multipart