From 2a2333cccd3807065483431b0e3b6bdac3229c76 Mon Sep 17 00:00:00 2001 From: Max De Marzi Date: Mon, 4 Jun 2012 21:59:29 -0500 Subject: [PATCH] switching httparty to excon --- lib/neography.rb | 5 +---- lib/neography/config.rb | 3 +-- lib/neography/oj_parser.rb | 8 -------- lib/neography/rest.rb | 20 ++++++++------------ neography.gemspec | 2 +- 5 files changed, 11 insertions(+), 27 deletions(-) delete mode 100644 lib/neography/oj_parser.rb diff --git a/lib/neography.rb b/lib/neography.rb index 24b136a..fbe0302 100644 --- a/lib/neography.rb +++ b/lib/neography.rb @@ -16,17 +16,14 @@ def find_and_require_user_defined_code DIRECTIONS = ["incoming", "in", "outgoing", "out", "all", "both"] require 'cgi' -require 'crack' -require 'httparty' require 'json' +require 'excon' require 'oj' require 'logger' require 'ostruct' require 'os' require 'zip/zipfilesystem' -require 'neography/oj_parser' - require 'neography/config' require 'neography/rest' require 'neography/neography' diff --git a/lib/neography/config.rb b/lib/neography/config.rb index c59c529..efebf0f 100644 --- a/lib/neography/config.rb +++ b/lib/neography/config.rb @@ -1,6 +1,6 @@ module Neography class Config - class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end + class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password end @protocol = 'http://' @server = 'localhost' @@ -15,6 +15,5 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path @authentication = {} @username = nil @password = nil - @parser = {:parser => OjParser} end end \ No newline at end of file diff --git a/lib/neography/oj_parser.rb b/lib/neography/oj_parser.rb deleted file mode 100644 index 94ebd82..0000000 --- a/lib/neography/oj_parser.rb +++ /dev/null @@ -1,8 +0,0 @@ -class OjParser < HTTParty::Parser - - protected - def json - #Oj::Doc.parse(body) - Oj.load(body) - end -end \ No newline at end of file diff --git a/lib/neography/rest.rb b/lib/neography/rest.rb index da7fb4b..60b6708 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,9 +1,8 @@ module Neography class Rest - include HTTParty - attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser + attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password def initialize(options=ENV['NEO4J_URL'] || {}) init = {:protocol => Neography::Config.protocol, @@ -18,7 +17,6 @@ def initialize(options=ENV['NEO4J_URL'] || {}) :authentication => Neography::Config.authentication, :username => Neography::Config.username, :password => Neography::Config.password, - :parser => Neography::Config.parser } unless options.respond_to?(:each_pair) @@ -47,7 +45,6 @@ def initialize(options=ENV['NEO4J_URL'] || {}) @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 = init[:parser] end def configure(protocol, server, port, directory) @@ -479,15 +476,14 @@ def get_batch(args) end def evaluate_response(response) - code = response.code - body = response.body + code = response.status case code when 200 @logger.debug "OK" if @log_enabled - response.parsed_response + Oj.load(response.body) when 201 @logger.debug "OK, created #{body}" if @log_enabled - response.parsed_response + Oj.load(response.body) when 204 @logger.debug "OK, no content returned" if @log_enabled nil @@ -504,19 +500,19 @@ def evaluate_response(response) end def get(path,options={}) - evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) + evaluate_response(Excon.get(configuration + URI.encode(path), options.merge!(@authentication))) end def post(path,options={}) - evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) + evaluate_response(Excon.post(configuration + URI.encode(path), options.merge!(@authentication))) end def put(path,options={}) - evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) + evaluate_response(Excon.put(configuration + URI.encode(path), options.merge!(@authentication))) end def delete(path,options={}) - evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser))) + evaluate_response(Excon.delete(configuration + URI.encode(path), options.merge!(@authentication))) end def get_id(id) diff --git a/neography.gemspec b/neography.gemspec index a70427c..c277302 100644 --- a/neography.gemspec +++ b/neography.gemspec @@ -22,7 +22,7 @@ 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.8.1" + s.add_dependency "excon", ">= 0.14.0" s.add_dependency "rake", ">= 0.8.7" s.add_dependency "json" s.add_dependency "os"