Module: TextBelt

Includes:
Configurations
Defined in:
lib/textbelt.rb,
lib/textbelt/errors.rb,
lib/textbelt/version.rb,
lib/textbelt/textutils.rb,
lib/textbelt/validators/phone_validator.rb,
lib/textbelt/validators/response_validator.rb

Overview

Author:

  • Dean Silfen

Defined Under Namespace

Modules: Errors Classes: PhoneValidator, ResponseValidator, TextUtils

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.text(phone_number, message, country = 'US') ⇒ Boolean

Get a list of categories from the service

Raises:

  • phone number passed as an integer

  • phone number is not valid

  • http server says number is blacklisted

  • http server had a gateway error communicating with carrier

  • http server cannot validate the phone's quota

  • http server cannot validate the ip’s quota

  • the phone’s quota has been exceeded

  • IP’s quota has been exceeded

Parameters:

  • number to send the text to

  • the body of the text message

  • (defaults to: 'US')

    ISO 3166 Country code for destination country

Returns:

  • true if TextBelt successfully passed on the message



41
42
43
44
45
46
47
48
# File 'lib/textbelt.rb', line 41

def text(phone_number, message, country = 'US')
  PhoneValidator.validate(phone_number, country)
  uri = TextUtils.uri_for(country)
  res = Net::HTTP.post_form(uri, number: phone_number, message: message)
  body = JSON.parse(res.body)
  ResponseValidator.validate(phone_number, body)
  body['success'.freeze]
end