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

Parameters:

  • phone_number (String)

    number to send the text to

  • message (String)

    the body of the text message

  • country (String) (defaults to: 'US')

    ISO 3166 Country code for destination country

Returns:

  • (Boolean)

    true if TextBelt successfully passed on the message

Raises:



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