Class: TextBelt::ResponseValidator
- Inherits:
-
Object
- Object
- TextBelt::ResponseValidator
- Defined in:
- lib/textbelt/validators/response_validator.rb
Overview
Validator for incoming http responses
Class Method Summary collapse
-
.validate(phone_number, body) ⇒ Boolean
Validate the response from http service.
Class Method Details
.validate(phone_number, body) ⇒ Boolean
Validate the response from http service
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 51 |
# File 'lib/textbelt/validators/response_validator.rb', line 23 def validate(phone_number, body) return true if body['message'].nil? && body['success'] = body['message'] if == 'Sorry, texts to this number are disabled.' raise TextBelt::Errors::BlackListedNumberError, "#{phone_number} has been blacklisted" end if == 'Communication with SMS gateway failed.' raise TextBelt::Errors::GatewayFailureError, 'A gateway failure occured between the http service and the carrier' end if == 'Could not validate phone# quota.' raise TextBelt::Errors::PhoneCouldNotValidateError, "#{phone_number} could not be validated in http service" end if == 'Could not validate IP quota.' raise TextBelt::Errors::IPCouldNotValidateError, end if .include? 'Exceeded quota for this phone number.' raise TextBelt::Errors::PhoneQuotaExceededError, end if .include? 'Exceeded quota for this IP address.' raise TextBelt::Errors::IPQuotaExceededError, end true end |