Class: EY::Tea::Client::Consumer
- Inherits:
-
Rack::Client::Base
- Object
- Rack::Client::Base
- EY::Tea::Client::Consumer
- Defined in:
- lib/htttee/client/consumer.rb
Instance Method Summary collapse
- #build_env(request_method, url, headers = {}, body = nil) ⇒ Object
- #down(uuid) ⇒ Object
- #http_host_for(uri) ⇒ Object
- #http_user_agent ⇒ Object
-
#initialize(options = {}) ⇒ Consumer
constructor
A new instance of Consumer.
- #up(io, uuid, content_type = 'text/plain') ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Consumer
Returns a new instance of Consumer.
5 6 7 8 9 10 |
# File 'lib/htttee/client/consumer.rb', line 5 def initialize( = {}) @base_uri = URI.parse(.fetch(:endpoint, 'http://tea.engineyard.com/')) inner_app = .fetch(:app, Rack::Client::Handler::NetHTTP.new) super(inner_app) end |
Instance Method Details
#build_env(request_method, url, headers = {}, body = nil) ⇒ Object
24 25 26 27 28 29 30 31 32 33 |
# File 'lib/htttee/client/consumer.rb', line 24 def build_env(request_method, url, headers = {}, body = nil) uri = @base_uri.nil? ? URI.parse(url) : @base_uri + url env = super(request_method, uri.to_s, headers, body) env['HTTP_HOST'] ||= http_host_for(uri) env['HTTP_USER_AGENT'] ||= http_user_agent env end |
#down(uuid) ⇒ Object
16 17 18 19 20 21 22 |
# File 'lib/htttee/client/consumer.rb', line 16 def down(uuid) get("/#{uuid}") do |status, headers, response_body| response_body.each do |chunk| yield chunk end end end |
#http_host_for(uri) ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/htttee/client/consumer.rb', line 35 def http_host_for(uri) if uri.to_s.include?(":#{uri.port}") [uri.host, uri.port].join(':') else uri.host end end |
#http_user_agent ⇒ Object
43 44 45 |
# File 'lib/htttee/client/consumer.rb', line 43 def http_user_agent "htttee (rack-client #{Rack::Client::VERSION} (app: #{@app.class}))" end |
#up(io, uuid, content_type = 'text/plain') ⇒ Object
12 13 14 |
# File 'lib/htttee/client/consumer.rb', line 12 def up(io, uuid, content_type = 'text/plain') post("/#{uuid}", {'Content-Type' => content_type, 'Transfer-Encoding' => 'chunked'}, io) end |