Class: Signalwire::Relay::Task
- Inherits:
-
Object
- Object
- Signalwire::Relay::Task
- Defined in:
- lib/signalwire/relay/task.rb
Constant Summary collapse
- DEFAULT_HOST =
"relay.signalwire.com"
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
Instance Method Summary collapse
- #deliver(context:, message:) ⇒ Object
-
#initialize(project:, token:, host: nil) ⇒ Task
constructor
A new instance of Task.
- #normalize_host(passed_host) ⇒ Object
Constructor Details
#initialize(project:, token:, host: nil) ⇒ Task
Returns a new instance of Task.
10 11 12 13 14 |
# File 'lib/signalwire/relay/task.rb', line 10 def initialize(project:, token:, host: nil ) @project = project @token = token @host = host || DEFAULT_HOST end |
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
8 9 10 |
# File 'lib/signalwire/relay/task.rb', line 8 def host @host end |
Instance Method Details
#deliver(context:, message:) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/signalwire/relay/task.rb', line 16 def deliver(context:, message:) = JSON.generate({ context: context, message: }) conn = Faraday.new( url: normalize_host(@host), headers: {'Content-Type' => 'application/json'} ) conn.basic_auth(@project, @token) resp = conn.post('/api/relay/rest/tasks') do |req| req.body = end return resp.status == 204 end |
#normalize_host(passed_host) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/signalwire/relay/task.rb', line 33 def normalize_host(passed_host) uri = URI.parse(passed_host) if uri.scheme.nil? && uri.host.nil? unless uri.path.nil? uri.scheme = 'https' uri.host = uri.path uri.path = '' end end uri.to_s end |