lib/heroku/api.rb in heroku-api-0.2.7 vs lib/heroku/api.rb in heroku-api-0.2.8

- old
+ new

@@ -7,10 +7,12 @@ __LIB_DIR__ = File.expand_path(File.join(File.dirname(__FILE__), "..")) unless $LOAD_PATH.include?(__LIB_DIR__) $LOAD_PATH.unshift(__LIB_DIR__) end +require "heroku/api/vendor/okjson" + require "heroku/api/errors" require "heroku/api/mock" require "heroku/api/version" require "heroku/api/addons" @@ -30,40 +32,10 @@ srand module Heroku class API - begin - - require('json') - - def self.json_decode(json) - JSON.parse(json) - rescue - json - end - - def self.json_encode(object) - JSON.dump(object) - end - - rescue LoadError - - require('heroku/api/vendor/okjson') - - def self.json_decode(json) - Heroku::API::OkJson.decode(json) - rescue - json - end - - def self.json_encode(object) - Heroku::API::OkJson.encode(object) - end - - end - def initialize(options={}) @api_key = options.delete(:api_key) || ENV['HEROKU_API_KEY'] user_pass = ":#{@api_key}" options = { :headers => {}, @@ -107,10 +79,12 @@ if response.body && !response.body.empty? if response.headers['Content-Encoding'] == 'gzip' response.body = Zlib::GzipReader.new(StringIO.new(response.body)).read end begin - response.body = Heroku::API.json_decode(response.body) + response.body = Heroku::API::OkJson.decode(response.body) + rescue + # leave non-JSON body as is end end # reset (non-persistent) connection @connection.reset