lib/calais/client.rb in calais-0.0.11 vs lib/calais/client.rb in calais-0.0.12
- old
+ new
@@ -25,17 +25,11 @@
"licenseID" => @license_id,
"content" => Iconv.iconv('UTF-8//IGNORE', 'UTF-8', "#{@content} ").first[0..-2],
"paramsXML" => params_xml
}
- @client ||= Curl::Easy.new
- @client.url = @use_beta ? BETA_REST_ENDPOINT : REST_ENDPOINT
- @client.timeout = HTTP_TIMEOUT
-
- post_fields = post_args.map {|k,v| Curl::PostField.content(k, v) }
-
- do_request(post_fields)
+ do_request(post_args)
end
def params_xml
check_params
document = Nokogiri::XML::Document.new
@@ -71,10 +65,14 @@
end
params_node.to_xml(:indent => 2)
end
+ def url
+ @url ||= URI.parse(calais_endpoint)
+ end
+
private
def check_params
raise 'missing content' if @content.nil? || @content.empty?
content_length = @content.length
@@ -101,13 +99,15 @@
unknown_discards = Set.new(@metadata_discards) - KNOWN_DISCARDS
raise "unknown metadata discards: #{unknown_discards.to_a.inspect}" unless unknown_discards.empty?
end
def do_request(post_fields)
- unless @client.http_post(post_fields)
- raise 'unable to post to api endpoint'
- end
+ @request ||= Net::HTTP::Post.new(url.path)
+ @request.set_form_data(post_fields)
+ Net::HTTP.new(url.host, url.port).start {|http| http.request(@request)}.body
+ end
- @client.body_str
+ def calais_endpoint
+ @use_beta ? BETA_REST_ENDPOINT : REST_ENDPOINT
end
end
-end
\ No newline at end of file
+end