Class: Smspartner::Client
- Inherits:
-
Object
- Object
- Smspartner::Client
- Defined in:
- lib/smspartner/client.rb
Constant Summary collapse
- SEND_SMS_URL =
'https://api.smspartner.fr/v1/send'.freeze
- SMS_STATUS_URL =
'https://api.smspartner.fr/v1/message-status'.freeze
- MY_DATA_URL =
'https://api.smspartner.fr/v1/me'.freeze
- ALLOWED_CONFIG_OVERRIDE =
%i[sandbox sender range_value].freeze
- RANGE_VALUES =
{ premium: 1, low_cost: 2 }.freeze
Instance Method Summary collapse
-
#initialize(config) ⇒ Client
constructor
A new instance of Client.
- #me ⇒ Object
- #send_sms(to:, body:, **config) ⇒ Object
- #sms_status(to:, message_id:, **config) ⇒ Object
Constructor Details
#initialize(config) ⇒ Client
Returns a new instance of Client.
7 8 9 |
# File 'lib/smspartner/client.rb', line 7 def initialize(config) @config = config end |
Instance Method Details
#me ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/smspartner/client.rb', line 38 def me HTTParty.get( MY_DATA_URL, query: { apiKey: @config.api_key }, headers: { content_type: 'application/json' } ).parsed_response end |
#send_sms(to:, body:, **config) ⇒ Object
24 25 26 27 28 29 |
# File 'lib/smspartner/client.rb', line 24 def send_sms(to:, body:, **config) res = send_request(to, body, config) ret = Response.new(res.parsed_response) raise SmsSendError.new(ret) if !ret.success? && config[:raise_on_error] ret end |
#sms_status(to:, message_id:, **config) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/smspartner/client.rb', line 31 def sms_status(to:, message_id:, **config) res = status_request(to, , config) ret = Response.new(res.parsed_response) raise SmsStatusError.new(ret) if !ret.success? && config[:raise_on_error] ret end |