Class: SMSSend

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

Instance Method Summary collapse

Constructor Details

#initialize(endpoints, username, password) ⇒ SMSSend

Returns a new instance of SMSSend.



18
19
20
21
22
# File 'lib/sms/SMSSend.rb', line 18

def initialize(endpoints, username, password)
  @endpoints=endpoints
  @username=username
  @password=password
end

Instance Method Details

#cancelDeliveryNotifications(subscriptionId) ⇒ Object



148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
# File 'lib/sms/SMSSend.rb', line 148

def cancelDeliveryNotifications(subscriptionId)
  baseurl=@endpoints.getCancelSMSDeliverySubscriptionEndpoint()
  requestProcessor=JSONRequest.new()
  if baseurl.index('{subscriptionId}')!=nil then
    baseurl=baseurl.gsub('{subscriptionId}',CGI::escape(subscriptionId.to_s))
  end
  rawresponse=requestProcessor.delete(baseurl,@username,@password)
  response=HTTPResponse.new()
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#getEndpointsObject



23
24
25
# File 'lib/sms/SMSSend.rb', line 23

def getEndpoints
  @endpoints
end

#getPasswordObject



39
40
41
# File 'lib/sms/SMSSend.rb', line 39

def getPassword
  @password
end

#getUsernameObject



31
32
33
# File 'lib/sms/SMSSend.rb', line 31

def getUsername
  @username
end

#queryDeliveryStatus(senderAddress, requestId) ⇒ Object



87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/sms/SMSSend.rb', line 87

def queryDeliveryStatus(senderAddress,requestId)
  baseurl=@endpoints.getQuerySMSDeliveryEndpoint()
  requestProcessor=JSONRequest.new()
  if baseurl.index('{senderAddress}')!=nil then
    baseurl=baseurl.gsub('{senderAddress}',CGI::escape(senderAddress.to_s))
  end
  if baseurl.index('{requestId}')!=nil then
    baseurl=baseurl.gsub('{requestId}',CGI::escape(requestId.to_s))
  end
  rawresponse=requestProcessor.get(baseurl,'application/json', @username, @password)
  response=SMSSendDeliveryStatusResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['deliveryInfoList']!=nil) then
      response.setDeliveryInfoListJSON(jsondata['deliveryInfoList'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#sendSMS(senderAddress, address, message, clientCorrelator, notifyURL, senderName, callbackData) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# File 'lib/sms/SMSSend.rb', line 48

def sendSMS(senderAddress,address,message,clientCorrelator,notifyURL,senderName,callbackData)
  baseurl=@endpoints.getSendSMSEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('senderAddress',senderAddress)
  if baseurl.index('{senderAddress}')!=nil then
    baseurl=baseurl.gsub('{senderAddress}',CGI::escape(senderAddress.to_s))
  end
  if address!=nil
    for item in address
      formparameters.put('address',item)
    end
  end
  formparameters.put('message',message)
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('notifyURL',notifyURL)
  formparameters.put('senderName',senderName)
  formparameters.put('callbackData',callbackData)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=SendSMSResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['resourceReference']!=nil) then
      response.setResourceReferenceJSON(jsondata['resourceReference'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end

#setEndpoints(endpoints) ⇒ Object



27
28
29
# File 'lib/sms/SMSSend.rb', line 27

def setEndpoints(endpoints)
  @endpoints=endpoints
end

#setPassword(password) ⇒ Object



43
44
45
# File 'lib/sms/SMSSend.rb', line 43

def setPassword(password)
  @password=password
end

#setUsername(username) ⇒ Object



35
36
37
# File 'lib/sms/SMSSend.rb', line 35

def setUsername(username)
  @username=username
end

#subscribeToDeliveryNotifications(senderAddress, clientCorrelator, notifyURL, callbackData) ⇒ Object



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# File 'lib/sms/SMSSend.rb', line 116

def subscribeToDeliveryNotifications(senderAddress,clientCorrelator,notifyURL,callbackData)
  baseurl=@endpoints.getSMSDeliverySubscriptionsEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('senderAddress',senderAddress)
  if baseurl.index('{senderAddress}')!=nil then
    baseurl=baseurl.gsub('{senderAddress}',CGI::escape(senderAddress.to_s))
  end
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('notifyURL',notifyURL)
  formparameters.put('callbackData',callbackData)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=SMSDeliveryReceiptSubscriptionResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['deliveryReceiptSubscription']!=nil) then
      response.setDeliveryReceiptSubscriptionJSON(jsondata['deliveryReceiptSubscription'])
    end
  end
  if rawresponse.getCode()!=nil then
    response.setHTTPResponseCode(rawresponse.getCode())
  end
  if rawresponse.getLocation()!=nil then
    response.setLocation(rawresponse.getLocation())
  end
  if rawresponse.getContentType()!=nil then
    response.setContentType(rawresponse.getContentType())
  end
  return response
end