Skip to content

Commit

Permalink
A cleaner runtime fix for the JSON issue. Opening the class is pretty…
Browse files Browse the repository at this point in the history
… overkill for the one call this is used for.
  • Loading branch information
Matthew Beale authored and Jack Chen and Dr Nic Williams committed Oct 16, 2009
1 parent 8069551 commit 47aecd1
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions lib/contacts/gmail.rb
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
# Use ActiveSupport's version of JSON if available
if Object.const_defined?('ActiveSupport') && ActiveSupport.const_defined?('JSON')
class JSON
def self.parse(i)
ActiveSupport::JSON.decode(i)
end
end
else
require 'json/add/rails'
end

class Contacts
class Gmail < Base
URL = "https://mail.google.com/mail/"
LOGIN_URL = "https://www.google.com/accounts/ServiceLoginAuth"
LOGIN_REFERER_URL = "https://www.google.com/accounts/ServiceLogin?service=mail&passive=true&rm=false&continue=http%3A%2F%2Fmail.google.com%2Fmail%3Fui%3Dhtml%26zy%3Dl&ltmpl=yj_blanco&ltmplcache=2&hl=en"
CONTACT_LIST_URL = "https://mail.google.com/mail/contacts/data/contacts?thumb=true&show=ALL&enums=true&psort=Name&max=10000&out=js&rf=&jsx=true"
PROTOCOL_ERROR = "Gmail has changed its protocols, please upgrade this library first. If that does not work, dive into the code and submit a patch at http://github.com/cardmagic/contacts"

def self.parse_json( string )
if Object.const_defined?('ActiveSupport') and
ActiveSupport.const_defined?('JSON')
ActiveSupport::JSON.decode( string )
elsif Object.const_defined?('JSON')
JSON.parse( string )
else
raise 'Contacts requires JSON or Rails (with ActiveSupport::JSON)'
end
end

def real_connect
postdata = "ltmpl=yj_blanco"
Expand Down Expand Up @@ -66,7 +66,7 @@ def parse(data, options)
data.gsub!(/\t/, ' ') # tabs in the note field cause errors with JSON.parse
data.gsub!(/[\t\x00-\x1F]/, " ") # strip control characters

@contacts = JSON.parse(data)['Body']['Contacts'] || {}
@contacts = self.class.parse_json(data)['Body']['Contacts'] || {}

# Determine in which format to return the data.

Expand Down

0 comments on commit 47aecd1

Please sign in to comment.