Skip to content

Commit

Permalink
Subclasses HTTParyt's Parser to use Crack parsing again for HTTParty …
Browse files Browse the repository at this point in the history
…0.8.1
  • Loading branch information
David Pitman committed Jan 3, 2012
1 parent 8c1ce42 commit 51d5c35
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
13 changes: 8 additions & 5 deletions 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
Expand All @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions 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

Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion neography.gemspec
Expand Up @@ -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"
Expand Down

0 comments on commit 51d5c35

Please sign in to comment.