Class: SMSRetrieve

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

Instance Method Summary collapse

Constructor Details

#initialize(endpoints, username, password) ⇒ SMSRetrieve

Returns a new instance of SMSRetrieve.



15
16
17
18
19
# File 'lib/sms/SMSRetrieve.rb', line 15

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

Instance Method Details

#cancelReceiptNotifications(subscriptionId) ⇒ Object



105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/sms/SMSRetrieve.rb', line 105

def cancelReceiptNotifications(subscriptionId)
  baseurl=@endpoints.getCancelSMSReceiptSubscriptionEndpoint()
  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



20
21
22
# File 'lib/sms/SMSRetrieve.rb', line 20

def getEndpoints
  @endpoints
end

#getPasswordObject



36
37
38
# File 'lib/sms/SMSRetrieve.rb', line 36

def getPassword
  @password
end

#getUsernameObject



28
29
30
# File 'lib/sms/SMSRetrieve.rb', line 28

def getUsername
  @username
end

#retrieveMessages(registrationId, maxBatchSize) ⇒ Object



45
46
47
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
# File 'lib/sms/SMSRetrieve.rb', line 45

def retrieveMessages(registrationId,maxBatchSize)
  baseurl=@endpoints.getRetrieveSMSEndpoint()
  requestProcessor=JSONRequest.new()
  if baseurl.index('{registrationId}')!=nil then
    baseurl=baseurl.gsub('{registrationId}',CGI::escape(registrationId.to_s))
  end
  if baseurl.index('{maxBatchSize}')!=nil then
    baseurl=baseurl.gsub('{maxBatchSize}',CGI::escape(maxBatchSize.to_s))
  end
  rawresponse=requestProcessor.get(baseurl,'application/json', @username, @password)
  response=RetrieveSMSResponse.new()
  if (rawresponse!=nil) && (rawresponse.getContent()!=nil)
    jsondata=JSON.parse(rawresponse.getContent())
    if (jsondata!=nil) && (jsondata['inboundSMSMessageList']!=nil) then
      response.setInboundSMSMessageListJSON(jsondata['inboundSMSMessageList'])
    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



24
25
26
# File 'lib/sms/SMSRetrieve.rb', line 24

def setEndpoints(endpoints)
  @endpoints=endpoints
end

#setPassword(password) ⇒ Object



40
41
42
# File 'lib/sms/SMSRetrieve.rb', line 40

def setPassword(password)
  @password=password
end

#setUsername(username) ⇒ Object



32
33
34
# File 'lib/sms/SMSRetrieve.rb', line 32

def setUsername(username)
  @username=username
end

#subscribeToReceiptNotifications(destinationAddress, notifyURL, criteria, notificationFormat, clientCorrelator, callbackData) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/sms/SMSRetrieve.rb', line 74

def subscribeToReceiptNotifications(destinationAddress,notifyURL,criteria,notificationFormat,clientCorrelator,callbackData)
  baseurl=@endpoints.getSMSReceiptSubscriptionsEndpoint()
  requestProcessor=JSONRequest.new()
  formparameters=FormParameters.new()
  formparameters.put('destinationAddress',destinationAddress)
  formparameters.put('notifyURL',notifyURL)
  formparameters.put('criteria',criteria)
  formparameters.put('notificationFormat',notificationFormat)
  formparameters.put('clientCorrelator',clientCorrelator)
  formparameters.put('callbackData',callbackData)
  postdata=formparameters.encodeParameters()
  rawresponse=requestProcessor.post(baseurl,postdata,'application/json', @username, @password)
  response=SMSMessageReceiptSubscriptionResponse.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