2009-04-22 19:48:58 -04:00
|
|
|
require 'active_support/json'
|
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
module ActiveResource
|
|
|
|
module Formats
|
|
|
|
module JsonFormat
|
|
|
|
extend self
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def extension
|
|
|
|
"json"
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def mime_type
|
|
|
|
"application/json"
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2009-06-08 22:30:27 -04:00
|
|
|
def encode(hash, options = nil)
|
|
|
|
ActiveSupport::JSON.encode(hash, options)
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
|
2007-09-20 19:18:05 -04:00
|
|
|
def decode(json)
|
2011-05-17 19:30:43 -04:00
|
|
|
Formats.remove_root(ActiveSupport::JSON.decode(json))
|
2007-09-20 19:18:05 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2008-08-29 21:19:18 -04:00
|
|
|
end
|