diff options
| author | Mike McQuaid | 2016-11-21 18:45:20 +0000 |
|---|---|---|
| committer | GitHub | 2016-11-21 18:45:20 +0000 |
| commit | c3f959d6af36f075600aac63f208d59c30cd602c (patch) | |
| tree | 336233a927c2be8b69f74dd704b73b3293d6ac33 /Library/Homebrew/utils | |
| parent | c7267b123d38d1c96c2ca786c942255d2417cd86 (diff) | |
| parent | d07b9ed7f2e8806b1840b4f60605ef45487655e1 (diff) | |
| download | brew-c3f959d6af36f075600aac63f208d59c30cd602c.tar.bz2 | |
Merge pull request #1542 from woodruffw/deprecate-utils-json
compat: deprecate Utils::JSON in favor of corelib JSON.
Diffstat (limited to 'Library/Homebrew/utils')
| -rw-r--r-- | Library/Homebrew/utils/github.rb | 12 | ||||
| -rw-r--r-- | Library/Homebrew/utils/json.rb | 34 |
2 files changed, 6 insertions, 40 deletions
diff --git a/Library/Homebrew/utils/github.rb b/Library/Homebrew/utils/github.rb index 43a0e88a8..5f961974c 100644 --- a/Library/Homebrew/utils/github.rb +++ b/Library/Homebrew/utils/github.rb @@ -149,9 +149,9 @@ module GitHub data_tmpfile = nil if data begin - data = Utils::JSON.dump data + data = JSON.generate data data_tmpfile = Tempfile.new("github_api_post", HOMEBREW_TEMP) - rescue Utils::JSON::Error => e + rescue JSON::ParserError => e raise Error, "Failed to parse JSON request:\n#{e.message}\n#{data}", e.backtrace end end @@ -183,13 +183,13 @@ module GitHub if !http_code.start_with?("2") && !status.success? raise_api_error(output, errors, http_code, headers, scopes) end - json = Utils::JSON.load output + json = JSON.parse output if block_given? yield json else json end - rescue Utils::JSON::Error => e + rescue JSON::ParserError => e raise Error, "Failed to parse JSON response\n#{e.message}", e.backtrace end end @@ -205,7 +205,7 @@ module GitHub if meta.fetch("x-ratelimit-remaining", 1).to_i <= 0 reset = meta.fetch("x-ratelimit-reset").to_i - error = Utils::JSON.load(output)["message"] + error = JSON.parse(output)["message"] raise RateLimitExceededError.new(reset, error) end @@ -218,7 +218,7 @@ module GitHub raise HTTPNotFoundError, output else error = begin - Utils::JSON.load(output)["message"] + JSON.parse(output)["message"] rescue nil end diff --git a/Library/Homebrew/utils/json.rb b/Library/Homebrew/utils/json.rb deleted file mode 100644 index 21c5b52b0..000000000 --- a/Library/Homebrew/utils/json.rb +++ /dev/null @@ -1,34 +0,0 @@ -require "json" - -module Utils - module JSON - module_function - - Error = Class.new(StandardError) - - def load(str) - ::JSON.load(str) - rescue ::JSON::ParserError => e - raise Error, e.message - end - - def dump(obj) - ::JSON.generate(obj) - end - - def stringify_keys(obj) - case obj - when Array - obj.map { |val| stringify_keys(val) } - when Hash - obj.inject({}) do |result, (key, val)| - key = key.respond_to?(:to_s) ? key.to_s : key - val = stringify_keys(val) - result.merge!(key => val) - end - else - obj - end - end - end -end |
