neography 1.0.8 → 1.0.9

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
+ coverage
2
+ .DS_Store
1
3
  Gemfile.lock
2
4
  .idea
3
5
  *.iml
data/README.md CHANGED
@@ -1,5 +1,10 @@
1
- [![Build Status](https://secure.travis-ci.org/maxdemarzi/neography.png?branch=master)](http://travis-ci.org/maxdemarzi/neography)
2
- [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/maxdemarzi/neography)
1
+ Neography
2
+ =========
3
+
4
+ - [![Gem Version](https://badge.fury.io/rb/neography.png)](https://rubygems.org/gems/neography)
5
+ - [![Build Status](https://secure.travis-ci.org/maxdemarzi/neography.png?branch=master)](http://travis-ci.org/maxdemarzi/neography)
6
+ - [![Code Climate](https://codeclimate.com/badge.png)](https://codeclimate.com/github/maxdemarzi/neography)
7
+ - [![Coverage Status](https://coveralls.io/repos/maxdemarzi/neography/badge.png?branch=master)](https://coveralls.io/r/maxdemarzi/neography)
3
8
 
4
9
  ## Welcome to Neography
5
10
 
data/lib/neography.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  require 'cgi'
2
- require 'httparty'
2
+ require 'httpclient'
3
3
  require 'json'
4
4
  require 'multi_json'
5
5
  require 'logger'
@@ -45,7 +45,7 @@ module Neography
45
45
  @authentication = nil
46
46
  @username = nil
47
47
  @password = nil
48
- @parser = {:parser => MultiJsonParser}
48
+ @parser = MultiJsonParser
49
49
  end
50
50
 
51
51
  end
@@ -1,6 +1,5 @@
1
1
  module Neography
2
2
  class Connection
3
-
4
3
  USER_AGENT = "Neography/#{Neography::VERSION}"
5
4
 
6
5
  attr_accessor :protocol, :server, :port, :directory,
@@ -8,11 +7,12 @@ module Neography
8
7
  :log_file, :log_enabled, :logger,
9
8
  :max_threads,
10
9
  :authentication, :username, :password,
11
- :parser
10
+ :parser, :client
12
11
 
13
12
  def initialize(options = ENV['NEO4J_URL'] || {})
14
13
  config = merge_configuration(options)
15
14
  save_local_configuration(config)
15
+ @client = HTTPClient.new
16
16
  end
17
17
 
18
18
  def configure(protocol, server, port, directory)
@@ -27,27 +27,37 @@ module Neography
27
27
  end
28
28
 
29
29
  def merge_options(options)
30
- merged_options = options.merge!(@authentication).merge!(@parser)
30
+ merged_options = options.merge!(@authentication)#.merge!(@parser)
31
31
  merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
32
32
  merged_options
33
33
  end
34
34
 
35
35
  def get(path, options={})
36
- evaluate_response(HTTParty.get(configuration + path, merge_options(options)))
36
+ authenticate(configuration + path)
37
+ evaluate_response(@client.get(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
37
38
  end
38
39
 
39
40
  def post(path, options={})
40
- evaluate_response(HTTParty.post(configuration + path, merge_options(options)))
41
+ authenticate(configuration + path)
42
+ evaluate_response(@client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
41
43
  end
42
44
 
43
45
  def put(path, options={})
44
- evaluate_response(HTTParty.put(configuration + path, merge_options(options)))
46
+ authenticate(configuration + path)
47
+ evaluate_response(@client.put(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
45
48
  end
46
49
 
47
50
  def delete(path, options={})
48
- evaluate_response(HTTParty.delete(configuration + path, merge_options(options)))
51
+ authenticate(configuration + path)
52
+ evaluate_response(@client.delete(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
49
53
  end
50
54
 
55
+ def authenticate(path)
56
+ @client.set_auth(path,
57
+ @authentication[@authentication.keys.first][:username],
58
+ @authentication[@authentication.keys.first][:password]) unless @authentication.empty?
59
+ end
60
+
51
61
  private
52
62
 
53
63
  def merge_configuration(options)
@@ -91,10 +101,10 @@ module Neography
91
101
  case code
92
102
  when 200
93
103
  @logger.debug "OK" if @log_enabled
94
- response.parsed_response
104
+ @parser.json(body) #response.parsed_response
95
105
  when 201
96
106
  @logger.debug "OK, created #{body}" if @log_enabled
97
- response.parsed_response
107
+ @parser.json(body) #response.parsed_response
98
108
  when 204
99
109
  @logger.debug "OK, no content returned" if @log_enabled
100
110
  nil
@@ -110,7 +120,7 @@ module Neography
110
120
  message = "No error message returned from server."
111
121
  stacktrace = ""
112
122
  else
113
- parsed_body = JSON.parse(body)
123
+ parsed_body = @parser.json(body)
114
124
  message = parsed_body["message"]
115
125
  stacktrace = parsed_body["stacktrace"]
116
126
  end
@@ -1,6 +1,5 @@
1
- class MultiJsonParser < HTTParty::Parser
1
+ class MultiJsonParser
2
2
 
3
- protected
4
3
 
5
4
  # I know this looks pretty ugly, but we have issues with Neo4j returning true, false,
6
5
  # plain numbers and plain strings, which is considered by some JSON libraries to be
@@ -8,7 +7,7 @@ class MultiJsonParser < HTTParty::Parser
8
7
  # This ugly hack deals with the problem. Send me a Pull Request if you
9
8
  # come up with a nicer solution... please!
10
9
  #
11
- def json
10
+ def self.json(body)
12
11
  begin
13
12
  MultiJson.load(body)
14
13
  rescue MultiJson::DecodeError, ArgumentError
@@ -31,7 +31,6 @@ require 'neography/connection'
31
31
  module Neography
32
32
 
33
33
  class Rest
34
- include HTTParty
35
34
  include Helpers
36
35
  extend Forwardable
37
36
 
@@ -1,6 +1,6 @@
1
1
  # borrowed from architect4r
2
2
  require 'os'
3
- require 'httparty'
3
+ require 'httpclient'
4
4
  require 'zip/zip'
5
5
 
6
6
  namespace :neo4j do
@@ -14,7 +14,7 @@ namespace :neo4j do
14
14
  unless File.exist?('neo4j.zip')
15
15
  df = File.open('neo4j.zip', 'wb')
16
16
  begin
17
- df << HTTParty.get("http://dist.neo4j.org/neo4j-#{args[:edition]}-#{args[:version]}-windows.zip")
17
+ df << HTTPClient.new.get("http://dist.neo4j.org/neo4j-#{args[:edition]}-#{args[:version]}-windows.zip")
18
18
  ensure
19
19
  df.close()
20
20
  end
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "1.0.8"
2
+ VERSION = "1.0.9"
3
3
  end
data/neography.gemspec CHANGED
@@ -22,7 +22,8 @@ Gem::Specification.new do |s|
22
22
  s.add_development_dependency "rspec", ">= 2.11"
23
23
  s.add_development_dependency "net-http-spy", "0.2.1"
24
24
  s.add_development_dependency "rake", ">= 0.8.7"
25
- s.add_dependency "httparty", ">= 0.8.1"
25
+ s.add_development_dependency "coveralls"
26
+ s.add_dependency "httpclient", ">= 2.3.3"
26
27
  s.add_dependency "rake", ">= 0.8.7"
27
28
  s.add_dependency "json", ">= 1.6.0"
28
29
  s.add_dependency "os", ">= 0.9.6"
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  describe Neography::Connection do
4
4
 
5
5
  it "should not add a content-type header if there's no existing headers" do
6
- subject.merge_options({}).keys.should == [:parser]
6
+ subject.merge_options({}).keys.should == []
7
7
  end
8
8
 
9
9
  it "should add a content type if there's existing headers" do
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  require 'neography'
2
2
  require 'benchmark'
3
3
  require 'matchers'
4
+ require 'coveralls'
5
+ Coveralls.wear!
4
6
 
5
7
  # If you want to see more, uncomment the next few lines
6
8
  # require 'net-http-spy'
@@ -19,7 +19,7 @@ module Neography
19
19
  its(:authentication) { should == nil }
20
20
  its(:username) { should == nil }
21
21
  its(:password) { should == nil }
22
- its(:parser) { should == { :parser => MultiJsonParser } }
22
+ its(:parser) { should == MultiJsonParser}
23
23
 
24
24
  it "has a hash representation" do
25
25
  expected_hash = {
@@ -35,7 +35,7 @@ module Neography
35
35
  :authentication => nil,
36
36
  :username => nil,
37
37
  :password => nil,
38
- :parser => { :parser => MultiJsonParser }
38
+ :parser => MultiJsonParser
39
39
  }
40
40
  config.to_hash.should == expected_hash
41
41
  end
@@ -78,22 +78,22 @@ module Neography
78
78
  context "requests" do
79
79
 
80
80
  it "does a GET request" do
81
- HTTParty.should_receive(:get).with("http://localhost:7474/db/data/foo/bar", { :parser => MultiJsonParser }) { stub.as_null_object }
81
+ connection.client.should_receive(:get).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
82
82
  connection.get("/foo/bar")
83
83
  end
84
84
 
85
85
  it "does a POST request" do
86
- HTTParty.should_receive(:post).with("http://localhost:7474/db/data/foo/bar", { :parser => MultiJsonParser }) { stub.as_null_object }
86
+ connection.client.should_receive(:post).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
87
87
  connection.post("/foo/bar")
88
88
  end
89
89
 
90
90
  it "does a PUT request" do
91
- HTTParty.should_receive(:put).with("http://localhost:7474/db/data/foo/bar", { :parser => MultiJsonParser }) { stub.as_null_object }
91
+ connection.client.should_receive(:put).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
92
92
  connection.put("/foo/bar")
93
93
  end
94
94
 
95
95
  it "does a DELETE request" do
96
- HTTParty.should_receive(:delete).with("http://localhost:7474/db/data/foo/bar", { :parser => MultiJsonParser }) { stub.as_null_object }
96
+ connection.client.should_receive(:delete).with("http://localhost:7474/db/data/foo/bar", nil, nil) { stub.as_null_object }
97
97
  connection.delete("/foo/bar")
98
98
  end
99
99
 
@@ -107,25 +107,24 @@ module Neography
107
107
  end
108
108
 
109
109
  it "does requests with authentication" do
110
- HTTParty.should_receive(:get).with(
110
+ connection.client.should_receive(:set_auth).with(
111
111
  "http://localhost:7474/db/data/foo/bar",
112
- { :parser => MultiJsonParser,
113
- :basic_auth => {
114
- :username => "foo",
115
- :password => "bar"
116
- }
117
- }) { stub.as_null_object }
112
+ "foo",
113
+ "bar") { stub.as_null_object }
114
+
115
+ connection.client.should_receive(:get).with(
116
+ "http://localhost:7474/db/data/foo/bar", nil, nil
117
+ ) { stub.as_null_object }
118
118
 
119
119
  connection.get("/foo/bar")
120
120
  end
121
121
  end
122
122
 
123
123
  it "adds the User-Agent to the headers" do
124
- HTTParty.should_receive(:get).with(
124
+ connection.client.should_receive(:get).with(
125
125
  "http://localhost:7474/db/data/foo/bar",
126
- { :parser => MultiJsonParser,
127
- :headers => { "User-Agent" => "Neography/#{Neography::VERSION}" }
128
- }) { stub.as_null_object }
126
+ nil, { "User-Agent" => "Neography/#{Neography::VERSION}" }
127
+ ) { stub.as_null_object }
129
128
 
130
129
  connection.get("/foo/bar", :headers => {})
131
130
  end
@@ -134,7 +133,7 @@ module Neography
134
133
 
135
134
  it "raises NodeNotFoundException" do
136
135
  response = error_response(code: 404, message: "a message", exception: "NodeNotFoundException")
137
- HTTParty.stub(:get).and_return(response)
136
+ connection.client.stub(:get).and_return(response)
138
137
  expect {
139
138
  connection.get("/foo/bar")
140
139
  }.to raise_error NodeNotFoundException
@@ -142,7 +141,7 @@ module Neography
142
141
 
143
142
  it "raises OperationFailureException" do
144
143
  response = error_response(code: 409, message: "a message", exception: "OperationFailureException")
145
- HTTParty.stub(:get).and_return(response)
144
+ connection.client.stub(:get).and_return(response)
146
145
  expect {
147
146
  connection.get("/foo/bar")
148
147
  }.to raise_error OperationFailureException
@@ -150,7 +149,7 @@ module Neography
150
149
 
151
150
  it "raises PropertyValueException" do
152
151
  response = error_response(code: 400, message: "a message", exception: "PropertyValueException")
153
- HTTParty.stub(:get).and_return(response)
152
+ connection.client.stub(:get).and_return(response)
154
153
  expect {
155
154
  connection.get("/foo/bar")
156
155
  }.to raise_error PropertyValueException
@@ -158,7 +157,7 @@ module Neography
158
157
 
159
158
  it "raises NoSuchPropertyException" do
160
159
  response = error_response(code: 404, message: "a message", exception: "NoSuchPropertyException")
161
- HTTParty.stub(:get).and_return(response)
160
+ connection.client.stub(:get).and_return(response)
162
161
  expect {
163
162
  connection.get("/foo/bar")
164
163
  }.to raise_error NoSuchPropertyException
@@ -166,7 +165,7 @@ module Neography
166
165
 
167
166
  it "raises RelationshipNotFoundException" do
168
167
  response = error_response(code: 404, message: "a message", exception: "RelationshipNotFoundException")
169
- HTTParty.stub(:get).and_return(response)
168
+ connection.client.stub(:get).and_return(response)
170
169
  expect {
171
170
  connection.get("/foo/bar")
172
171
  }.to raise_error RelationshipNotFoundException
@@ -174,7 +173,7 @@ module Neography
174
173
 
175
174
  it "raises BadInputException" do
176
175
  response = error_response(code: 400, message: "a message", exception: "BadInputException")
177
- HTTParty.stub(:get).and_return(response)
176
+ connection.client.stub(:get).and_return(response)
178
177
  expect {
179
178
  connection.get("/foo/bar")
180
179
  }.to raise_error BadInputException
@@ -182,7 +181,7 @@ module Neography
182
181
 
183
182
  it "raises UnauthorizedError" do
184
183
  response = error_response(code: 401)
185
- HTTParty.stub(:get).and_return(response)
184
+ connection.client.stub(:get).and_return(response)
186
185
  expect {
187
186
  connection.get("/foo/bar")
188
187
  }.to raise_error UnauthorizedError
@@ -190,7 +189,7 @@ module Neography
190
189
 
191
190
  it "raises NeographyError in all other cases" do
192
191
  response = error_response(code: 418, message: "I'm a teapot.")
193
- HTTParty.stub(:get).and_return(response)
192
+ connection.client.stub(:get).and_return(response)
194
193
  expect {
195
194
  connection.get("/foo/bar")
196
195
  }.to raise_error NeographyError
@@ -198,7 +197,7 @@ module Neography
198
197
 
199
198
  it "raises BadInputException" do
200
199
  response = error_response(code: 500, message: "a message", exception: "JsonParseException")
201
- HTTParty.stub(:get).and_return(response)
200
+ connection.client.stub(:get).and_return(response)
202
201
  expect {
203
202
  connection.get("/foo/bar")
204
203
  }.to raise_error NeographyError
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: neography
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.8
4
+ version: 1.0.9
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-03-15 00:00:00.000000000 Z
12
+ date: 2013-03-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -60,13 +60,29 @@ dependencies:
60
60
  - !ruby/object:Gem::Version
61
61
  version: 0.8.7
62
62
  - !ruby/object:Gem::Dependency
63
- name: httparty
63
+ name: coveralls
64
64
  requirement: !ruby/object:Gem::Requirement
65
65
  none: false
66
66
  requirements:
67
67
  - - ! '>='
68
68
  - !ruby/object:Gem::Version
69
- version: 0.8.1
69
+ version: '0'
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
79
+ name: httpclient
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 2.3.3
70
86
  type: :runtime
71
87
  prerelease: false
72
88
  version_requirements: !ruby/object:Gem::Requirement
@@ -74,7 +90,7 @@ dependencies:
74
90
  requirements:
75
91
  - - ! '>='
76
92
  - !ruby/object:Gem::Version
77
- version: 0.8.1
93
+ version: 2.3.3
78
94
  - !ruby/object:Gem::Dependency
79
95
  name: rake
80
96
  requirement: !ruby/object:Gem::Requirement