Skip to content
Browse files

Added Yajl as default. Fallback to JSON

  • Loading branch information...
1 parent 584be20 commit 1391cdbcc6339b1f3647e592fcfb66a3ee589b01 @tylercunnion committed Nov 7, 2011
Showing with 16 additions and 6 deletions.
  1. +0 −2 Gemfile
  2. +0 −2 Gemfile.lock
  3. +16 −2 lib/crunchbase/api.rb
View
2 Gemfile
@@ -1,7 +1,5 @@
source "http://rubygems.org"
-gem "json"
-
group :development do
gem "rspec"
gem "bundler", "~> 1.0.0"
View
2 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
View
18 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

0 comments on commit 1391cdb

Please sign in to comment.
Something went wrong with that request. Please try again.