Class: MMSRetrieve
- Inherits:
-
Object
- Object
- MMSRetrieve
- Defined in:
- lib/mms/MMSRetrieve.rb
Instance Method Summary collapse
- #cancelReceiptNotifications(subscriptionId) ⇒ Object
- #getEndpoints ⇒ Object
- #getPassword ⇒ Object
- #getUsername ⇒ Object
-
#initialize(endpoints, username, password) ⇒ MMSRetrieve
constructor
A new instance of MMSRetrieve.
- #retrieveMessageContent(registrationId, messageId, resFormat) ⇒ Object
- #retrieveMessages(registrationId, maxBatchSize) ⇒ Object
- #setEndpoints(endpoints) ⇒ Object
- #setPassword(password) ⇒ Object
- #setUsername(username) ⇒ Object
- #subscribeToReceiptNotifications(destinationAddress, notifyURL, criteria, notificationFormat, clientCorrelator, callbackData) ⇒ Object
Constructor Details
#initialize(endpoints, username, password) ⇒ MMSRetrieve
Returns a new instance of MMSRetrieve.
19 20 21 22 23 |
# File 'lib/mms/MMSRetrieve.rb', line 19 def initialize(endpoints, username, password) @endpoints=endpoints @username=username @password=password end |
Instance Method Details
#cancelReceiptNotifications(subscriptionId) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/mms/MMSRetrieve.rb', line 178 def cancelReceiptNotifications(subscriptionId) baseurl=@endpoints.getCancelMMSReceiptSubscriptionEndpoint() 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 |
#getEndpoints ⇒ Object
24 25 26 |
# File 'lib/mms/MMSRetrieve.rb', line 24 def getEndpoints @endpoints end |
#getPassword ⇒ Object
40 41 42 |
# File 'lib/mms/MMSRetrieve.rb', line 40 def getPassword @password end |
#getUsername ⇒ Object
32 33 34 |
# File 'lib/mms/MMSRetrieve.rb', line 32 def getUsername @username end |
#retrieveMessageContent(registrationId, messageId, resFormat) ⇒ Object
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 104 105 106 107 108 109 110 111 112 113 114 115 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 |
# File 'lib/mms/MMSRetrieve.rb', line 78 def retrieveMessageContent(registrationId,,resFormat) baseurl=@endpoints.getRetrieveMMSMessageEndpoint() requestProcessor=JSONRequest.new() if baseurl.index('{registrationId}')!=nil then baseurl=baseurl.gsub('{registrationId}',CGI::escape(registrationId.to_s)) end if baseurl.index('{messageId}')!=nil then baseurl=baseurl.gsub('{messageId}',CGI::escape(.to_s)) end if baseurl.index('{resFormat}')!=nil then baseurl=baseurl.gsub('{resFormat}',CGI::escape(resFormat.to_s)) end rawresponse=requestProcessor.get(baseurl,'application/json', @username, @password) response=RetrieveMMSMessageResponse.new() if (rawresponse!=nil) && (rawresponse.getContent()!=nil) then mimecontent="Content-Type: "+rawresponse.getContentType()+'\r\n\r\n'+rawresponse.getContent() mimemsg=Mail.read_from_string(mimecontent.gsub("\\t","\t").gsub("\\n","\n").gsub("\\r","\r").gsub("\\\"","\"")) response=RetrieveMMSMessageResponse.new() =nil for part in mimemsg.parts contentType=part.content_type.strip if (contentType.index(";")!=nil) ct=contentType.split(";") contentType=ct[0].strip end filename=nil contentDisposition=part.content_disposition if (contentDisposition!=nil) cdp=contentDisposition.split(";") for cvp in cdp kv=cvp.split("=") if kv[0].strip=="name" filename=kv[1].gsub("\"","").strip end end end if contentType!='multipart/mixed' payload=part.body.to_s if (contentType!=nil) && (contentType=='application/json') && (filename!=nil) && (filename=="root-fields") && (payload!=nil) jsondata=JSON.parse(payload) if (jsondata!=nil) && (jsondata['inboundMessage']!=nil) response.setInboundMessage(jsondata['inboundMessage']) end else =Attachment.new .setContentType(contentType) .setName(filename) .setData(payload) if ==nil =Array.new end [.length]= end end end response.setAttachment() 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 |
#retrieveMessages(registrationId, maxBatchSize) ⇒ Object
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 |
# File 'lib/mms/MMSRetrieve.rb', line 49 def retrieveMessages(registrationId,maxBatchSize) baseurl=@endpoints.getRetrieveMMSEndpoint() 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=RetrieveMMSResponse.new() if (rawresponse!=nil) && (rawresponse.getContent()!=nil) jsondata=JSON.parse(rawresponse.getContent()) if (jsondata!=nil) && (jsondata['inboundMessageList']!=nil) then response.setInboundMessageListJSON(jsondata['inboundMessageList']) 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
28 29 30 |
# File 'lib/mms/MMSRetrieve.rb', line 28 def setEndpoints(endpoints) @endpoints=endpoints end |
#setPassword(password) ⇒ Object
44 45 46 |
# File 'lib/mms/MMSRetrieve.rb', line 44 def setPassword(password) @password=password end |
#setUsername(username) ⇒ Object
36 37 38 |
# File 'lib/mms/MMSRetrieve.rb', line 36 def setUsername(username) @username=username end |
#subscribeToReceiptNotifications(destinationAddress, notifyURL, criteria, notificationFormat, clientCorrelator, callbackData) ⇒ Object
147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
# File 'lib/mms/MMSRetrieve.rb', line 147 def subscribeToReceiptNotifications(destinationAddress,notifyURL,criteria,notificationFormat,clientCorrelator,callbackData) baseurl=@endpoints.getMMSReceiptSubscriptionsEndpoint() 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=MMSMessageReceiptSubscriptionResponse.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 |