lib/patentscope/client.rb in patentscope-0.0.2 vs lib/patentscope/client.rb in patentscope-0.0.4

- old
+ new

@@ -16,17 +16,23 @@ def get_url(url) open(url, "User-Agent" => USER_AGENT_STRING, http_basic_authentication: [username, password]).read end def post_url(url, content_type = 'text/html', body = '') - uri = URI.parse(url) - http = Net::HTTP.new(uri.host, uri.port) - request = Net::HTTP::Post.new(uri.request_uri) + uri = URI(url) + request = Net::HTTP::Post.new(uri) request.basic_auth(username, password) request["User-Agent"] = USER_AGENT_STRING request["Content-Type"] = content_type request.body = body - response = http.request(request) - response.body + + Net::HTTP.start(uri.host, uri.port, use_ssl: true) do |http| + response = http.request(request) + if response.header["Content-Type"].include? "text/html" + response.body + elsif response.header["Content-Type"].include? "multipart/related" + response.body.split("\r\n\r\n")[1].split("\r\n")[0] + end + end end end end