Class: SmsOwl

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

Defined Under Namespace

Classes: SmsType

Constant Summary collapse

URL =
URI('https://api.smsowl.in/v1/sms')

Instance Method Summary collapse

Constructor Details

#initialize(accountId, apiKey) ⇒ SmsOwl

Returns a new instance of SmsOwl.



16
17
18
19
# File 'lib/sms_owl.rb', line 16

def initialize(accountId,apiKey)
  @accountId = accountId
  @apiKey = apiKey
end

Instance Method Details

#getCommonArray(dndType, smsType, senderId, to) ⇒ Object



63
64
65
66
67
68
69
70
71
72
# File 'lib/sms_owl.rb', line 63

def getCommonArray(dndType,smsType,senderId,to)
  return {     
      accountId: @accountId,
      apiKey: @apiKey,
      dndType: dndType,
      smsType: smsType,
      senderId: senderId,
      to: to
    }
end

#sendPromotionalSms(senderId, to, message, smsType = SmsOwl::SmsType::NORMAL) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/sms_owl.rb', line 21

def sendPromotionalSms(senderId,to,message,smsType = SmsOwl::SmsType::NORMAL)
  req = Net::HTTP::Post.new(SmsOwl::URL, initheader = {'Content-Type' =>'application/json'})
  data = getCommonArray("promotional",smsType,senderId,to)
  data['message'] = message
  req.body = data.to_json
  res = Net::HTTP.start(URL.hostname, URL.port,
    :use_ssl => URL.scheme == 'https') do |http|
    http.request(req)
  end
  if res.code == '200'
    jsonRes = JSON.parse(res.body)
    if to.kind_of?(Array)
      return jsonRes["smsIds"]
    else
      return jsonRes["smsId"]
    end
  elsif res.code == '400'
    jsonRes = JSON.parse(res.body)
    raise jsonRes['message']
  end
end

#sendTransactionalSms(senderId, to, templateId, placeholderArray) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/sms_owl.rb', line 43

def sendTransactionalSms(senderId,to,templateId,placeholderArray)
  req = Net::HTTP::Post.new(SmsOwl::URL, initheader = {'Content-Type' =>'application/json'})
  data = getCommonArray("transactional","normal",senderId,to)
  data['templateId'] = templateId
  data['placeholders'] = placeholderArray
  req.body = data.to_json
  res = Net::HTTP.start(URL.hostname, URL.port,
    :use_ssl => URL.scheme == 'https') do |http|
    http.request(req)
  end
  if res.code == '200'
    jsonRes = JSON.parse(res.body)
    return jsonRes["smsId"]
  elsif res.code == '400'
    jsonRes = JSON.parse(res.body)
    raise jsonRes['message']
  end
end