File: vonage_sms.rb

package info (click to toggle)
ruby-noticed 3.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 324 kB
  • sloc: ruby: 1,186; makefile: 4
file content (22 lines) | stat: -rw-r--r-- 679 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
module Noticed
  module DeliveryMethods
    class VonageSms < DeliveryMethod
      DEFAULT_URL = "https://rest.nexmo.com/sms/json"

      required_options :json

      def deliver
        headers = evaluate_option(:headers)
        json = evaluate_option(:json)
        response = post_request url, headers: headers, json: json
        raise ResponseUnsuccessful.new(response, url, headers: headers, json: json) if JSON.parse(response.body).dig("messages", 0, "status") != "0"
      end

      def url
        evaluate_option(:url) || DEFAULT_URL
      end
    end
  end
end

ActiveSupport.run_load_hooks :noticed_delivery_methods_vonage_sms, Noticed::DeliveryMethods::VonageSms