From 51d5c35e3e2c2794cddeb010ce5fda0c05b4bd23 Mon Sep 17 00:00:00 2001 From: David Pitman Date: Tue, 3 Jan 2012 14:55:42 -0700 Subject: [PATCH] Subclasses HTTParyt's Parser to use Crack parsing again for HTTParty 0.8.1 --- Gemfile.lock | 13 ++++++++----- lib/neography/rest.rb | 22 +++++++++++++++++----- neography.gemspec | 3 ++- 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index 8f478aa..0fcd7d5 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,8 +1,9 @@ PATH remote: . specs: - neography (0.0.17) - httparty (= 0.7.8) + neography (0.0.18) + crack (= 0.1.8) + httparty (= 0.8.1) json os rubyzip @@ -12,10 +13,12 @@ GEM specs: crack (0.1.8) diff-lcs (1.1.3) - httparty (0.7.8) - crack (= 0.1.8) + httparty (0.8.1) + multi_json + multi_xml json (1.6.4) - json (1.6.4-java) + multi_json (1.0.4) + multi_xml (0.4.1) net-http-spy (0.2.1) os (0.9.5) rake (0.8.7) diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index df9a2b6..5a818a2 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,6 +1,16 @@ module Neography + class Rest include HTTParty + + class CrackParser < HTTParty::Parser + require 'crack' + + protected + def json + Crack::JSON.parse(body) + end + end attr_accessor :protocol, :server, :port, :directory, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password @@ -14,7 +24,8 @@ def initialize(options={}) :max_threads => Neography::Config.max_threads, :authentication => Neography::Config.authentication, :username => Neography::Config.username, - :password => Neography::Config.password} + :password => Neography::Config.password, + } unless options.respond_to?(:each_pair) url = URI.parse(options) @@ -40,6 +51,7 @@ def initialize(options={}) @max_threads = init[:max_threads] @authentication = Hash.new @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty? + @parser = {:parser => CrackParser} end def configure(protocol, server, port, directory) @@ -381,19 +393,19 @@ def evaluate_response(response) end def get(path,options={}) - evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def post(path,options={}) - evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def put(path,options={}) - evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def delete(path,options={}) - evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication))) + evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) end def get_id(id) diff --git a/neography.gemspec b/neography.gemspec index 6652c13..46b5a7e 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -22,7 +22,8 @@ Gem::Specification.new do |s| s.add_development_dependency "rspec" s.add_development_dependency "net-http-spy", "0.2.1" s.add_development_dependency "rake", "~> 0.8.7" - s.add_dependency "httparty", "0.7.8" + s.add_dependency "crack", "0.1.8" + s.add_dependency "httparty", "0.8.1" s.add_dependency "json" s.add_dependency "os" s.add_dependency "rubyzip"