class BMC::SMS::Strategies::Sendinblue URL = "https://api.sendinblue.com/v3/transactionalSMS/sms" DeliveryError = Class.new(BMC::SMS::DeliveryError) attr_reader :api_key def initialize(api_key: ENV["SENDINBLUE_API_KEY"]) @api_key = api_key end def call(data) response = HTTP.request(:post, URL, headers: request_headers, json: request_body(data)) unless response.code.to_s.start_with?("2") raise DeliveryError, "Invalid response: #{response.code} / #{response.body}" end true end private def request_headers { :content_type => "application/json", :api_key => api_key, } end def request_body(data) from = data[:from] || BMC::SMS.default_from { :type => "transactional", :sender => from, :recipient => data[:to], :content => data[:body], } end end