Class: SmsAdapter::Plasgate

Inherits:
Base
  • Object
show all
Defined in:
app/services/sms_adapter/plasgate.rb

Instance Method Summary collapse

Instance Method Details

#clientObject



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

Yields:

  • (external_ref: json['queue_id'])


4
5
6
7
8
9
10
11
12
13
14
15
# File 'app/services/sms_adapter/plasgate.rb', line 4

def create_message(options)
  response = request(options)

  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(options)
  client.post('/rest/send') do |req|
    req.params = { private_key: Rails.application.credentials.plasgate[:private] }
    req.body = request_body(options).to_json
  end
end