Skip to content

Commit

Permalink
Move the "X-Phx" header addition to middleware
Browse files Browse the repository at this point in the history
  • Loading branch information
laserlemon committed Sep 7, 2011
1 parent 4f5d12c commit 1e55df5
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 5 deletions.
18 changes: 18 additions & 0 deletions lib/faraday/request/phoenix.rb
Original file line number Diff line number Diff line change
@@ -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
8 changes: 3 additions & 5 deletions lib/twitter/connection.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -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},
Expand All @@ -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
Expand Down

0 comments on commit 1e55df5

Please sign in to comment.