Permalink
Browse files

Merge remote-tracking branch 'jpmcgrath/master' into sprint_json

  • Loading branch information...
2 parents 66e5da4 + e8df44f commit 863321921d59feb3654220ca711af1d0319fef4d @monde committed May 31, 2012
View
@@ -7,6 +7,7 @@
require 'net/http'
require 'nokogiri'
require 'cgi'
+require 'json'
module MMS2R
@@ -105,30 +106,48 @@ def sprint_process_text(doc)
type, file = sprint_write_file(type, text.strip)
add_file(type, file) unless type.nil? || file.nil?
end
-
# if no text was found, there still might be a message with images
# that can be seen at the end of the "View Entire Message" link
if !text_found
- # Sprint uses AJAX/josn to serve up the content at the end of the link so this is conveluted
view_entire_message_link = doc.search("a").find { |link| link.inner_html == "View Entire Message"}
- url = view_entire_message_link.attr("href")
- # extract the "invite" param out of the url - this will be the id we pass to the ajax path below
- inviteMessageId = CGI::parse(URI::parse(url).query)["invite"].first
- json_url = "http://pictures.sprintpcs.com/ui-refresh/guest/getMessageContainerJSON.do%3FcomponentType%3DmediaDetail&invite=#{inviteMessageId}&externalMessageId=#{inviteMessageId}"
- # pull down the json from the url and parse it
- json_response = Net::HTTP.get_response(URI.parse(json_url))
- json = JSON.parse(json_response.body)
-
- # there may be multiple "results" in the json - due to multiple images
- # cycle through them and extract the "description" which is the text
- # message the sender sent with the images
- json["Results"].each do |result|
- type = 'text/plain'
- text = result["description"] ? result["description"].strip : nil
- next if text.empty?
- type, text = transform_text(type, text)
- type, file = sprint_write_file(type, text.strip)
- add_file(type, file) unless type.nil? || file.nil?
+ # if we can't find the view entire message link, give up
+ if view_entire_message_link
+ # Sprint uses AJAX/json to serve up the content at the end of the link so this is conveluted
+ url = view_entire_message_link.attr("href")
+ # extract the "invite" param out of the url - this will be the id we pass to the ajax path below
+ inviteMessageId = CGI::parse(URI::parse(url).query)["invite"].first
+
+ if inviteMessageId
+ json_url = "http://pictures.sprintpcs.com/ui-refresh/guest/getMessageContainerJSON.do%3FcomponentType%3DmediaDetail&invite=#{inviteMessageId}&externalMessageId=#{inviteMessageId}"
+ # pull down the json from the url and parse it
+ uri = URI.parse(json_url)
+ connection = Net::HTTP.new(uri.host, uri.port)
+ response = connection.get2(
+ uri.request_uri,
+ { "User-Agent" => MMS2R::Media::USER_AGENT }
+ )
+ content = response.body
+
+ # if the content has expired, sprint sends back html "content expired page
+ # json will fail to parse
+ begin
+ json = JSON.parse(content)
+
+ # there may be multiple "results" in the json - due to multiple images
+ # cycle through them and extract the "description" which is the text
+ # message the sender sent with the images
+ json["Results"].each do |result|
+ type = 'text/plain'
+ text = result["description"] ? result["description"].strip : nil
+ next if text.empty?
+ type, text = transform_text(type, text)
+ type, file = sprint_write_file(type, text.strip)
+ add_file(type, file) unless type.nil? || file.nil?
+ end
+ rescue JSON::ParserError => e
+ log("#{self.class} processing error, #{$!}", :error)
+ end
+ end
end
end
end
@@ -182,7 +201,6 @@ def sprint_process_media(doc)
log("#{self.class} processing error, #{$!}", :error)
next
end
-
# if the Sprint content server uses response code 500 when the content is purged
# the content type will text/html and the body will be the message
if response.content_type == 'text/html' && response.code == "500"
@@ -0,0 +1,173 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
+
+<head>
+
+
+
+ <meta name="ROBOTS" content="NOINDEX,NOFOLLOW"/>
+ <title>Pictures from Sprint</title>
+ <link rel="shortcut icon" type="image/x-icon" href="/retailers/PCSNEXTEL/ui-refresh/images/icons/favicon.ico"/>
+ <link rel="stylesheet" type="text/css" href="/combined.css.h-968716942.pack" charset="utf-8"/>
+
+
+
+
+
+
+
+
+
+
+
+ <link rel="stylesheet" type="text/css" href="/combined.css.h-865380446.pack" charset="utf-8"/>
+
+
+<script type="text/javascript" src="/combined.js.h2135702050.pack" charset="utf-8"></script>
+<script type="text/javascript" src="/js/ui-refresh/jsprops.jsp"></script>
+
+</head>
+<body class="yui-skin-sam" onload=";javascript:YAHOO.com.sprint.pm.util.functions.isLoginPageLoadedIntoIframe();" onunload="">
+
+
+<div id="com-sprint-pm-panel-container" class="com-sprint-pm-panel-container"></div>
+
+<div id="com-xoom-widget-result-dialog"></div>
+
+<div id="custom-doc" class="yui-t7">
+
+
+
+ <div id="hd">
+
+
+
+
+
+
+
+
+
+
+
+<div id="com-sprint-pm-brand"><a href="http://www.sprintpcs.com" target="_blank"></a></div>
+
+<div class="yui-g">
+ <img src="/retailers/PCSNEXTEL/ui-refresh/images/sprint-nav.gif" width="963" height="57" alt="Sprint Navigation" usemap="#sprint_nav_Map"/>
+</div>
+
+
+
+
+
+<map id="sprint_nav_Map" name="sprint_nav_Map">
+ <area shape="rect" title="Support" alt="Support" coords="537,15,620,44" href="http://support.sprint.com/support" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();"/>
+ <area shape="rect" title="Community" alt="Community" coords="429,15,533,44" href="http://community.sprint.com/" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();"/>
+ <area shape="rect" title="Digital Lounge" alt="Digital Lounge" coords="305,15,425,44" href="http://www.sprint.com/digitallounge" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();"/>
+ <area shape="rect" title="Shop" alt="Shop" coords="230,15,300,44" href="http://www.nextel.com/en/shop/" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();"/>
+ <area shape="rect" title="My Sprint" alt="My Sprint" coords="137,15,225,44" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();" href="https://mysprint.sprint.com/mysprint/pages/secure/myaccount/landingPage.jsp"/>
+ <area shape="rect" title="Sprint.com" alt="Sprint.com" coords="0,0,110,44" onclick="javascript:YAHOO.com.sprint.pm.util.functions.removeSSOCookie();" href="http://www.sprint.com"/>
+</map>
+</div>
+
+ <div id="bd">
+ <div id="yui-main">
+
+
+
+
+
+
+
+ <div class="yui-navset">
+ <ul class="yui-nav"><li class="yui-li-empty-tab-nav"></li></ul>
+ <div class="yui-content">
+ <div id="com-sprint-pm-configurable-content-holder" class="yui-g">
+
+<div class="com-sprint-pm-one-panel-box">
+ <div class="com-sprint-pm-one-panel-content">
+ <div class="com-sprint-pm-title-heading"><img src="/retailers/PCSNEXTEL/ui-refresh/images/title/title_error.gif"/></div><br/><br/>
+ <div>Sorry, but the shared album or picture has been removed by its owner.</div><br/>
+ </div>
+</div>
+
+ <div class="com-sprint-pm-one-panel-verisign-logo">
+</div>
+ </div>
+ </div>
+ </div>
+
+ </div><!-- /yui-main -->
+ </div> <!-- close bd -->
+
+ <div id="ft">
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+<div id="com-sprint-pm-footer" >
+ <div class="yui-ge">
+ <div class="yui-u first">
+ <ul id="com-sprint-pm-footerLinks">
+ <li>Order by phone 1-800-2-SPRINT</li>
+ <li><a href="http://www2.sprint.com/mr/aboutsprint.do" target="_blank" title="About Us">About Us</a></li>
+ <li><a href="http://www.sprint.com/contactus/" target="_blank" title="Contact Us">Contact Us</a></li>
+ <li><a href="http://www.sprint.com/legal/picturemail_terms_and_conditions.html" target="_blank" title="Terms of Use">Terms of Use</a></li>
+ <li class="pm-last"><a href="http://www.sprint.com/legal/privacy.html" target="_blank" title="Privacy Policy">Privacy Policy</a></li>
+ </ul>
+ </div>
+ <div class="yui-u" id="com-sprint-pm-copyright">
+ &copy; 2012 Sprint. All rights reserved.<br/>
+ </div>
+ </div>
+
+
+
+<script type="text/javascript" src="/combined.js.h845901428.pack" charset="utf-8"></script>
+<script type="text/javascript"> _uacct = "UA-822828-4"; _udn=".sprintpcs.com"; YAHOO.com.sprint.pm.util.functions.urchinTracker(); </script>
+
+
+ </div>
+
+</div> <!-- close custom-doc -->
+</body>
+
+
+
+
+</html>
@@ -0,0 +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"}
Oops, something went wrong.

0 comments on commit 8633219

Please sign in to comment.