Skip to content

Commit

Permalink
Add User-Agent header.
Browse files Browse the repository at this point in the history
  • Loading branch information
simpsonjulian committed Aug 14, 2012
1 parent 65f6ca9 commit a871d00
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/neography.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def find_and_require_user_defined_code

require 'neography/oj_parser'

require 'neography/version'

require 'neography/config'
require 'neography/rest'
require 'neography/neography'
Expand Down
18 changes: 14 additions & 4 deletions lib/neography/rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ module Neography

class Rest
include HTTParty
USER_AGENT = "Neography/#{Neography::VERSION}"

attr_accessor :protocol, :server, :port, :directory, :cypher_path, :gremlin_path, :log_file, :log_enabled, :logger, :max_threads, :authentication, :username, :password, :parser

Expand Down Expand Up @@ -48,6 +49,7 @@ def initialize(options=ENV['NEO4J_URL'] || {})
@authentication = Hash.new
@authentication = {"#{init[:authentication]}_auth".to_sym => {:username => init[:username], :password => init[:password]}} unless init[:authentication].empty?
@parser = init[:parser]
@user_agent = {"User-Agent" => USER_AGENT}
end

def configure(protocol, server, port, directory)
Expand Down Expand Up @@ -569,20 +571,28 @@ def evaluate_response(response)
end
end

def merge_options(options)
merged_options = options.merge!(@authentication).merge!(@parser)
merged_options[:headers].merge!(@user_agent) if merged_options[:headers]
merged_options
end

def get(path,options={})
evaluate_response(HTTParty.get(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
evaluate_response(HTTParty.get(configuration + URI.encode(path), merge_options(options)))
end



def post(path,options={})
evaluate_response(HTTParty.post(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
evaluate_response(HTTParty.post(configuration + URI.encode(path), merge_options(options)))
end

def put(path,options={})
evaluate_response(HTTParty.put(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
evaluate_response(HTTParty.put(configuration + URI.encode(path), merge_options(options)))
end

def delete(path,options={})
evaluate_response(HTTParty.delete(configuration + URI.encode(path), options.merge!(@authentication).merge!(@parser)))
evaluate_response(HTTParty.delete(configuration + URI.encode(path), merge_options(options)))
end

def get_id(id)
Expand Down

0 comments on commit a871d00

Please sign in to comment.