Class: SmsRu
- Inherits:
-
Object
- Object
- SmsRu
- Defined in:
- lib/sms_ru/client.rb,
lib/sms_ru/my.rb,
lib/sms_ru/auth.rb,
lib/sms_ru/data.rb,
lib/sms_ru/coerce.rb,
lib/sms_ru/errors.rb,
lib/sms_ru/events.rb,
lib/sms_ru/version.rb,
lib/sms_ru/webhook.rb,
lib/sms_ru/statuses.rb,
lib/sms_ru/stoplist.rb,
lib/sms_ru/callbacks.rb,
lib/sms_ru/call_check.rb
Overview
Ruby client for the SMS.ru HTTP API (sms.ru/api).
client = SmsRu.new("YOUR_API_ID")
client.deliver("79991234567", "Hello!")
Defined Under Namespace
Modules: Coerce, DeliveryStatus, Events, MessageCollection, Statuses, Webhook Classes: Auth, AuthError, Call, CallCheck, CallCheckResult, CallCheckStatus, Callbacks, ConnectionError, Cost, CostItem, Error, FreeLimit, InsufficientFundsError, Limit, My, ResponseError, SendResult, Sms, Status, Stoplist, StoplistEntry
Constant Summary collapse
- BASE_URL =
Base URL of the SMS.ru HTTP API.
"https://sms.ru"- RETRIABLE =
Transport-level exceptions that warrant a retry.
[ Net::OpenTimeout, Net::ReadTimeout, IOError, EOFError, SocketError, Errno::ECONNREFUSED, Errno::ECONNRESET, Errno::EHOSTUNREACH, OpenSSL::SSL::SSLError ].freeze
- VERSION =
The gem version.
"1.0.0"
Instance Method Summary collapse
-
#auth ⇒ SmsRu::Auth
The authentication sub-resource.
-
#call(phone, ip: "-1", partner_id: nil) ⇒ SmsRu::Call
Requests a flash-call verification: SMS.ru calls the number; the last 4 digits of the calling number (returned as ‘code`) are the code the user enters.
-
#callbacks ⇒ SmsRu::Callbacks
The callbacks sub-resource.
-
#callcheck ⇒ SmsRu::CallCheck
The call-check (incoming-call auth) sub-resource.
-
#cost(to, text = nil, translit: false) ⇒ SmsRu::Cost
Returns the cost and SMS count for a message without sending it.
-
#deliver(to, text = nil, from: nil, time: nil, ttl: nil, daytime: false, translit: false, test: nil, ip: nil, partner_id: nil) ⇒ SmsRu::SendResult
Sends a message.
-
#initialize(api_id, timeout: 30, test: false, retries: 5, from: nil, logger: nil) ⇒ SmsRu
constructor
A new instance of SmsRu.
-
#my ⇒ SmsRu::My
The account-info sub-resource (balance, limit, free_limit, senders).
-
#status(sms_id) ⇒ SmsRu::Status+
Delivery status for one id or an Array of ids.
-
#stoplist ⇒ SmsRu::Stoplist
The stoplist sub-resource.
Constructor Details
#initialize(api_id, timeout: 30, test: false, retries: 5, from: nil, logger: nil) ⇒ SmsRu
Returns a new instance of SmsRu.
24 25 26 27 28 29 30 31 |
# File 'lib/sms_ru/client.rb', line 24 def initialize(api_id, timeout: 30, test: false, retries: 5, from: nil, logger: nil) @api_id = api_id @timeout = timeout @test = test @retries = retries @from = from @logger = logger end |
Instance Method Details
#auth ⇒ SmsRu::Auth
Returns the authentication sub-resource.
109 |
# File 'lib/sms_ru/client.rb', line 109 def auth = @auth ||= Auth.new(method(:request)) |
#call(phone, ip: "-1", partner_id: nil) ⇒ SmsRu::Call
Requests a flash-call verification: SMS.ru calls the number; the last 4 digits of the calling number (returned as ‘code`) are the code the user enters.
101 102 103 |
# File 'lib/sms_ru/client.rb', line 101 def call(phone, ip: "-1", partner_id: nil) Call.build(request("/code/call", **{ phone: phone.to_s, ip:, partner_id: }.compact)) end |
#callbacks ⇒ SmsRu::Callbacks
Returns the callbacks sub-resource.
115 |
# File 'lib/sms_ru/client.rb', line 115 def callbacks = @callbacks ||= Callbacks.new(method(:request)) |
#callcheck ⇒ SmsRu::CallCheck
Returns the call-check (incoming-call auth) sub-resource.
118 |
# File 'lib/sms_ru/client.rb', line 118 def callcheck = @callcheck ||= CallCheck.new(method(:request)) |
#cost(to, text = nil, translit: false) ⇒ SmsRu::Cost
Returns the cost and SMS count for a message without sending it.
75 76 77 78 79 80 |
# File 'lib/sms_ru/client.rb', line 75 def cost(to, text = nil, translit: false) # @type var params: Hash[Symbol, untyped] params = { to: Array(to).join(","), text: text }.compact params[:translit] = 1 if translit Cost.build(request("/sms/cost", **params)) end |
#deliver(to, text = nil, from: nil, time: nil, ttl: nil, daytime: false, translit: false, test: nil, ip: nil, partner_id: nil) ⇒ SmsRu::SendResult
Sends a message.
56 57 58 59 60 61 62 63 64 |
# File 'lib/sms_ru/client.rb', line 56 def deliver(to, text = nil, from: nil, time: nil, ttl: nil, daytime: false, translit: false, test: nil, ip: nil, partner_id: nil) params = { from: from || @from, time:, ttl:, ip:, partner_id: }.compact params[:translit] = 1 if translit params[:daytime] = 1 if daytime params[:test] = 1 if test.nil? ? @test : test add_recipients(params, to, text) SendResult.build(request("/sms/send", **params)) end |
#my ⇒ SmsRu::My
Returns the account-info sub-resource (balance, limit, free_limit, senders).
106 |
# File 'lib/sms_ru/client.rb', line 106 def my = @my ||= My.new(method(:request)) |
#status(sms_id) ⇒ SmsRu::Status+
Delivery status for one id or an Array of ids.
88 89 90 91 |
# File 'lib/sms_ru/client.rb', line 88 def status(sms_id) statuses = Status.build_all(request("/sms/status", sms_id: Array(sms_id).join(","))) sms_id.is_a?(Array) ? statuses : statuses.first end |
#stoplist ⇒ SmsRu::Stoplist
Returns the stoplist sub-resource.
112 |
# File 'lib/sms_ru/client.rb', line 112 def stoplist = @stoplist ||= Stoplist.new(method(:request)) |