Skip to content

Instantly share code, notes, and snippets.

@tisba
Created November 2, 2009 08:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tisba/224037 to your computer and use it in GitHub Desktop.
Save tisba/224037 to your computer and use it in GitHub Desktop.
class CurlAdapter
class Response
attr_reader :http_response_code
attr_reader :time_total
def initialize(http_response_code, time_total)
@http_response_code = http_response_code
@time_total = time_total
end
def inspect
"#{@http_response_code} #{@time_total} sec"
end
end
class Invoker
attr_reader :db_url
def initialize(db_url)
@db_url = db_url
end
def invoke(payload)
cmd = "curl -T - -X POST #{@db_url}/_bulk_docs -w\"%{http_code}\ %{time_total}\" -o out.file 2> /dev/null"
curl_io = IO.popen(cmd, "w+")
curl_io.puts payload
curl_io.close_write
result = CurlAdapter::Response.new(*curl_io.gets.split(" "))
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment