Class: ISMS::Client

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

Constant Summary collapse

SEND_SMS_URL =
'/isms_send.php'

Instance Method Summary collapse

Constructor Details

#initializeClient

Returns a new instance of Client.

Raises:

  • (RuntimeError)


8
9
10
11
# File 'lib/isms/client.rb', line 8

def initialize
  # Check for username and password
  raise RuntimeError, "Username and password not provided!" unless ISMS.username && ISMS.password
end

Instance Method Details

#send_sms(message_body, phone_no, type = 1) ⇒ Object

Returns Hash of :code and :description code has the error code number description is the error description www.isms.com.my/sms_api.php#SendSMS_Response



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/isms/client.rb', line 19

def send_sms(message_body, phone_no, type = 1)
  request_body = {}
  request_body[:un] = ISMS.username
  request_body[:pwd] = ISMS.password
  request_body[:dstno] = phone_no
  request_body[:msg] = message_body
  request_body[:type] = type

  faraday_response = connection.post do |request|
    request.url SEND_SMS_URL
    request.body = request_body
  end

  parse_response(faraday_response.body)
end