Module: MicroService::Server::InstanceMethods

Defined in:
lib/micro_service/server/instance_methods.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



4
5
6
# File 'lib/micro_service/server/instance_methods.rb', line 4

def self.included(base)
	base.table_name = "micro_service_servers"
end

Instance Method Details

#signed_request(request) {|http, request, prefix| ... } ⇒ Object

Net::HTTP request instance able to communicate with the server described here

Yields:

  • (http, request, prefix)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/micro_service/server/instance_methods.rb', line 9

def signed_request(request)
	require "open-uri"
	require "net/http"
	require "openssl"

	uri = URI.parse(self.url.to_s)
	http = Net::HTTP.new(uri.host, uri.port)
	http.use_ssl = true if uri.scheme == "https"

	prefix = "MicroService"

	yield http,request,prefix

	# Populate with authorization header
	request["Authorization"] = "#{prefix} #{self.send(:valid_authentication_header)}"

	http.request(request)
end