Skip to content

Commit

Permalink
Added Yajl as default. Fallback to JSON
Browse files Browse the repository at this point in the history
  • Loading branch information
tylercunnion committed Nov 7, 2011
1 parent 584be20 commit 1391cdb
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 6 deletions.
2 changes: 0 additions & 2 deletions Gemfile
@@ -1,7 +1,5 @@
source "http://rubygems.org"

gem "json"

group :development do
gem "rspec"
gem "bundler", "~> 1.0.0"
Expand Down
2 changes: 0 additions & 2 deletions Gemfile.lock
Expand Up @@ -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)
Expand All @@ -26,7 +25,6 @@ PLATFORMS
DEPENDENCIES
bundler (~> 1.0.0)
jeweler (~> 1.6.4)
json
rcov
rdoc
rspec
18 changes: 16 additions & 2 deletions 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
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 1391cdb

Please sign in to comment.