Skip to content

Commit

Permalink
Added option to force use of JSON gem even if ActiveSupport::JSON is …
Browse files Browse the repository at this point in the history
…present, in a backwards-compatible way.
  • Loading branch information
Jordan Brough committed Mar 31, 2009
1 parent 77c2475 commit 7e69503
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/contacts/yahoo.rb
Expand Up @@ -6,7 +6,6 @@
require 'net/https'
require 'uri'
require 'yaml'
require 'json' unless defined? ActiveSupport::JSON

module Contacts
# = How I can fetch Yahoo Contacts?
Expand Down Expand Up @@ -105,12 +104,12 @@ def get_authentication_url
# * path <String>:: The path of the redirect request that Yahoo sent to you
# after authenticating the user
#
def contacts(path)
def contacts(path, force_json_gem=false)
validate_signature(path)
credentials = access_user_credentials()
parse_credentials(credentials)
contacts_json = access_address_book_api()
Yahoo.parse_contacts(contacts_json)
Yahoo.parse_contacts(contacts_json, force_json_gem)
end

# This method processes and validates the redirect request that Yahoo send to
Expand Down Expand Up @@ -206,11 +205,12 @@ def access_address_book_api
# ==== Parameters
# * json <String>:: A String of user's contacts in JSON format
#
def self.parse_contacts(json)
def self.parse_contacts(json, force_json_gem=false)
contacts = []
people = if defined? ActiveSupport::JSON
people = if !force_json_gem && defined? ActiveSupport::JSON
ActiveSupport::JSON.decode(json)
else
require 'json'
JSON.parse(json)
end

Expand Down

0 comments on commit 7e69503

Please sign in to comment.