### Local Development Setup and Execution (Bash) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Outlines the steps for setting up and running the OVH HTTP2SMS gem locally without Docker. This includes installing dependencies, running tests, and installing the gem locally. ```bash bin/setup bundle exec rake spec To install locally: bundle exec rake install ``` -------------------------------- ### Install OVH HTTP2SMS Gem Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Instructions for installing the ovh-http2sms gem using Bundler or directly via the gem command. This gem is required to use the OVH SMS API. ```ruby gem "ovh-http2sms" ``` ```bash bundle install ``` ```bash gem install ovh-http2sms ``` -------------------------------- ### Enqueueing and Scheduling SMS Jobs with ActiveJob Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Demonstrates how to enqueue SMS delivery jobs using ActiveJob for immediate or scheduled sending. It shows examples of sending a standard message, a message with options like `no_stop`, and scheduling a message for later delivery. ```ruby # Enqueue SMS jobs SmsNotificationJob.perform_later("0601020304", "Your order shipped!", { tag: "shipping" }) SmsNotificationJob.perform_later("0601020304", "Your 2FA code: 123456", { no_stop: true }) # Scheduled delivery with ActiveJob SmsNotificationJob.set(wait: 1.hour).perform_later("0601020304", "Reminder!") ``` -------------------------------- ### Configure OVH HTTP2SMS Gem with Block Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Configures the OVH HTTP2SMS gem using a block, allowing for detailed setup of credentials and optional parameters. This method is recommended for most application setups. It requires account, login, and password, with optional settings for sender, country code, response format, timeout, error handling, and logging. ```ruby Ovh::Http2sms.configure do |config| # Required credentials config.account = "sms-xx11111-1" # Your OVH SMS account ID config.login = "your_login" # SMS user login config.password = "your_password" # SMS user password # Optional settings config.default_sender = "MyApp" # Default sender name (must be registered with OVH) config.default_country_code = "33" # Country code for local phone numbers (France) config.default_content_type = "application/json" # Response format config.timeout = 15 # HTTP timeout in seconds config.raise_on_length_error = true # Raise error for very long messages config.logger = Logger.new($stdout) # Enable debugging end # Check if configuration is valid puts Ovh::Http2sms.configuration.valid? # => true ``` -------------------------------- ### Configure OVH HTTP2SMS Gem with Environment Variables Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Configures the OVH HTTP2SMS gem using environment variables, which allows for setup without modifying code. This is useful for deployment environments. Required credentials and optional settings can be defined as environment variables. ```bash # Required credentials export OVH_SMS_ACCOUNT="sms-xx11111-1" export OVH_SMS_LOGIN="your_login" export OVH_SMS_PASSWORD="your_password" # Optional settings export OVH_SMS_DEFAULT_SENDER="MyApp" export OVH_SMS_DEFAULT_COUNTRY_CODE="33" export OVH_SMS_TIMEOUT="30" export OVH_SMS_DEFAULT_CONTENT_TYPE="application/json" export OVH_SMS_RAISE_ON_LENGTH_ERROR="true" ``` -------------------------------- ### Code Style Check with RuboCop (Bash) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Command to check the code style of the OVH HTTP2SMS gem against the defined Ruby style guide using RuboCop. ```bash bundle exec rubocop ``` -------------------------------- ### Use OVH HTTP2SMS with ActiveJob Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Integrates the OVH HTTP2SMS gem with Rails' ActiveJob for asynchronous SMS notifications. The example shows a `SmsNotificationJob` class that performs the `Ovh::Http2sms.deliver` method in the background. Parameters, including options, are passed and symbolized correctly for use with ActiveJob. ```ruby class SmsNotificationJob < ApplicationJob queue_as :default def perform(phone_number, message, options = {}) Ovh::Http2sms.deliver( to: phone_number, message: message, **options.symbolize_keys ) end end # Enqueue SmsNotificationJob.perform_later("0601020304", "Your order shipped!", { tag: "shipping" }) ``` -------------------------------- ### Schedule SMS Sending with DateTime Object Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Schedules an SMS message for future delivery using a Ruby DateTime object with the OVH HTTP2SMS gem. The `deferred` parameter can accept a `DateTime` object for scheduling. This example schedules a birthday message for a specific date and time. ```ruby # Using DateTime require 'date' response = Ovh::Http2sms.deliver( to: "33601020304", message: "Happy Birthday!", deferred: DateTime.new(2025, 3, 15, 9, 0, 0) # March 15, 2025 at 9:00 AM ) ``` -------------------------------- ### Schedule SMS Sending with Time Object Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Schedules an SMS message for future delivery using a Ruby Time object with the OVH HTTP2SMS gem. The `deferred` parameter accepts a `Time` object, allowing for precise scheduling. This example schedules a reminder for 24 hours in the future. ```ruby # Using Ruby Time object (recommended) response = Ovh::Http2sms.deliver( to: "33601020304", message: "Reminder: Your appointment is tomorrow at 10am", deferred: Time.now + 86400 # 24 hours from now ) ``` -------------------------------- ### Get SMS Message Information (Ruby) Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Calculates message details like character count, encoding, and the number of SMS segments required. Useful for managing long messages and understanding costs. It takes a string message as input. ```ruby long_message = "A" * 200 info = Ovh::Http2sms.message_info(long_message) # => { # characters: 200, # encoding: :gsm, # sms_count: 2, # Split into 2 SMS segments # remaining: 102, # max_single_sms: 149, # non_gsm_chars: [] # } ``` -------------------------------- ### Message Information Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Get information about a long message, including character count, encoding, and the number of SMS segments required. ```APIDOC ## Message Information ### Description Get information about a long message, including character count, encoding, and the number of SMS segments required. ### Method `POST` (or equivalent internal method) ### Endpoint `/fkiene/ovh-http2sms` (Conceptual endpoint for message info) ### Parameters #### Request Body - **message** (string) - Required - The message content to analyze. ### Request Example ```ruby long_message = "A" * 200 info = Ovh::Http2sms.message_info(long_message) ``` ### Response #### Success Response (200) - **characters** (integer) - The total number of characters in the message. - **encoding** (string) - The detected character encoding (:gsm or :unicode). - **sms_count** (integer) - The number of SMS segments the message will be split into. - **remaining** (integer) - The remaining characters allowed in the last SMS segment. - **max_single_sms** (integer) - The maximum number of characters for a single SMS segment with the detected encoding. - **non_gsm_chars** (array) - An array of characters not compatible with GSM encoding. #### Response Example ```json { "characters": 200, "encoding": ":gsm", "sms_count": 2, "remaining": 102, "max_single_sms": 149, "non_gsm_chars": [] } ``` ``` -------------------------------- ### Schedule SMS Sending with OVH Format String Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Schedules an SMS message for future delivery using an OVH-specific format string with the OVH HTTP2SMS gem. The `deferred` parameter can accept a string in `hhmmddMMYYYY` format for scheduling. This example schedules a New Year's message. ```ruby # Using OVH format string (hhmmddMMYYYY) response = Ovh::Http2sms.deliver( to: "33601020304", message: "Happy New Year!", deferred: "000001012025" # Midnight on January 1, 2025 ) ``` -------------------------------- ### Format Phone Numbers for OVH Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Automatically formats phone numbers into the OVH international format, which typically starts with '00' followed by the country code. It handles various input formats, including local numbers, international numbers with or without a plus sign, and numbers with spaces or dashes. A custom country code can be provided if needed. ```ruby # Local French number Ovh::Http2sms.format_phone("0601020304") # => "0033601020304" # Already international Ovh::Http2sms.format_phone("33601020304") # => "0033601020304" # With plus sign Ovh::Http2sms.format_phone("+33601020304") # => "0033601020304" # With spaces and dashes Ovh::Http2sms.format_phone("06 01 02-03-04") # => "0033601020304" # Already OVH format (unchanged) Ovh::Http2sms.format_phone("0033601020304") # => "0033601020304" # UK number with custom country code Ovh::Http2sms.format_phone("07911123456", country_code: "44") # => "00447911123456" ``` -------------------------------- ### Development Workflow with Docker (Bash) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Provides commands for interacting with the OVH HTTP2SMS gem using Docker. It covers launching an interactive console, running tests, and executing linters within a Dockerized environment. Instructions for using real credentials by editing the `.env` file are also included. ```bash # Interactive console docker compose run --rm dev # Run tests docker compose run --rm test # Run linter docker compose run --rm lint To test with real credentials: cp .env.example .env # Edit .env with your OVH credentials docker compose run --rm dev ``` -------------------------------- ### Manage Multiple OVH Accounts with Clients Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Demonstrates how to create and use separate `Ovh::Http2sms` clients for different OVH accounts. This is useful when managing multiple OVH API credentials or sender identities. Each client can be configured with specific account details, login credentials, passwords, and default sender numbers, allowing for distinct sending contexts. ```ruby marketing_client = Ovh::Http2sms.client( account: "sms-marketing-1", login: "marketing_user", password: "marketing_pass", default_sender: "Promo" ) transactional_client = Ovh::Http2sms.client( account: "sms-transact-1", login: "transact_user", password: "transact_pass", default_sender: "Alerts" ) marketing_client.deliver(to: "33601020304", message: "Special offer!") transactional_client.deliver(to: "33601020304", message: "Order confirmed", no_stop: true) ``` -------------------------------- ### Create Separate Ovh::Http2sms Client Instances Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Instantiate multiple Ovh::Http2sms client objects to manage different OVH accounts or configurations. Each client can have its own default sender, timeout, and logger settings, allowing for distinct usage patterns like marketing and transactional messaging. ```ruby # Create client for marketing account marketing_client = Ovh::Http2sms.client( account: "sms-marketing-1", login: "marketing_user", password: "marketing_pass", default_sender: "Promo" ) # Create client for transactional account transactional_client = Ovh::Http2sms.client( account: "sms-transact-1", login: "transact_user", password: "transact_pass", default_sender: "Alerts" ) # Use different clients for different purposes marketing_client.deliver( to: "33601020304", message: "Exclusive offer just for you!" ) transactional_client.deliver( to: "33601020304", message: "Your password has been reset", no_stop: true ) # Client with custom timeout and logging debug_client = Ovh::Http2sms.client( account: "sms-xx11111-1", login: "user", password: "pass", timeout: 30, logger: Logger.new($stdout) ) ``` -------------------------------- ### Running Tests with RSpec (Bash) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Command to execute the test suite for the OVH HTTP2SMS gem using RSpec. ```bash bundle exec rspec ``` -------------------------------- ### Git Workflow for Contributions (Bash) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Standard Git commands for contributing to the OVH HTTP2SMS project. It details forking the repository, creating a feature branch, committing changes, and preparing a pull request. ```bash 1. Fork it 2. Create your feature branch (`git checkout -b feature/my-feature`) 3. Commit your changes (`git commit -am 'Add my feature'`) 4. Push to the branch (`git push origin feature/my-feature`) 5. Create a Pull Request ``` -------------------------------- ### Send a Simple SMS Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Demonstrates sending a single SMS message using the `deliver` method. It includes basic error checking for the response. The `to` and `message` parameters are mandatory. ```ruby # Configure credentials first (see Configuration section) response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") if response.success? puts "SMS sent! ID: #{response.sms_ids.first}" puts "Credits remaining: #{response.credits_remaining}" else puts "Error: #{response.error_message}" end ``` -------------------------------- ### Configure OVH HTTP2SMS Credentials (Environment Variables) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Sets OVH HTTP2SMS configuration using environment variables. This method allows for flexible configuration without modifying code directly. Supported variables include account, login, password, default sender, country code, and timeout. ```bash export OVH_SMS_ACCOUNT="sms-xx11111-1" export OVH_SMS_LOGIN="your_login" export OVH_SMS_PASSWORD="your_password" export OVH_SMS_DEFAULT_SENDER="MyApp" export OVH_SMS_DEFAULT_COUNTRY_CODE="33" export OVH_SMS_TIMEOUT="30" ``` -------------------------------- ### Configure OVH HTTP2SMS Credentials (Block) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Configures the OVH HTTP2SMS client using a block. Requires account, login, and password. Optional parameters include default sender, country code, content type, timeout, error handling, and logger. ```ruby Ovh::Http2sms.configure do |config| # Required config.account = "sms-xx11111-1" config.login = "your_login" config.password = "your_password" # Optional config.default_sender = "MyApp" # Default sender name config.default_country_code = "33" # For phone number formatting (default: "33" France) config.default_content_type = "application/json" # Response format config.timeout = 15 # HTTP timeout in seconds config.raise_on_length_error = true # Raise error for very long messages config.logger = Logger.new($stdout) # For debugging end ``` -------------------------------- ### Handle OVH HTTP2SMS Errors (Ruby) Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Provides a comprehensive error handling structure for various OVH HTTP2SMS API failures using `begin...rescue` blocks. It catches specific exceptions like `ConfigurationError`, `AuthenticationError`, `MissingParameterError`, `InvalidParameterError`, `SenderNotFoundError`, `PhoneNumberError`, `MessageLengthError`, `NetworkError`, `ValidationError`, `ResponseParseError`, and the general `Error` class, offering detailed information for each. ```ruby begin response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") rescue Ovh::Http2sms::ConfigurationError => e # Missing or invalid configuration puts "Configuration error: #{e.message}" # => "Missing required configuration: account, login. Set via Ovh::Http2sms.configure block..." rescue Ovh::Http2sms::AuthenticationError => e # IP not authorized (status 401) puts "Auth error: #{e.message}" puts "Status code: #{e.status_code}" # => 401 # Whitelist your IP in OVH SMS control panel rescue Ovh::Http2sms::MissingParameterError => e # Required parameter missing (status 201) puts "Missing param: #{e.message}" puts "Parameter: #{e.parameter}" rescue Ovh::Http2sms::InvalidParameterError => e # Invalid parameter value (status 202) puts "Invalid param: #{e.message}" puts "Parameter: #{e.parameter}" rescue Ovh::Http2sms::SenderNotFoundError => e # Sender not registered (status 241) puts "Sender error: #{e.message}" puts "Sender: #{e.sender}" # Register sender in OVH SMS control panel rescue Ovh::Http2sms::PhoneNumberError => e # Invalid phone number format puts "Phone error: #{e.message}" puts "Phone number: #{e.phone_number}" # => "abc123" rescue Ovh::Http2sms::MessageLengthError => e # Message exceeds SMS limits puts "Length error: #{e.message}" puts "Encoding: #{e.encoding}" # => :gsm or :unicode puts "Length: #{e.length}" # => 1600 puts "Max length: #{e.max_length}" rescue Ovh::Http2sms::NetworkError => e # HTTP request failed (timeout, connection error) puts "Network error: #{e.message}" puts "Original error: #{e.original_error}" rescue Ovh::Http2sms::ValidationError => e # Parameter validation failed before sending puts "Validation error: #{e.message}" # e.g., "Tag exceeds maximum length of 20 characters" rescue Ovh::Http2sms::ResponseParseError => e # Failed to parse API response puts "Parse error: #{e.message}" puts "Content type: #{e.content_type}" puts "Raw response: #{e.raw_response}" rescue Ovh::Http2sms::Error => e # Base error class for any OVH HTTP2SMS error puts "General error: #{e.message}" puts "Status code: #{e.status_code}" puts "Raw response: #{e.raw_response}" end ``` -------------------------------- ### Handle OVH HTTP2SMS Errors Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Demonstrates how to handle various exceptions that can be raised by the `Ovh::Http2sms` gem during message delivery. This includes specific errors for configuration issues, authentication failures, missing or invalid parameters, phone number problems, message length limits, network errors, and response parsing failures. A general `Ovh::Http2sms::Error` catch-all is also provided. ```ruby begin response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") rescue Ovh::Http2sms::ConfigurationError => e puts "Missing configuration: #{e.message}" rescue Ovh::Http2sms::AuthenticationError => e puts "IP not authorized: #{e.message}" rescue Ovh::Http2sms::MissingParameterError => e puts "Missing parameter: #{e.message}" rescue Ovh::Http2sms::InvalidParameterError => e puts "Invalid parameter: #{e.message}" rescue Ovh::Http2sms::SenderNotFoundError => e puts "Sender not registered: #{e.message}" rescue Ovh::Http2sms::PhoneNumberError => e puts "Invalid phone number: #{e.phone_number}" rescue Ovh::Http2sms::MessageLengthError => e puts "Message too long: #{e.length} chars (#{e.encoding} encoding)" rescue Ovh::Http2sms::NetworkError => e puts "Network error: #{e.message}" rescue Ovh::Http2sms::ResponseParseError => e puts "Failed to parse response: #{e.message}" rescue Ovh::Http2sms::Error => e puts "General error: #{e.message}" end ``` -------------------------------- ### Generate OVH HTTP2SMS Initializer in Rails Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Generates an initializer file for the OVH HTTP2SMS gem within a Rails application using the provided Rails generator command. This initializer, typically located at `config/initializers/ovh_http2sms.rb`, allows for centralized configuration of OVH API credentials and other settings. ```bash rails g ovh:http2sms:install ``` -------------------------------- ### Send SMS with OVH HTTP2SMS Gem (Environment Variables) Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Sends a simple SMS message using the OVH HTTP2SMS gem after configuring it via environment variables. This demonstrates a basic usage scenario after the gem has been set up. The `deliver` method takes `to` and `message` as arguments. ```ruby # Configuration automatically loaded from environment variables response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") # => # ``` -------------------------------- ### Configure OVH HTTP2SMS Credentials (Rails Credentials) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Integrates OVH HTTP2SMS configuration with Rails encrypted credentials. This enhances security by keeping sensitive information out of version control. The configuration is loaded in an initializer. ```bash rails credentials:edit ``` ```yaml ovh_sms: account: sms-xx11111-1 login: your_login password: your_password default_sender: MyApp ``` ```ruby Ovh::Http2sms.configure do |config| credentials = Rails.application.credentials.ovh_sms config.account = credentials[:account] config.login = credentials[:login] config.password = credentials[:password] config.default_sender = credentials[:default_sender] end ``` -------------------------------- ### OVH HTTP2SMS Deliver Method Response Object (Ruby) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Demonstrates the attributes of the response object returned by the `Ovh::Http2sms.deliver` method. It shows how to check for success or failure, retrieve status codes, SMS IDs, remaining credits, error details, and raw response data. ```ruby response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") response.success? # true/false response.failure? # opposite of success? response.status # API status code (100, 101 = success) response.sms_ids # Array of SMS IDs response.credits_remaining # Remaining SMS credits response.error_message # Error message if failed response.error_type # :missing_parameter, :invalid_parameter, :authentication_error response.raw_response # Raw API response body response.content_type # Response content type ``` -------------------------------- ### Configure OVH HTTP2SMS with Rails Credentials Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Configures the OVH HTTP2SMS client using Rails credentials for secure storage of account details. It sets the account, login, password, and default sender, and assigns the Rails logger for output. This is the recommended approach for managing sensitive information. ```ruby Ovh::Http2sms.configure do |config| # Using Rails credentials (recommended) if Rails.application.credentials.ovh_sms.present? config.account = Rails.application.credentials.dig(:ovh_sms, :account) config.login = Rails.application.credentials.dig(:ovh_sms, :login) config.password = Rails.application.credentials.dig(:ovh_sms, :password) config.default_sender = Rails.application.credentials.dig(:ovh_sms, :default_sender) end config.logger = Rails.logger end ``` -------------------------------- ### Send Full-Featured SMS with OVH HTTP2SMS Gem Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Sends an SMS with various advanced options using the OVH HTTP2SMS gem. This includes specifying a custom sender, scheduling the delivery time, adding a tag, setting the SMS class and encoding, managing the STOP clause, and controlling reply capability. The `deliver` method accepts numerous optional parameters for customization. ```ruby # Full-featured SMS with all options response = Ovh::Http2sms.deliver( to: "33601020304", message: "Your order #12345 has shipped!", sender: "MyShop", # Custom sender name (must be registered with OVH) deferred: Time.now + 3600, # Schedule for 1 hour from now tag: "shipping-notifications", # Custom tag for tracking (max 20 chars) sms_class: 1, # SMS class (0=flash, 1=phone memory, 2=SIM, 3=external) sms_coding: 1, # Encoding (1=GSM 7-bit, 2=Unicode) no_stop: true, # Remove STOP clause for non-commercial SMS sender_for_response: false # Enable reply capability via short code ) ``` -------------------------------- ### Schedule SMS for a Specific Time Today Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Send an SMS at a predetermined time today. This requires setting a Time object for the desired delivery time. ```ruby send_time = Time.new(Time.now.year, Time.now.month, Time.now.day, 14, 30, 0) # 2:30 PM response = Ovh::Http2sms.deliver( to: "33601020304", message: "Lunch is ready!", deferred: send_time ) ``` -------------------------------- ### Error Handling Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Handle specific error types raised by the OVH HTTP2SMS API, providing detailed information about failures. ```APIDOC ## Error Handling ### Description Handle specific error types with detailed information about failures. ### Method `POST` (or equivalent internal method for deliver) ### Endpoint `/fkiene/ovh-http2sms` (Conceptual endpoint for delivery with error handling) ### Request Example ```ruby begin response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") rescue Ovh::Http2sms::ConfigurationError => e # Missing or invalid configuration puts "Configuration error: #{e.message}" # => "Missing required configuration: account, login. Set via Ovh::Http2sms.configure block..." rescue Ovh::Http2sms::AuthenticationError => e # IP not authorized (status 401) puts "Auth error: #{e.message}" puts "Status code: #{e.status_code}" # => 401 # Whitelist your IP in OVH SMS control panel rescue Ovh::Http2sms::MissingParameterError => e # Required parameter missing (status 201) puts "Missing param: #{e.message}" puts "Parameter: #{e.parameter}" rescue Ovh::Http2sms::InvalidParameterError => e # Invalid parameter value (status 202) puts "Invalid param: #{e.message}" puts "Parameter: #{e.parameter}" rescue Ovh::Http2sms::SenderNotFoundError => e # Sender not registered (status 241) puts "Sender error: #{e.message}" puts "Sender: #{e.sender}" # Register sender in OVH SMS control panel rescue Ovh::Http2sms::PhoneNumberError => e # Invalid phone number format puts "Phone error: #{e.message}" puts "Phone number: #{e.phone_number}" # => "abc123" rescue Ovh::Http2sms::MessageLengthError => e # Message exceeds SMS limits puts "Length error: #{e.message}" puts "Encoding: #{e.encoding}" # => :gsm or :unicode puts "Length: #{e.length}" # => 1600 puts "Max length: #{e.max_length}" rescue Ovh::Http2sms::NetworkError => e # HTTP request failed (timeout, connection error) puts "Network error: #{e.message}" puts "Original error: #{e.original_error}" rescue Ovh::Http2sms::ValidationError => e # Parameter validation failed before sending puts "Validation error: #{e.message}" # e.g., "Tag exceeds maximum length of 20 characters" rescue Ovh::Http2sms::ResponseParseError => e # Failed to parse API response puts "Parse error: #{e.message}" puts "Content type: #{e.content_type}" puts "Raw response: #{e.raw_response}" rescue Ovh::Http2sms::Error => e # Base error class for any OVH HTTP2SMS error puts "General error: #{e.message}" puts "Status code: #{e.status_code}" puts "Raw response: #{e.raw_response}" end ``` ``` -------------------------------- ### Enable SMS Replies (Sender for Response) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Configures SMS messages to allow replies by setting `sender_for_response` to `true`. This enables the recipient to reply directly to the sender's short code. ```ruby response = Ovh::Http2sms.deliver( to: "33601020304", message: "Reply YES to confirm", sender_for_response: true # Enables reply capability ) ``` -------------------------------- ### Enable Reply-Enabled SMS Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Configure SMS messages to allow recipients to reply using OVH's short code feature. When enabled, the sender parameter is ignored, and the message appears from an OVH short code. ```ruby # Enable reply capability - recipient can reply to this SMS response = Ovh::Http2sms.deliver( to: "33601020304", message: "Reply YES to confirm your appointment or NO to cancel", sender_for_response: true # Enables reply via OVH short code ) # Note: When sender_for_response is true, the sender parameter is ignored # The SMS will appear from OVH's short code number ``` -------------------------------- ### Rails Integration Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Integrate the OVH HTTP2SMS API with Rails applications using the provided generator, credentials management, and ActiveJob support. ```APIDOC ## Rails Integration ### Description Integrate with Rails applications using the generator, credentials, and ActiveJob. ### Installation #### Generate initializer file ```bash rails g ovh:http2sms:install # This command creates the config/initializers/ovh_http2sms.rb file. ``` ### Configuration Edit the generated `config/initializers/ovh_http2sms.rb` file to set your OVH API credentials and other configuration options. ```ruby # config/initializers/ovh_http2sms.rb Ovh::Http2sms.configure do |config| config.consumer_key = ENV['OVH_CONSUMER_KEY'] config.consumer_secret = ENV['OVH_CONSUMER_SECRET'] config.access_token = ENV['OVH_ACCESS_TOKEN'] config.access_secret = ENV['OVH_ACCESS_SECRET'] config.api_url = ENV['OVH_API_URL'] # e.g., 'https://api.us.ovhcloud.com/1.0' config.default_sender = 'MySenderName' end ``` ### Usage with ActiveJob The OVH HTTP2SMS gem provides an ActiveJob integration for asynchronous message delivery. ```ruby # app/jobs/send_sms_job.rb class SendSmsJob < ApplicationJob queue_as :default def perform(to:, message:, sender: nil) Ovh::Http2sms.deliver( to: to, message: message, sender: sender || Ovh::Http2sms.configuration.default_sender ) end end # Enqueue the job SendSmsJob.perform_later(to: "33601020304", message: "Hello from Rails!") ``` ``` -------------------------------- ### Send SMS and Access Response Data (Ruby) Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Sends an SMS message and provides an object to access delivery status, SMS IDs, remaining credits, and error details. The response object offers methods like `success?`, `failure?`, `status`, `sms_ids`, `credits_remaining`, `error_message`, and `raw_response` for comprehensive data access. ```ruby response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") # Check delivery status response.success? # => true (status 100 or 101) response.failure? # => false response.status # => 100 # Access delivery data response.sms_ids # => ["12345678901"] (array of SMS IDs) response.credits_remaining # => 1987.0 # Error information (when failed) response.error_message # => nil (or error description) response.error_type # => nil (or :missing_parameter, :invalid_parameter, :authentication_error, :sender_not_found) # Raw response for debugging response.raw_response # => '{"status":100,"creditLeft":"1987","SmsIds":["12345678901"]}' response.content_type # => "application/json" # Response codes reference: # 100, 101 = Success # 201 = Missing parameter # 202 = Invalid parameter # 241 = Sender not found # 401 = IP not authorized ``` -------------------------------- ### Analyze SMS Message Content and Properties Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Use `message_info` to analyze SMS content, determining the encoding (GSM or Unicode), character count, and the number of SMS segments required. It also provides remaining characters per segment and maximum characters for commercial and non-commercial messages, accounting for the 'STOP' clause where applicable. ```ruby # Standard GSM message (commercial SMS with STOP clause) info = Ovh::Http2sms.message_info("Hello World! Your order is ready.") # => { # characters: 34, # encoding: :gsm, # sms_count: 1, # remaining: 115, # Characters remaining in this segment # max_single_sms: 149, # Max chars for commercial SMS (160 - 11 for STOP) # non_gsm_chars: [] # } # Message with GSM extension characters (count as 2 chars each) info = Ovh::Http2sms.message_info("Price: €100 [discount]") # => { # characters: 24, # € counts as 2, [ and ] count as 2 each # encoding: :gsm, # sms_count: 1, # remaining: 125, # max_single_sms: 149, # non_gsm_chars: [] # } # Unicode message (emoji forces Unicode encoding) info = Ovh::Http2sms.message_info("Great news! Your package is here! :D") # => { encoding: :gsm, max_single_sms: 149, ... } info = Ovh::Http2sms.message_info("Your order is ready!") # => { # characters: 22, # encoding: :unicode, # sms_count: 1, # remaining: 37, # max_single_sms: 59, # Max chars for commercial Unicode SMS # non_gsm_chars: [""] # } # Non-commercial SMS (no STOP clause, more characters available) info = Ovh::Http2sms.message_info("Your 2FA code is 123456", commercial: false) # => { # characters: 23, # encoding: :gsm, # sms_count: 1, # remaining: 137, # max_single_sms: 160, # Full 160 chars without STOP clause # non_gsm_chars: [] # } ``` -------------------------------- ### Send SMS to Multiple Recipients Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Shows how to send an SMS to multiple recipients simultaneously. The `to` parameter can accept an array of phone numbers or a comma-separated string. ```ruby # As array response = Ovh::Http2sms.deliver( to: ["33601020304", "33602030405", "33603040506"], message: "Team meeting at 3pm" ) # As comma-separated string response = Ovh::Http2sms.deliver( to: "33601020304,33602030405", message: "Team meeting at 3pm" ) ``` -------------------------------- ### Schedule SMS Sending (Deferred) Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Enables sending SMS messages at a future time. The `deferred` parameter can be a Ruby `Time` object or a string in the OVH format 'hhmmddMMYYYY'. ```ruby # Using Ruby Time object response = Ovh::Http2sms.deliver( to: "33601020304", message: "Reminder: Meeting tomorrow", deferred: Time.now + 3600 # 1 hour from now ) # Using OVH format (hhmmddMMYYYY) response = Ovh::Http2sms.deliver( to: "33601020304", message: "Happy New Year!", deferred: "000001012025" # Midnight on Jan 1, 2025 ) ``` -------------------------------- ### SMS Delivery Response Object Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Parse and access SMS delivery response data, including status codes, SMS IDs, and error information. ```APIDOC ## Response Object ### Description Parse and access SMS delivery response data with status codes, SMS IDs, and error information. ### Method `POST` (or equivalent internal method for deliver) ### Endpoint `/fkiene/ovh-http2sms` (Conceptual endpoint for delivery) ### Parameters #### Query Parameters - **to** (string) - Required - The recipient's phone number. - **message** (string) - Required - The message content. ### Request Example ```ruby response = Ovh::Http2sms.deliver(to: "33601020304", message: "Hello!") ``` ### Response #### Success Response (200) - **success?** (boolean) - `true` if the delivery was successful (status 100 or 101). - **failure?** (boolean) - `true` if the delivery failed. - **status** (integer) - The delivery status code. - **sms_ids** (array) - An array of SMS IDs for the delivered messages. - **credits_remaining** (float) - The number of credits remaining after the delivery. - **error_message** (string) - The error message if the delivery failed. - **error_type** (string) - The type of error encountered (e.g., :missing_parameter, :invalid_parameter). - **raw_response** (string) - The raw response from the API for debugging purposes. - **content_type** (string) - The content type of the raw response. #### Response Example ```json { "success?": true, "failure?": false, "status": 100, "sms_ids": ["12345678901"], "credits_remaining": 1987.0, "error_message": null, "error_type": null, "raw_response": "{\"status\":100,\"creditLeft\":\"1987\",\"SmsIds\":[\"12345678901\"]}", "content_type": "application/json" } ``` ### Response Codes Reference - **100, 101**: Success - **201**: Missing parameter - **202**: Invalid parameter - **241**: Sender not found - **401**: IP not authorized ``` -------------------------------- ### Send SMS with Custom Tag for Tracking Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Adds a custom tag to SMS messages for tracking purposes using the `tag` parameter. The tag has a maximum length of 20 characters. ```ruby response = Ovh::Http2sms.deliver( to: "33601020304", message: "Order #12345 confirmed", tag: "order-confirmations" # Max 20 characters ) ``` -------------------------------- ### GSM Compatibility Check Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Check if a message contains only GSM 03.38 compatible characters. This is useful for optimizing SMS costs as GSM encoding is more efficient. ```APIDOC ## Ovh::Http2sms.gsm_compatible? ### Description Check if a message contains only GSM 03.38 compatible characters. This is useful for optimizing SMS costs as GSM encoding is more efficient. ### Method `POST` (or equivalent internal method) ### Endpoint `/fkiene/ovh-http2sms` (Conceptual endpoint for GSM check) ### Parameters #### Request Body - **message** (string) - Required - The message content to check. ### Request Example ```ruby # Standard ASCII characters Ovh::Http2sms.gsm_compatible?("Hello World!") # => true # French characters (accented letters supported in GSM) Ovh::Http2sms.gsm_compatible?("Bonjour! Comment ça va?") # => true # Euro symbol (GSM extension character, valid but counts as 2 chars) Ovh::Http2sms.gsm_compatible?("Price: €100") # => true # Cyrillic characters (requires Unicode) Ovh::Http2sms.gsm_compatible?("Привет мир!") # => false # Emoji (requires Unicode) Ovh::Http2sms.gsm_compatible?("Hello! :D") # => false # Chinese characters (requires Unicode) Ovh::Http2sms.gsm_compatible?("Hello!") # => false # Mixed content - any non-GSM character forces Unicode Ovh::Http2sms.gsm_compatible?("Meeting at 3pm") # => false (emoji requires Unicode) ``` ### Response #### Success Response (200) - **compatible** (boolean) - `true` if the message is GSM compatible, `false` otherwise. #### Response Example ```json { "compatible": true } ``` ``` -------------------------------- ### Check GSM Compatibility of Message Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Determines if a given message string is compatible with the GSM 7-bit encoding. This is useful for optimizing SMS costs, as GSM 7-bit allows for more characters per SMS part than Unicode. The function returns `true` if the message only contains standard GSM characters or specific GSM extension characters (which are counted differently). ```ruby Ovh::Http2sms.gsm_compatible?("Hello World!") # => true Ovh::Http2sms.gsm_compatible?("Привет мир!") # => false Ovh::Http2sms.gsm_compatible?("Price: €100") # => true (€ is GSM extension) ``` -------------------------------- ### ActiveJob Integration for Background SMS Delivery Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Integrates OVH HTTP2SMS delivery with ActiveJob for background processing. It defines a job that retries network errors and handles successful and failed deliveries by logging errors. This ensures reliable SMS sending without blocking the main application thread. ```ruby # ActiveJob integration for background SMS delivery class SmsNotificationJob < ApplicationJob queue_as :default retry_on Ovh::Http2sms::NetworkError, wait: 5.seconds, attempts: 3 def perform(phone_number, message, options = {}) response = Ovh::Http2sms.deliver( to: phone_number, message: message, **options.symbolize_keys ) unless response.success? Rails.logger.error "SMS failed: #{response.error_message}" raise "SMS delivery failed" end end end ``` -------------------------------- ### Deliver SMS Message with Unicode Encoding Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Sends an SMS message using the OVH HTTP2SMS gem. The `sms_coding: 2` option forces Unicode encoding, which supports a wider range of characters but has a lower character limit per SMS part compared to GSM 7-bit encoding. ```ruby response = Ovh::Http2sms.deliver( to: "33601020304", message: "Hello World", sms_coding: 2 # 1 = GSM 7-bit, 2 = Unicode ) ``` -------------------------------- ### Check GSM Compatibility (Ruby) Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Determines if a given message string contains only characters compatible with the GSM 03.38 standard. Returns true for standard ASCII, accented French characters, and some extension characters like the Euro symbol. Returns false for characters requiring Unicode, such as Cyrillic, emojis, or Chinese. ```ruby # Standard ASCII characters Ovh::Http2sms.gsm_compatible?("Hello World!") # => true # French characters (accented letters supported in GSM) Ovh::Http2sms.gsm_compatible?("Bonjour! Comment ça va?") # => true # Euro symbol (GSM extension character, valid but counts as 2 chars) Ovh::Http2sms.gsm_compatible?("Price: €100") # => true # Cyrillic characters (requires Unicode) Ovh::Http2sms.gsm_compatible?("Привет мир!") # => false # Emoji (requires Unicode) Ovh::Http2sms.gsm_compatible?("Hello! :D") # => false # Chinese characters (requires Unicode) Ovh::Http2sms.gsm_compatible?("Hello!") # => false # Mixed content - any non-GSM character forces Unicode Ovh::Http2sms.gsm_compatible?("Meeting at 3pm") # => false (emoji requires Unicode) ``` -------------------------------- ### Send SMS with Custom Sender Name Source: https://github.com/fkiene/ovh-http2sms/blob/main/README.md Allows specifying a custom sender name for SMS messages using the `sender` parameter. The sender name must be pre-registered with OVH. ```ruby response = Ovh::Http2sms.deliver( to: "33601020304", message: "Your order has shipped!", sender: "MyShop" # Must be registered with OVH ) ``` -------------------------------- ### Send Bulk SMS with OVH HTTP2SMS Gem Source: https://context7.com/fkiene/ovh-http2sms/llms.txt Sends SMS messages to multiple recipients using the OVH HTTP2SMS gem. It supports sending to an array of phone numbers or a comma-separated string. The `deliver` method handles bulk sending, and the response object provides the count of sent messages. ```ruby # Send to multiple recipients (array) response = Ovh::Http2sms.deliver( to: ["33601020304", "33602030405", "33603040506"], message: "Team meeting at 3pm today" ) puts "Sent #{response.sms_ids.count} messages" # => "Sent 3 messages" # Send to multiple recipients (comma-separated string) response = Ovh::Http2sms.deliver( to: "33601020304,33602030405", message: "Flash sale starts now!" ) ```