Module: Ovh::Http2sms

Defined in:
lib/ovh/http2sms.rb,
lib/ovh/http2sms/client.rb,
lib/ovh/http2sms/errors.rb,
lib/ovh/http2sms/railtie.rb,
lib/ovh/http2sms/version.rb,
lib/ovh/http2sms/response.rb,
lib/ovh/http2sms/validators.rb,
lib/ovh/http2sms/gsm_encoding.rb,
lib/ovh/http2sms/phone_number.rb,
lib/ovh/http2sms/configuration.rb,
lib/generators/ovh/http2sms/install_generator.rb

Overview

OVH HTTP2SMS Ruby client

Send SMS via OVH’s http2sms API using simple HTTP GET requests. Supports single and bulk sending, scheduled messages, GSM/Unicode encoding, phone number formatting, and Rails integration.

Examples:

Configuration

Ovh::Http2sms.configure do |config|
  config. = "sms-xx11111-1"
  config. = "user"
  config.password = "secret"
end

Simple send

response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!")
response.success? # => true
response.sms_ids # => ["123456789"]

With options

Ovh::Http2sms.deliver(
  to: ["33601020304", "33602030405"],
  message: "Meeting reminder",
  sender: "MyCompany",
  deferred: 1.hour.from_now,
  tag: "meeting-reminders"
)

Check message length

Ovh::Http2sms.message_info("Hello!")
# => { characters: 6, encoding: :gsm, sms_count: 1, remaining: 143 }

Defined Under Namespace

Modules: Generators, GsmEncoding, PhoneNumber, Validators Classes: AuthenticationError, Client, Configuration, ConfigurationError, Error, InvalidParameterError, MessageLengthError, MissingParameterError, NetworkError, PhoneNumberError, Railtie, Response, ResponseParseError, ResponseParser, SenderNotFoundError, ValidationError

Constant Summary collapse

VERSION =
"0.1.2"

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.configurationConfiguration

Get the current configuration

Returns:



55
56
57
# File 'lib/ovh/http2sms.rb', line 55

def configuration
  @configuration ||= Configuration.new
end

Class Method Details

.client(**options) ⇒ Client

Get a new client instance with optional configuration overrides

Examples:

Use different credentials

client = Ovh::Http2sms.client(account: "sms-other-1")
client.deliver(to: "33601020304", message: "Hello!")

Parameters:

  • options (Hash)

    Configuration options to override

Returns:

  • (Client)

    New client instance



104
105
106
# File 'lib/ovh/http2sms.rb', line 104

def client(**options)
  Client.new(**options)
end

.configure {|Configuration| ... } ⇒ Configuration

Configure the gem

Examples:

Ovh::Http2sms.configure do |config|
  config. = "sms-xx11111-1"
  config. = "user"
  config.password = "secret"
  config.default_sender = "MyApp"
  config.timeout = 30
end

Yields:

Returns:



72
73
74
75
# File 'lib/ovh/http2sms.rb', line 72

def configure
  yield(configuration)
  configuration
end

.deliver(**options) ⇒ Response

Send an SMS message using the global configuration

Examples:

Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!")

Parameters:

  • to (String, Array<String>)

    Recipient phone number(s)

  • message (String)

    SMS content

  • sender (String, nil)

    Sender name (uses default if nil)

  • deferred (Time, String, nil)

    Scheduled send time

  • tag (String, nil)

    Custom tag for tracking (max 20 chars)

  • sms_class (Integer, nil)

    SMS class (0-3)

  • sms_coding (Integer, nil)

    Encoding (1=7bit, 2=Unicode)

  • no_stop (Boolean)

    Set to true for non-commercial SMS

  • sender_for_response (Boolean)

    Enable reply capability

  • content_type (String, nil)

    Response format (uses default if nil)

Returns:

Raises:



92
93
94
# File 'lib/ovh/http2sms.rb', line 92

def deliver(**options)
  client.deliver(**options)
end

.format_phone(phone, country_code: nil) ⇒ String

Format a phone number to international format

Examples:

Ovh::Http2sms.format_phone("0601020304") # => "0033601020304"
Ovh::Http2sms.format_phone("+33601020304") # => "0033601020304"

Parameters:

  • phone (String)

    Phone number in local or international format

  • country_code (String) (defaults to: nil)

    Country code for local numbers (default: from config)

Returns:

  • (String)

    Phone number in OVH format (00 prefix)



146
147
148
# File 'lib/ovh/http2sms.rb', line 146

def format_phone(phone, country_code: nil)
  PhoneNumber.format(phone, country_code: country_code)
end

.gsm_compatible?(message) ⇒ Boolean

Check if a message uses only GSM characters

Examples:

Ovh::Http2sms.gsm_compatible?("Hello!") # => true
Ovh::Http2sms.gsm_compatible?("Привет") # => false

Parameters:

  • message (String)

    Message to check

Returns:

  • (Boolean)

    true if all characters are GSM compatible



133
134
135
# File 'lib/ovh/http2sms.rb', line 133

def gsm_compatible?(message)
  GsmEncoding.gsm_compatible?(message)
end

.message_info(message, commercial: true) ⇒ Hash

Get message information (character count, encoding, SMS count)

Examples:

Ovh::Http2sms.message_info("Hello!")
# => { characters: 6, encoding: :gsm, sms_count: 1, remaining: 143, ... }

Non-commercial SMS

Ovh::Http2sms.message_info("Hello!", commercial: false)
# => { characters: 6, encoding: :gsm, sms_count: 1, remaining: 154, ... }

Parameters:

  • message (String)

    Message to analyze

  • commercial (Boolean) (defaults to: true)

    Whether this is a commercial SMS (default: true)

Returns:

  • (Hash)

    Message information



121
122
123
# File 'lib/ovh/http2sms.rb', line 121

def message_info(message, commercial: true)
  GsmEncoding.message_info(message, commercial: commercial)
end

.reset_configuration!Configuration

Reset configuration to defaults

Returns:



80
81
82
# File 'lib/ovh/http2sms.rb', line 80

def reset_configuration!
  @configuration = Configuration.new
end