Browse files

Sprint is returning html   in the json response that contains the

text message that comes with some photos. This commit implements a
search and replace on the returned message string to replace all POSIX
spaces with regular spaces " ".
Also updated the test suite to include an nbsp in the json response
fixture file.
NOTE: This file is encoded as ASCII-8BIT NOT UTF-8, this is necessary
for the text to be effective.
  • Loading branch information...
1 parent 340a7c6 commit ed782e003ac405fedbf33e4aa582917da5cf20c1 James McGrath committed Jun 4, 2012
Showing with 10 additions and 6 deletions.
  1. +2 −1 lib/mms2r/media/sprint.rb
  2. +1 −1 test/fixtures/sprint-ajax-response-success.json
  3. +7 −4 test/test_pm_sprint_com.rb
View
3 lib/mms2r/media/sprint.rb
@@ -139,7 +139,8 @@ def sprint_process_text(doc)
# message the sender sent with the images
json["Results"].each do |result|
type = 'text/plain'
- text = result["description"] ? result["description"].strip : nil
+ # remove any   chars from the resulting text
+ text = result["description"] ? result["description"].gsub(/[[:space:]]/, " ").strip : nil
next if text.empty?
type, text = transform_text(type, text)
type, file = sprint_write_file(type, text.strip)
View
2 test/fixtures/sprint-ajax-response-success.json
@@ -1 +1 @@
-{"totalMediaItems":1,"shareType":"normal","nomediaItem":"false","isOnlyVideo":null,"creationDate":"Apr 16, 2012","from":"(513)545-5510","offset":null,"externalMessageId":"GEc4YYms2Y7KAkmhaoFL","Results":[{"elementID":"2","hasVoiceCaption":false,"URL":{"elementID":"2","indexCount":0,"audio":null,"thumb":"http:\/\/pictures.sprintpcs.com:80\/mmps\/031_36415d1a9c3c73f0_1\/2.jpg?partExt=.jpg&&&outquality=90&ext=.jpg&&size=40,40&squareoutput=255,255,255&aspectcrop=0.5,0.5,1.0,1.0,1.0","annotationVoiceID":null,"image":"http:\/\/pictures.sprintpcs.com:80\/mmps\/031_36415d1a9c3c73f0_1\/2.jpg?partExt=.jpg&&&outquality=90&ext=.jpg","video":null},"description":"Just testing the caption on Sprint","mediaItemNum":0,"isDRMProtected":false,"externalMessageId":"GEc4YYms2Y7KAkmhaoFL","mediaType":"IMAGE","restOperation":"false","folderFullName":"\/RECIPIENT"}],"invite":null,"tmemo":null,"toAddress":"submit@CapStory.com","mediaIndex":0,"subject":"New Message","isDRMProtected":false,"expirationDate":"Expires in 18 days","voiceURL":null,"guest":"true","folderFullName":"\/RECIPIENT"}
+{"totalMediaItems":2,"shareType":"normal","nomediaItem":"false","isOnlyVideo":null,"creationDate":"May 31, 2012","from":"(513)545-0000","offset":null,"externalMessageId":"XXXXXXXXXXXXXXXXXX","Results":[{"elementID":"0","hasVoiceCaption":false,"URL":{"elementID":"0","indexCount":0,"audio":null,"thumb":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","annotationVoiceID":null,"image":"\/retailers\/PCSNEXTEL\/ui-refresh\/images\/background\/slide_no_media_90x90.gif","video":null},"description":"First text content. ","mediaItemNum":0,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"TEXT","restOperation":"false","folderFullName":"\/RECIPIENT"},{"elementID":"3","hasVoiceCaption":false,"URL":{"elementID":"3","indexCount":1,"audio":"","thumb":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg&&size=40,40&squareoutput=255,255,255&aspectcrop=0.5,0.5,1.0,1.0,1.0","annotationVoiceID":null,"image":"http:\/\/pictures.sprintpcs.com:80\/mmps\/048_0736849c3f1a9d27_1\/3.jpg?partExt=.jpg&&&outquality=90&ext=.jpg","video":""},"description":"Second text content. ","mediaItemNum":1,"isDRMProtected":false,"externalMessageId":"XXXXXXXXXXXXXXXXXX","mediaType":"IMAGE","restOperation":"false","folderFullName":"\/RECIPIENT"}],"invite":null,"tmemo":null,"toAddress":"textinsubmit@gmail.com","mediaIndex":0,"subject":"New Message","isDRMProtected":false,"expirationDate":"Expires in 57 Days","voiceURL":null,"guest":"true","folderFullName":"\/RECIPIENT"}
View
11 test/test_pm_sprint_com.rb
@@ -239,12 +239,15 @@ def test_message_is_missing_in_mail
mock_sprint_ajax
mms = MMS2R::Media.new(mail)
- assert_equal 1, mms.media['text/plain'].size
-
+ assert_equal 2, mms.media['text/plain'].size
+
# test that the message was extracted from the ajax response
message = IO.readlines(mms.media['text/plain'].first).join("")
- assert_equal "Just testing the caption on Sprint", message
-
+ assert_equal "First text content.", message
+
+ # test that the   was removed ()
+ assert message.last.bytes.to_a != [194, 160]
+
mms.purge
end

0 comments on commit ed782e0

Please sign in to comment.