neography 0.0.29 → 0.0.30

Sign up to get free protection for your applications and to get access to all the features.
data/lib/neography.rb CHANGED
@@ -26,6 +26,8 @@ require 'zip/zipfilesystem'
26
26
 
27
27
  require 'neography/multi_json_parser'
28
28
 
29
+ require 'neography/version'
30
+
29
31
  require 'neography/config'
30
32
  require 'neography/rest'
31
33
  require 'neography/neography'
@@ -2,6 +2,7 @@ module Neography
2
2
 
3
3
  class Rest
4
4
  include HTTParty
5
+ USER_AGENT = "Neography/#{Neography::VERSION}"
5
6
 
6
7
  attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser
7
8
 
@@ -48,6 +49,7 @@ module Neography
48
49
  @authentication = Hash.new
49
50
  @authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
50
51
  @parser = init[:parser]
52
+ @user_agent = {"User-Agent" => USER_AGENT}
51
53
  end
52
54
 
53
55
  def configure(protocol, server, port, directory)
@@ -488,6 +490,12 @@ module Neography
488
490
  false
489
491
  end
490
492
  end
493
+
494
+ def merge_options(options)
495
+ merged_options = options.merge!(@authentication).merge!(@parser)
496
+ merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
497
+ merged_options
498
+ end
491
499
 
492
500
  private
493
501
 
@@ -572,19 +580,21 @@ module Neography
572
580
  end
573
581
 
574
582
  def get(path,options={})
575
- evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
583
+ evaluate_response(HTTParty.get(configuration + URI.encode(path), merge_options(options)))
576
584
  end
577
585
 
586
+
587
+
578
588
  def post(path,options={})
579
- evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
589
+ evaluate_response(HTTParty.post(configuration + URI.encode(path), merge_options(options)))
580
590
  end
581
591
 
582
592
  def put(path,options={})
583
- evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
593
+ evaluate_response(HTTParty.put(configuration + URI.encode(path), merge_options(options)))
584
594
  end
585
595
 
586
596
  def delete(path,options={})
587
- evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
597
+ evaluate_response(HTTParty.delete(configuration + URI.encode(path), merge_options(options)))
588
598
  end
589
599
 
590
600
  def get_id(id)
@@ -1,3 +1,3 @@
1
1
  module Neography
2
- VERSION = "0.0.29"
2
+ VERSION = "0.0.30"
3
3
  end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
+
3
+ describe Neography::Rest do
4
+ before(:each) do
5
+ @neo = Neography::Rest.new
6
+ end
7
+
8
+ it "should not add a content-type header if there's no existing headers" do
9
+ @neo.merge_options({}).keys.should == [:parser]
10
+ end
11
+
12
+ it "should add a content type if there's existing headers" do
13
+ @neo.merge_options({:headers => {'Content-Type' => 'foo/bar'}})[:headers].should ==
14
+ {'Content-Type' => "foo/bar", "User-Agent" => "Neography/#{Neography::VERSION}"}
15
+
16
+ end
17
+
18
+
19
+ end
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: 0.0.29
4
+ version: 0.0.30
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: 2012-08-07 00:00:00.000000000 Z
12
+ date: 2012-08-24 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -210,6 +210,7 @@ files:
210
210
  - spec/integration/rest_bulk_spec.rb
211
211
  - spec/integration/rest_experimental_spec.rb
212
212
  - spec/integration/rest_gremlin_fail_spec.rb
213
+ - spec/integration/rest_header_spec.rb
213
214
  - spec/integration/rest_index_spec.rb
214
215
  - spec/integration/rest_node_spec.rb
215
216
  - spec/integration/rest_path_spec.rb
@@ -254,6 +255,7 @@ test_files:
254
255
  - spec/integration/rest_bulk_spec.rb
255
256
  - spec/integration/rest_experimental_spec.rb
256
257
  - spec/integration/rest_gremlin_fail_spec.rb
258
+ - spec/integration/rest_header_spec.rb
257
259
  - spec/integration/rest_index_spec.rb
258
260
  - spec/integration/rest_node_spec.rb
259
261
  - spec/integration/rest_path_spec.rb