Skip to content

Commit

Permalink
Reuse Net::HTTP object
Browse files Browse the repository at this point in the history
  • Loading branch information
tpope committed Jan 6, 2009
1 parent dfae800 commit f9611bf
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/pickler/tracker.rb
Expand Up @@ -17,17 +17,22 @@ def initialize(token)
@token = token
end

def request(method, path, *args)
require 'net/http'
Net::HTTP.start(ADDRESS) do |http|
headers = {
"X-TrackerToken" => @token,
"Accept" => "application/xml",
"Content-type" => "application/xml"
}
klass = Net::HTTP.const_get(method.to_s.capitalize)
http.request(klass.new("#{BASE_PATH}#{path}", headers), *args)
def http
unless @http
require 'net/http'
@http = Net::HTTP.new(ADDRESS)
end
@http
end

def request(method, path, *args)
headers = {
"X-TrackerToken" => @token,
"Accept" => "application/xml",
"Content-type" => "application/xml"
}
klass = Net::HTTP.const_get(method.to_s.capitalize)
http.request(klass.new("#{BASE_PATH}#{path}", headers), *args)
end

def request_xml(method, path, *args)
Expand Down

0 comments on commit f9611bf

Please sign in to comment.