Class: SFax::Client
Constant Summary
Constants included from Constants
SFax::Constants::SEND_FAX_PATH, SFax::Constants::SEND_FAX_QUEUE_ID_ERROR_VALUE, SFax::Constants::SFAX_URL
Instance Method Summary collapse
-
#initialize(username:, api_key:, encryption_key:) ⇒ Client
constructor
A new instance of Client.
- #send_fax(fax_number:, file:, recipient_name:) ⇒ Object
Constructor Details
Instance Method Details
#send_fax(fax_number:, file:, recipient_name:) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/sfax/client.rb', line 17 def send_fax(fax_number:, file:, recipient_name:) validate_fax_number fax_number response = connection.post SEND_FAX_PATH do |request| request.params = { 'token' => generate_token, 'ApiKey' => api_key, 'RecipientFax' => fax_number, 'RecipientName' => recipient_name, } request.body = { file: Faraday::UploadIO.new(file, 'application/pdf', "#{gen_dt}.pdf") } end response_object = JSON.parse(response.body) # TODO: Refactor into proper response objec. def response_object.fax_id fetch('SendFaxQueueId') end def response_object.success? fetch('isSuccess') end def response_object. fetch('message') end response_object.tap do |o| raise SendFaxError, o. unless o.success? raise SendFaxError, o. if o.fax_id.to_s == SEND_FAX_QUEUE_ID_ERROR_VALUE end end |