Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions lib/keymaker/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,17 @@ module Keymaker
class Configuration

attr_accessor :protocol, :server, :port, :data_directory,
:authentication, :username, :password
:authentication, :username, :password, :http_client_custom_initializer

def initialize(attrs={})
self.protocol = attrs.fetch(:protocol) {'http'}
self.server = attrs.fetch(:server) {'localhost'}
self.port = attrs.fetch(:port) {7474}
self.authentication = attrs.fetch(:authentication) {{}}
self.username = attrs.fetch(:username) {nil}
self.password = attrs.fetch(:password) {nil}
self.data_directory = 'db/data'
self.protocol = attrs.fetch(:protocol) {'http'}
self.server = attrs.fetch(:server) {'localhost'}
self.port = attrs.fetch(:port) {7474}
self.authentication = attrs.fetch(:authentication) {{}}
self.username = attrs.fetch(:username) {nil}
self.password = attrs.fetch(:password) {nil}
self.http_client_custom_initializer = attrs.fetch(:http_client_custom_initializer) {->(http_client){}}
self.data_directory = 'db/data'
end

def service_root
Expand Down
1 change: 1 addition & 0 deletions lib/keymaker/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ def connection
conn.response :mashify
conn.response :json, :content_type => /\bjson$/
conn.adapter :net_http
config.http_client_custom_initializer.call( conn )
end
end

Expand Down
16 changes: 16 additions & 0 deletions spec/service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@
end
end

context "with custom http client initializer provided" do
let(:options) { { http_client_custom_initializer: ->(conn){ conn.headers['X-Stream'] = 'true' }} }
let(:config) do
Keymaker::Configuration.new(options)
end

let(:service) { Keymaker::Service.new(config) }

describe "#connection" do
it "must be configured" do
service.connection.headers['X-Stream'].should == 'true'
end
end

end

end