Class: SmsAdapter::Plasgate
- Defined in:
- app/services/sms_adapter/plasgate.rb
Instance Method Summary collapse
- #client ⇒ Object
-
#create_message(options) {|external_ref: json['queue_id']| ... } ⇒ Object
options: to:, :from, :body.
- #request(options) ⇒ Object
Instance Method Details
#client ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'app/services/sms_adapter/plasgate.rb', line 24 def client host = 'https://cloudapi.plasgate.com' @client = Faraday.new( url: host, ssl: { verify: false }, headers: { 'X-Secret' => Rails.application.credentials.plasgate[:secret], 'Content-Type' => 'application/json' } ) @client end |
#create_message(options) {|external_ref: json['queue_id']| ... } ⇒ Object
options: to:, :from, :body
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'app/services/sms_adapter/plasgate.rb', line 4 def () response = request() raise response.body if response.status != 200 json = JSON.parse(response.body) # update sms log yield(external_ref: json['queue_id']) json end |
#request(options) ⇒ Object
17 18 19 20 21 22 |
# File 'app/services/sms_adapter/plasgate.rb', line 17 def request() client.post('/rest/send') do |req| req.params = { private_key: Rails.application.credentials.plasgate[:private] } req.body = request_body().to_json end end |