class Signalwire::Relay::Task
Constants
- DEFAULT_HOST
Attributes
host[RW]
Public Class Methods
new(project:, token:, host: nil )
click to toggle source
# File lib/signalwire/relay/task.rb, line 10 def initialize(project:, token:, host: nil ) @project = project @token = token @host = host || DEFAULT_HOST end
Public Instance Methods
deliver(context:, message:)
click to toggle source
# File lib/signalwire/relay/task.rb, line 16 def deliver(context:, message:) message = JSON.generate({ context: context, message: 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 = message end return resp.status == 204 end
normalize_host(passed_host)
click to toggle source
# 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