diff --git a/Gemfile b/Gemfile index 4c931b7..a10dcf4 100644 --- a/Gemfile +++ b/Gemfile @@ -1,7 +1,5 @@ source "http://rubygems.org" -gem "json" - group :development do gem "rspec" gem "bundler", "~> 1.0.0" diff --git a/Gemfile.lock b/Gemfile.lock index 775e332..9b1f54c 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -7,7 +7,6 @@ GEM bundler (~> 1.0) git (>= 1.2.5) rake - json (1.5.4) rake (0.9.2) rcov (0.9.10) rdoc (3.9.4) @@ -26,7 +25,6 @@ PLATFORMS DEPENDENCIES bundler (~> 1.0.0) jeweler (~> 1.6.4) - json rcov rdoc rspec diff --git a/lib/crunchbase/api.rb b/lib/crunchbase/api.rb index 27736e2..5e07dac 100644 --- a/lib/crunchbase/api.rb +++ b/lib/crunchbase/api.rb @@ -1,5 +1,11 @@ require 'net/http' -require 'json' + +begin + require 'yajl' +rescue LoadError + require 'json' +end + require 'timeout' module Crunchbase @@ -40,11 +46,19 @@ def self.fetch(permalink, object_name) resp = Timeout::timeout(5) { Net::HTTP.get(uri) } - j = JSON.parse(resp) + j = parser.parse(resp) raise CrunchException, j["error"] if j["error"] return j end + def self.parser + if defined?(Yajl) + Yajl::Parser + else + JSON + end + end + end end