Class: Mollie::SMS::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/mollie/sms.rb

Overview

This class encapsulates the HTTP response and the response from the gateway. Put shortly, instances of this class return whether or not a SMS message has been delivered.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Response

Initializes a new Mollie::SMS::Response instance.

Parameters:

  • http_response (Net::HTTPResponse)

    The HTTP response object.


283
284
285
# File 'lib/mollie/sms.rb', line 283

def initialize(http_response)
  @http_response = http_response
end

Instance Attribute Details

#http_responseNet::HTTPResponse (readonly)

Returns The raw HTTP response object.

Returns:

  • (Net::HTTPResponse)

    The raw HTTP response object.


278
279
280
# File 'lib/mollie/sms.rb', line 278

def http_response
  @http_response
end

Instance Method Details

#http_failure?Boolean

Returns Whether or not the HTTP request was a success.

Returns:

  • (Boolean)

    Whether or not the HTTP request was a success.


335
336
337
# File 'lib/mollie/sms.rb', line 335

def http_failure?
  !@http_response.is_a?(Net::HTTPSuccess)
end

#inspectString

Returns A `inspect' string representation of this instance.

Returns:

  • (String)

    A `inspect' string representation of this instance.


340
341
342
# File 'lib/mollie/sms.rb', line 340

def inspect
  "#<#{self.class.name} #{ success? ? 'succeeded' : 'failed' } (#{result_code}) `#{message}'>"
end

#messageString

Returns The message from the gateway, or the HTTP message in case of a HTTP error.

Returns:

  • (String)

    The message from the gateway, or the HTTP message in case of a HTTP error.

See Also:


325
326
327
# File 'lib/mollie/sms.rb', line 325

def message
  http_failure? ? "[HTTP: #{@http_response.code}] #{@http_response.message}" : params['resultmessage']
end

#paramsHash

Returns The response parameters from the gateway. Or an empty Hash if a HTTP error occurred.

Returns:

  • (Hash)

    The response parameters from the gateway. Or an empty Hash if a HTTP error occurred.


289
290
291
# File 'lib/mollie/sms.rb', line 289

def params
  @params ||= http_failure? ? {} : Hash.from_xml(@http_response.read_body)['response']['item']
end

#result_codeInteger

Upon success, returns the result code from the gateway. Otherwise the HTTP response code.

The possible gateway result codes are:

  • 10 - message sent

  • 20 - no ‘username’

  • 21 - no ‘password’

  • 22 - no, or incorrect, ‘originator’

  • 23 - no ‘recipients’

  • 24 - no ‘message’

  • 25 - incorrect ‘recipients’

  • 26 - incorrect ‘originator’

  • 27 - incorrect ‘message’

  • 28 - charset failure

  • 29 - parameter failure

  • 30 - incorrect ‘username’ or ‘password’

  • 31 - not enough credits to send message

  • 38 - binary UDH parameter misformed

  • 39 - ‘deliverydate’ format is not correct

  • 98 - gateway unreachable

  • 99 - unknown error

Returns:

  • (Integer)

    The result code from the gateway or HTTP response code.


317
318
319
# File 'lib/mollie/sms.rb', line 317

def result_code
  (http_failure? ? @http_response.code : params['resultcode']).to_i
end

#success?Boolean

Returns Whether or not the SMS message has been delivered.

Returns:

  • (Boolean)

    Whether or not the SMS message has been delivered.


330
331
332
# File 'lib/mollie/sms.rb', line 330

def success?
  !http_failure? && params['success'] == 'true'
end