Skip to content

Commit

Permalink
Revert "switching httparty to excon"
Browse files Browse the repository at this point in the history
Getting reports of excon causing problems, waiting for failing tests, but holding off since streaming batch still not working.
This reverts commit 2a2333c.
  • Loading branch information
maxdemarzi committed Jun 5, 2012
1 parent 31b4867 commit e4bd60e
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 11 deletions.
5 changes: 4 additions & 1 deletion lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 2 additions & 1 deletion lib/neography/config.rb
Original file line number Diff line number Diff line change
@@ -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'
Expand All @@ -15,5 +15,6 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path
@authentication = {}
@username = nil
@password = nil
@parser = {:parser => OjParser}
end
end
8 changes: 8 additions & 0 deletions lib/neography/oj_parser.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
class OjParser < HTTParty::Parser

protected
def json
#Oj::Doc.parse(body)
Oj.load(body)
end
end
20 changes: 12 additions & 8 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion neography.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit e4bd60e

Please sign in to comment.