Class: Stealth::Services::Bandwidth::Client
- Inherits:
-
Stealth::Services::BaseClient
- Object
- Stealth::Services::BaseClient
- Stealth::Services::Bandwidth::Client
- Defined in:
- lib/stealth/services/bandwidth/client.rb
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
readonly
Returns the value of attribute endpoint.
-
#http_client ⇒ Object
readonly
Returns the value of attribute http_client.
-
#reply ⇒ Object
readonly
Returns the value of attribute reply.
Instance Method Summary collapse
-
#initialize(reply:) ⇒ Client
constructor
A new instance of Client.
- #transmit ⇒ Object
Constructor Details
#initialize(reply:) ⇒ Client
Returns a new instance of Client.
16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/stealth/services/bandwidth/client.rb', line 16 def initialize(reply:) @reply = reply account_id = Stealth.config.bandwidth.account_id username = Stealth.config.bandwidth.api_username password = Stealth.config.bandwidth.api_password application_id = Stealth.config.bandwidth.application_id @endpoint = "https://messaging.bandwidth.com/api/v2/users/#{account_id}/messages" @http_client = HTTP .timeout(connect: 15, read: 30) .basic_auth(user: username, pass: password) .headers('Content-Type' => 'application/json') end |
Instance Attribute Details
#endpoint ⇒ Object (readonly)
Returns the value of attribute endpoint.
14 15 16 |
# File 'lib/stealth/services/bandwidth/client.rb', line 14 def endpoint @endpoint end |
#http_client ⇒ Object (readonly)
Returns the value of attribute http_client.
14 15 16 |
# File 'lib/stealth/services/bandwidth/client.rb', line 14 def http_client @http_client end |
#reply ⇒ Object (readonly)
Returns the value of attribute reply.
14 15 16 |
# File 'lib/stealth/services/bandwidth/client.rb', line 14 def reply @reply end |
Instance Method Details
#transmit ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/stealth/services/bandwidth/client.rb', line 29 def transmit # Don't transmit anything for delays return true if reply.blank? json_reply = Oj.dump(reply, mode: :compat) response = http_client.post(endpoint, body: json_reply) Stealth::Logger.l( topic: 'bandwidth', message: "Transmitting. Response: #{response.status.code}: #{response.body}" ) end |