diff --git a/lib/neography.rb b/lib/neography.rb index fbe0302..24b136a 100644 --- a/lib/neography.rb +++ b/lib/neography.rb @@ -16,14 +16,17 @@ 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 efebf0f..c59c529 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 end + class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser end @protocol = 'http://' @server = 'localhost' @@ -15,5 +15,6 @@ 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 new file mode 100644 index 0000000..94ebd82 --- /dev/null +++ b/lib/neography/oj_parser.rb @@ -0,0 +1,8 @@ +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 60b6708..da7fb4b 100644 --- a/lib/neography/rest.rb +++ b/lib/neography/rest.rb @@ -1,8 +1,9 @@ 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 + attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser def initialize(options=ENV['NEO4J_URL'] || {}) init = {:protocol => Neography::Config.protocol, @@ -17,6 +18,7 @@ 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) @@ -45,6 +47,7 @@ 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) @@ -476,14 +479,15 @@ def get_batch(args) end def evaluate_response(response) - code = response.status + code = response.code + body = response.body case code when 200 @logger.debug "OK" if @log_enabled - Oj.load(response.body) + response.parsed_response when 201 @logger.debug "OK, created #{body}" if @log_enabled - Oj.load(response.body) + response.parsed_response when 204 @logger.debug "OK, no content returned" if @log_enabled nil @@ -500,19 +504,19 @@ def evaluate_response(response) end def get(path,options={}) - evaluate_response(Excon.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(Excon.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(Excon.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(Excon.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 c277302..a70427c 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 "excon", ">= 0.14.0" + s.add_dependency "httparty", "0.8.1" s.add_dependency "rake", ">= 0.8.7" s.add_dependency "json" s.add_dependency "os"