Class: IprogSmsApi::Client
- Inherits:
-
Object
- Object
- IprogSmsApi::Client
- Defined in:
- lib/iprog_sms_api/client.rb
Constant Summary collapse
- BASE_URL =
"https://sms.iprogtech.com/api/v1"
Instance Method Summary collapse
- #check_sms_credits ⇒ Object
-
#initialize(api_token:) ⇒ Client
constructor
A new instance of Client.
- #send_sms(phone_number:, message:) ⇒ Object
Constructor Details
#initialize(api_token:) ⇒ Client
Returns a new instance of Client.
9 10 11 |
# File 'lib/iprog_sms_api/client.rb', line 9 def initialize(api_token:) @api_token = api_token end |
Instance Method Details
#check_sms_credits ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/iprog_sms_api/client.rb', line 31 def check_sms_credits uri = URI("#{BASE_URL}/account/sms_credits?api_token=#{@api_token}") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Get.new(uri) response = http.request(request) JSON.parse(response.body) rescue StandardError => e { error: e. } end |
#send_sms(phone_number:, message:) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/iprog_sms_api/client.rb', line 13 def send_sms(phone_number:, message:) uri = URI("#{BASE_URL}/sms_messages") http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = true request = Net::HTTP::Post.new(uri.path, { "Content-Type" => "application/json" }) request.body = { api_token: @api_token, phone_number: phone_number, message: }.to_json response = http.request(request) JSON.parse(response.body) rescue StandardError => e { error: e. } end |