Class: Wire::HttpTransport
- Inherits:
-
Object
- Object
- Wire::HttpTransport
- Defined in:
- lib/wire.rb
Instance Method Summary collapse
-
#initialize(host, port = nil) ⇒ HttpTransport
constructor
A new instance of HttpTransport.
- #transmit(service_name, version, invocation_signal, timeout_seconds) ⇒ Object
Constructor Details
#initialize(host, port = nil) ⇒ HttpTransport
Returns a new instance of HttpTransport.
155 156 157 158 159 160 |
# File 'lib/wire.rb', line 155 def initialize (host, port = nil) @host = host if !port.nil? @host += ":" + port end end |
Instance Method Details
#transmit(service_name, version, invocation_signal, timeout_seconds) ⇒ Object
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
# File 'lib/wire.rb', line 162 def transmit (service_name, version, invocation_signal, timeout_seconds) = Message.new begin uri = URI("#{@host}/api/message") headers = {"Content-Type" => "application/json"} http = Net::HTTP.new(uri.host, uri.port) http.read_timeout = timeout_seconds invocation_signal.function.service = service_name invocation_signal.function.version = version context_hash = {} invocation_signal.contexts.each { |context| context.each { |key, value| context_hash[key] = value } } invocation_signal.contexts = context_hash res = http.post(uri.path, invocation_signal.to_json, headers) case res when Net::HTTPSuccess response = JSON.parse res.body .complete(response) else res.error! end rescue Timeout::Error .timeout end end |