lib/crunchbase/api.rb in crunchbase_v2-0.0.8 vs lib/crunchbase/api.rb in crunchbase_v2-0.0.9

- old
+ new

@@ -16,13 +16,13 @@ SUPPORTED_ENTITIES = ['organizations', 'organization', 'people', 'person', 'products', 'product', 'funding_rounds', 'funding-round', 'acquisition', 'ipo', 'fund-raise', 'locations', 'categories', 'offices', 'customers'] @timeout_limit = 60 @redirect_limit = 2 @version = '2' - @base_url = 'http://api.crunchbase.com' - @site_url = "http://www.crunchbase.com" - @image_url = "http://images.crunchbase.com/" + @base_url = 'https://api.crunchbase.com' + @site_url = "https://www.crunchbase.com" + @image_url = "https://res.cloudinary.com/crunchbase-production/" @debug = false # Must be overridden in subclasses RESOURCE_NAME = "undefined" RESOURCE_LIST = "undefineds" @@ -128,19 +128,22 @@ # Performs actual HTTP requests, recursively if a redirect response is # encountered. Will raise HTTP error if response is not 200, 404, or 3xx. def self.get_url_following_redirects(uri_str, limit = 10) raise CrunchException, 'HTTP redirect too deep' if limit == 0 - url = URI.parse(uri_str) - + uri = URI.parse(uri_str) if self.debug - length = (uri_str.length + 10) - puts "*"*length - puts "*** #{url} ***" - puts "*"*length + puts "*"*120 + puts "*** #{uri} ***" + puts "*"*120 end - response = Net::HTTP.start(url.host, url.port) { |http| http.get(url.request_uri) } + http = Net::HTTP.new(uri.host, uri.port) + http.use_ssl = true if uri.scheme == 'https' + response = http.start do |h| + h.request Net::HTTP::Get.new(uri.request_uri) + end + case response when Net::HTTPSuccess, Net::HTTPNotFound response.body when Net::HTTPRedirection get_url_following_redirects(response['location'], limit - 1)