diff options
| author | Jack Nagel | 2014-02-08 16:04:53 -0500 | 
|---|---|---|
| committer | Jack Nagel | 2014-02-08 16:04:53 -0500 | 
| commit | 4d6df3e3bca5147f49deb530d930b2f40b032cd1 (patch) | |
| tree | 0b1edffaace3d05231edca4b493b73083b461046 /Library/Homebrew/utils.rb | |
| parent | f7e1244e6d761aff3c1e0228e560efb6f73f8e75 (diff) | |
| download | brew-4d6df3e3bca5147f49deb530d930b2f40b032cd1.tar.bz2 | |
Parse JSON early in GitHub module
Diffstat (limited to 'Library/Homebrew/utils.rb')
| -rw-r--r-- | Library/Homebrew/utils.rb | 8 | 
1 files changed, 6 insertions, 2 deletions
diff --git a/Library/Homebrew/utils.rb b/Library/Homebrew/utils.rb index f48e92b83..2f5bf1b0d 100644 --- a/Library/Homebrew/utils.rb +++ b/Library/Homebrew/utils.rb @@ -261,7 +261,9 @@ module GitHub extend self      default_headers = {'User-Agent' => HOMEBREW_USER_AGENT}      default_headers['Authorization'] = "token #{HOMEBREW_GITHUB_API_TOKEN}" if HOMEBREW_GITHUB_API_TOKEN -    Kernel.open(url, default_headers.merge(headers), &block) +    Kernel.open(url, default_headers.merge(headers)) do |f| +      yield Utils::JSON.load(f.read) +    end    rescue OpenURI::HTTPError => e      if e.io.meta['x-ratelimit-remaining'].to_i <= 0        raise <<-EOS.undent @@ -274,11 +276,13 @@ module GitHub extend self      end    rescue SocketError, OpenSSL::SSL::SSLError => e      raise Error, "Failed to connect to: #{url}\n#{e.message}" +  rescue Utils::JSON::Error => e +    raise Error, "Failed to parse JSON response\n#{e.message}"    end    def issues_matching(query)      uri = ISSUES_URI + uri_escape(query) -    open(uri) { |f| Utils::JSON.load(f.read)['issues'] } +    open(uri) { |json| json["issues"] }    end    def uri_escape(query)  | 
