Skip to content

Commit

Permalink
switching httparty to excon
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Jun 5, 2012
1 parent 3540965 commit 2a2333c
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 27 deletions.
5 changes: 1 addition & 4 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
3 changes: 1 addition & 2 deletions 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, :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'
Expand All @@ -15,6 +15,5 @@ class << self; attr_accessor :protocol, :server, :port, :directory, :cypher_path
@authentication = {}
@username = nil
@password = nil
@parser = {:parser => OjParser}
end
end
8 changes: 0 additions & 8 deletions lib/neography/oj_parser.rb

This file was deleted.

20 changes: 8 additions & 12 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand All @@ -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)
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 "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"
Expand Down

0 comments on commit 2a2333c

Please sign in to comment.