-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,41 @@ | |||
module TaaS | |||
@taas = nil | |||
|
|||
class TaaSClient | |||
|
|||
attr_accessor :url, :timeout | |||
|
|||
def initialize(url, timeout) | |||
@url = url | |||
@timeout = timeout | |||
end | |||
|
|||
def execute(contract_name,input_params={}) | |||
execute_contract(contract_name,input_params) | |||
end | |||
|
|||
private | |||
|
|||
def url_for(contract_name, input_params) | |||
contract_url = @url + "/#{contract_name}" | |||
input_params.values.each {|input_param_value| contract_url += "/#{input_param_value}" } | |||
contract_url | |||
end | |||
|
|||
def execute_contract(contract_name, input_params) | |||
uri = URI.parse(url_for(contract_name,input_params)) | |||
http_end_point = Net:HTTP.new(uri.host, url.port) | |||
|
|||
#configure the timeout setting for the http endpoint | |||
http_end_point.read_timeout = @timeout | |||
|
|||
http_response = http_end_point.request(Net::HTTP::Get.new(uri.request_uri)) | |||
|
|||
puts "http_response for contract: #{contract_name} with parameters:\n\t#{input_params}\n#{http_response.inspect}" | |||
end | |||
end | |||
|
|||
def configure (url,timeout) | |||
@taas = TaaSClient.new(url, timeout) if @taas.nil? | |||
end | |||
end |