added basic json parser support and tests

git-svn-id: https://google-api-ruby-client.googlecode.com/svn/trunk@23 c1d61fac-ed7f-fcc1-18f7-ff78120a04ef
This commit is contained in:
mattpok@google.com committed 2010-08-23 22:07:50 +00:00
1 parent bc844db311
commit 1b232831c4
2 files changed
+58

No files matched your search

@@ -16,8 +16,27 @@ require 'json'
module Google #:nodoc:
class APIClient #:nodoc:
##
# Provides a consistent interface by which to parse request and response
# content.
# TODO(mattpok): ensure floats, URLs, dates are parsed correctly
class JSONParser
def generate(hash)
# JSON parser used can accept arrays as well, but we will limit
# to only allow hash to JSON string parsing to keep a simple interface
unless hash.instance_of? Hash
raise ArgumentError,
"JSON generate expected a Hash but got a #{hash.class}."
end
return JSON.generate hash
end
def parse(json_string)
return JSON.parse json_string
end
end
end
end