Class: MMSSend
- Inherits:
-
Object
- Object
- MMSSend
- Defined in:
- lib/mms/MMSSend.rb
Instance Method Summary collapse
- #cancelDeliveryNotifications(subscriptionId) ⇒ Object
- #getEndpoints ⇒ Object
- #getPassword ⇒ Object
- #getUsername ⇒ Object
-
#initialize(endpoints, username, password) ⇒ MMSSend
constructor
A new instance of MMSSend.
- #queryDeliveryStatus(senderAddress, requestId) ⇒ Object
- #sendMMS(senderAddress, address, message, attachments, clientCorrelator, notifyURL, senderName, callbackData) ⇒ Object
- #setEndpoints(endpoints) ⇒ Object
- #setPassword(password) ⇒ Object
- #setUsername(username) ⇒ Object
- #subscribeToDeliveryNotifications(senderAddress, clientCorrelator, notifyURL, callbackData) ⇒ Object
Constructor Details
#initialize(endpoints, username, password) ⇒ MMSSend
Returns a new instance of MMSSend.
20 21 22 23 24 |
# File 'lib/mms/MMSSend.rb', line 20 def initialize(endpoints, username, password) @endpoints=endpoints @username=username @password=password end |
Instance Method Details
#cancelDeliveryNotifications(subscriptionId) ⇒ Object
185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 |
# File 'lib/mms/MMSSend.rb', line 185 def cancelDeliveryNotifications(subscriptionId) baseurl=@endpoints.getCancelMMSDeliverySubscriptionEndpoint() 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
25 26 27 |
# File 'lib/mms/MMSSend.rb', line 25 def getEndpoints @endpoints end |
#getPassword ⇒ Object
41 42 43 |
# File 'lib/mms/MMSSend.rb', line 41 def getPassword @password end |
#getUsername ⇒ Object
33 34 35 |
# File 'lib/mms/MMSSend.rb', line 33 def getUsername @username end |
#queryDeliveryStatus(senderAddress, requestId) ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/mms/MMSSend.rb', line 124 def queryDeliveryStatus(senderAddress,requestId) baseurl=@endpoints.getQueryMMSDeliveryEndpoint() 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=MMSSendDeliveryStatusResponse.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 |
#sendMMS(senderAddress, address, message, attachments, clientCorrelator, notifyURL, senderName, callbackData) ⇒ Object
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 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 |
# File 'lib/mms/MMSSend.rb', line 50 def sendMMS(senderAddress,address,,,clientCorrelator,notifyURL,senderName,callbackData) baseurl=@endpoints.getSendMMSEndpoint() 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',) formparameters.put('clientCorrelator',clientCorrelator) formparameters.put('notifyURL',notifyURL) formparameters.put('senderName',senderName) formparameters.put('callbackData',callbackData) postdata=formparameters.encodeParameters() uuid=UUID.new boundary=uuid.generate msg = '\r\nMIME-Version: 1.0\r\n' msg << '\r\n--'+boundary+'\r\n' msg << 'Content-Disposition: form-data; name="root-fields"\r\n' msg << 'Content-Type: application/x-www-form-urlencoded\r\n\r\n' msg << postdata msg << '\r\n' if !=nil then for item in if (item!=nil) && (item.getData!=nil) then msg << '\r\n--'+boundary+'\r\n' =item.getName() if !=nil then msg << 'Content-Disposition: form-data; name="attachments"; filename="'++'"\r\n' else msg << 'Content-Disposition: form-data; name="attachments"\r\n' end msg << 'Content-Transfer-Encoding: base64\r\n' =item.getContentType() =item.getData() if !=nil then msg << 'Content-Type:'++'\r\n' else msg << 'Content-Type: application/octet-stream\r\n' end msg << '\r\n' msg << Base64.encode64().gsub('\n','\r\n') msg << '\r\n' end end end msg << '\r\n--'+boundary+'--\r\n' msg = msg.gsub("\\r", "\r") msg = msg.gsub("\\n", "\n") rawresponse=requestProcessor.postMultipart(baseurl,msg,'application/json', @username, @password, boundary) response=SendMMSResponse.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
29 30 31 |
# File 'lib/mms/MMSSend.rb', line 29 def setEndpoints(endpoints) @endpoints=endpoints end |
#setPassword(password) ⇒ Object
45 46 47 |
# File 'lib/mms/MMSSend.rb', line 45 def setPassword(password) @password=password end |
#setUsername(username) ⇒ Object
37 38 39 |
# File 'lib/mms/MMSSend.rb', line 37 def setUsername(username) @username=username end |
#subscribeToDeliveryNotifications(senderAddress, clientCorrelator, notifyURL, callbackData) ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/mms/MMSSend.rb', line 153 def subscribeToDeliveryNotifications(senderAddress,clientCorrelator,notifyURL,callbackData) baseurl=@endpoints.getMMSDeliverySubscriptionsEndpoint() 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=MMSDeliveryReceiptSubscriptionResponse.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 |