Skip to content

Commit

Permalink
adding a little bit of meta
Browse files Browse the repository at this point in the history
  • Loading branch information
maxdemarzi committed Aug 31, 2013
1 parent 6f3cfe5 commit 5a6c8c2
Showing 1 changed file with 8 additions and 20 deletions.
28 changes: 8 additions & 20 deletions lib/neography/connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ module WasCreated
end
class Connection
USER_AGENT = "Neography/#{Neography::VERSION}"

ACTIONS = ["get", "post", "put", "delete"]

attr_accessor :protocol, :server, :port, :directory,
:cypher_path, :gremlin_path,
:log_file, :log_enabled, :logger,
Expand All @@ -27,7 +28,7 @@ def configure(protocol, server, port, directory)
end

def configuration
"#{@protocol}#{@server}:#{@port}#{@directory}/db/data"
@configuration ||= "#{@protocol}#{@server}:#{@port}#{@directory}/db/data"
end

def merge_options(options)
Expand All @@ -37,24 +38,11 @@ def merge_options(options)
merged_options
end

def get(path, options={})
authenticate(configuration + path)
evaluate_response(@client.get(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

def post(path, options={})
authenticate(configuration + path)
evaluate_response(@client.post(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

def put(path, options={})
authenticate(configuration + path)
evaluate_response(@client.put(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end

def delete(path, options={})
authenticate(configuration + path)
evaluate_response(@client.delete(configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
ACTIONS.each do |action|
define_method(action) do |path, options = {}|
authenticate(configuration + path)
evaluate_response(@client.send(action.to_sym, configuration + path, merge_options(options)[:body], merge_options(options)[:headers]))
end
end

def authenticate(path)
Expand Down

0 comments on commit 5a6c8c2

Please sign in to comment.