From c18f02460370b83191f0ad07e3da3e4f37ba741f Mon Sep 17 00:00:00 2001 From: wynst Date: Mon, 22 Feb 2010 00:48:19 +0700 Subject: [PATCH] Dynamically load json library (add compatibility with appengine-jruby) --- lib/sinbook.rb | 17 ++++++++++++++--- sinbook.gemspec | 3 +-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/sinbook.rb b/lib/sinbook.rb index b47a43d..b2aae97 100644 --- a/lib/sinbook.rb +++ b/lib/sinbook.rb @@ -11,7 +11,6 @@ class FacebookError < StandardError module Sinatra require 'digest/md5' - require 'yajl' class FacebookObject def initialize app @@ -200,10 +199,22 @@ def request method, opts = {} "#{k}=" + case v when Hash - Yajl::Encoder.encode(v) + if Object.const_defined?("Yajl") && Yajl.const_defined?("Encoder") + Yajl::Encoder.encode(v) + elsif Object.const_defined("JSON") + JSON.generate(v) + else + throw "you need to require either 'yajl' or 'json' for sinbook to work" + end when Array if k == :tags - Yajl::Encoder.encode(v) + if Object.const_defined?("Yajl") && Yajl.const_defined?("Encoder") + Yajl::Encoder.encode(v) + elsif Object.const_defined("JSON") + JSON.generate(v) + else + throw "you need to require either 'yajl' or 'json' for sinbook to work" + end else v.join(',') end diff --git a/sinbook.gemspec b/sinbook.gemspec index 991c300..4f88c9f 100644 --- a/sinbook.gemspec +++ b/sinbook.gemspec @@ -1,6 +1,6 @@ spec = Gem::Specification.new do |s| s.name = 'sinbook' - s.version = '0.1.9' + s.version = '0.1.9.aej' s.date = '2010-02-04' s.summary = 'simple sinatra facebook extension in 300 lines of ruby' s.description = 'A full-featured facebook extension for the sinatra webapp framework' @@ -10,7 +10,6 @@ spec = Gem::Specification.new do |s| s.authors = ["Aman Gupta"] s.email = "aman@tmm1.net" - s.add_dependency('yajl-ruby') s.has_rdoc = false # ruby -rpp -e' pp `git ls-files | grep -v examples`.split("\n") '