Class: Ovh::Http2sms::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/ovh/http2sms/client.rb

Overview

HTTP client for OVH HTTP2SMS API

Handles building requests, making HTTP calls, and processing responses. Thread-safe for use in multi-threaded environments.

Examples:

Direct usage

client = Client.new(account: "sms-xx111-1", login: "user", password: "pass")
response = client.deliver(to: "33601020304", message: "Hello!")

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(**options) ⇒ Client

Initialize a new client

Parameters:

  • options (Hash)

    Configuration options (overrides global config)

Options Hash (**options):

  • :account (String)

    SMS account identifier

  • :login (String)

    SMS user login

  • :password (String)

    SMS user password

  • :default_sender (String)

    Default sender name

  • :default_content_type (String)

    Response format

  • :timeout (Integer)

    HTTP timeout in seconds

  • :logger (Logger)

    Logger for debugging

  • :default_country_code (String)

    Default country code



31
32
33
# File 'lib/ovh/http2sms/client.rb', line 31

def initialize(**options)
  @config = build_config(options)
end

Instance Attribute Details

#configConfiguration (readonly)

Returns Client configuration.

Returns:



18
19
20
# File 'lib/ovh/http2sms/client.rb', line 18

def config
  @config
end

Instance Method Details

#deliver(to:, message:, sender: nil, deferred: nil, tag: nil, sms_class: nil, sms_coding: nil, no_stop: false, sender_for_response: false, content_type: nil) ⇒ Response

Send an SMS message

rubocop:disable Metrics/ParameterLists

Examples:

Simple send

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

With options

client.deliver(
  to: ["33601020304", "33602030405"],
  message: "Meeting at 3pm",
  sender: "MyCompany",
  deferred: 1.hour.from_now,
  tag: "reminders"
)

Parameters:

  • to (String, Array<String>)

    Recipient phone number(s)

  • message (String)

    SMS content

  • sender (String, nil) (defaults to: nil)

    Sender name (uses default if nil)

  • deferred (Time, String, nil) (defaults to: nil)

    Scheduled send time

  • tag (String, nil) (defaults to: nil)

    Custom tag for tracking (max 20 chars)

  • sms_class (Integer, nil) (defaults to: nil)

    SMS class (0-3)

  • sms_coding (Integer, nil) (defaults to: nil)

    Encoding (1=7bit, 2=Unicode)

  • no_stop (Boolean) (defaults to: false)

    Set to true for non-commercial SMS

  • sender_for_response (Boolean) (defaults to: false)

    Enable reply capability

  • content_type (String, nil) (defaults to: nil)

    Response format (uses default if nil)

Returns:

Raises:



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/ovh/http2sms/client.rb', line 67

def deliver(to:, message:, sender: nil, deferred: nil, tag: nil,
            sms_class: nil, sms_coding: nil, no_stop: false,
            sender_for_response: false, content_type: nil)
  # rubocop:enable Metrics/ParameterLists
  @config.validate!

  params = build_delivery_params(to, message, sender, deferred, tag, sms_class,
                                 sms_coding, no_stop, sender_for_response)
  Validators.validate!(params)

  query_params = build_query_params(params, content_type)
  execute_request(query_params, content_type)
end