lib/hn/request.rb in hn_api-0.0.1 vs lib/hn/request.rb in hn_api-0.0.2

- old
+ new

@@ -1,5 +1,8 @@ +require 'json' +require 'hashie' + module HN module Request def get(path, options = {}) request(:get, path, options) end @@ -8,9 +11,14 @@ def request(method, path, options) response = connection.send(method) do |request| request.url(path, options) end - response.body + prepare(response) + end + + def prepare(response) + result = JSON.parse(response.body) rescue response.body + result.is_a?(Hash) ? Hashie::Mash.new(result) : result end end end \ No newline at end of file