Permalink
Browse files

Result URL parsing

  • Loading branch information...
sam-wan committed Apr 16, 2008
1 parent 670202c commit 2cff0f826aa056fa9aa33905e9d507e343eed415
Showing with 239 additions and 9 deletions.
  1. +8 −1 lib/result.rb
  2. +206 −0 spec/fixtures/result.html
  3. +1 −7 spec/itunes_link_maker_spec.rb
  4. +17 −1 spec/result_spec.rb
  5. +7 −0 spec/spec_helper.rb
View
@@ -1,11 +1,18 @@
class ItunesLinkMaker
class Result
+ URL_ROOT = "http://ax.phobos.apple.com.edgesuite.net"
+
attr_reader :name, :type
def initialize(name, type, display_url)
@name = name
@type = type
- @display_url = display_url
+ @display_url = "#{URL_ROOT}#{display_url}"
+ end
+
+ def url
+ doc = Hpricot(open(@display_url))
+ (doc/'textarea a').first['href']
end
def ==(result)
View
@@ -0,0 +1,206 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
+<HTML>
+ <HEAD>
+ <meta http-equiv="content-type" content="text/html; charset=utf-8">
+ <STYLE TYPE="text/css">
+
+A {
+ text-decoration: none;
+}
+
+A:link {
+ color: #3366cc;
+ text-decoration: none;
+}
+
+A:visited {
+ color: #663399;
+ text-decoration: none;
+}
+
+A:active {
+ color: #cccccc;
+ text-decoration: none;
+}
+
+A:Hover {
+ text-decoration: underline;
+}
+
+BODY, TD, CENTER, P {
+ font-family: Geneva, Verdana, Arial, Helvetica;
+ font-size: 10px;
+ color: #333333;
+}
+
+.body {
+ font-family: Geneva, Verdana, Arial, Helvetica;
+ font-size: 10px;
+ color: #333333;
+}
+
+.content {
+ font-family: Arial, Helvetica, sans-serif;
+ font-size: 11px;
+ font-weight: normal;
+ color: #000000;
+}
+
+.title {
+ font-family: Helvetica, Arial, sans-serif;
+ font-size: 10px;
+ font-weight: normal;
+ color: #000000;
+}
+
+td.searchResults {
+ border-style: solid;
+ border-right-width: 1px;
+ border-color: #cccccc;
+}
+
+div.searchResults {
+ margin: 0px 5px 0px 5px;
+ color: black;
+}
+
+.searchResults a {
+ color: black;
+ text-decoration: none;
+}
+
+.sr_goButton img {
+ vertical-align: middle;
+}
+
+.sr_goButton {
+ float: right;
+ vertical-align: middle;
+}
+
+</style>
+
+ <META NAME="ITMS Link Maker" CONTENT="WebObjects 5.2">
+ <TITLE>ITMS Link Maker</TITLE>
+ </HEAD>
+
+ <BODY BGCOLOR="#FFFFFF">
+ <TABLE HEIGHT="100%" WIDTH="100%">
+ <TR><TD ALIGN=CENTER VALIGN=TOP>
+
+<BR>
+ <BR>
+ <TABLE WIDTH="448" BORDER="0" BORDERCOLOR="#CCCCCC" CELLSPACING="0" CELLPADDING="0">
+ <TR HEIGHT="36">
+ <TD ALIGN="center" WIDTH="721" HEIGHT="36">
+ <img width="721" height="60" alt="" border="0" src="/images/linkmaker/linkmaker.gif">
+
+ </TD>
+ </TR>
+
+
+
+
+ <TR HEIGHT="50">
+ <TD ALIGN="center" VALIGN="middle" WIDTH="721" HEIGHT="50" BACKGROUND="/images/linkmaker/bg_gray.gif"><br>
+ <TABLE CELLSPACING=2 BORDER=0 CELLPADDING=3>
+
+ <TR>
+
+ <TD align="right" VALIGN=TOP>
+ <FONT SIZE="1" FACE="Helvetica,Arial,Geneva,Swiss,SunSans-Regular">
+ Linking To:
+ </font>
+ </TD>
+ <TD VALIGN=TOP>
+ <FONT SIZE="1" FACE="Helvetica,Arial,Geneva,Swiss,SunSans-Regular">
+ The Postal Service - Give Up - Such Great Heights (USA)
+ </font><BR>
+ </TD>
+
+ </TR>
+ <tr>
+ <td align="right" valign=TOP>
+ <font size="1" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular">
+ Link Test:
+ </font>
+ </td>
+ <td valign=top>
+ <font size="1" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular">
+
+ <a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=2522315&id=2522333&s=143441">
+ <img border="0" width="61" height="15" src="http://ax.phobos.apple.com.edgesuite.net/images/badgeitunes61x15dark.gif">
+ </a>
+ </font>
+ </td>
+ </tr>
+ <tr>
+ <td align="right" valign=TOP>
+ <font size="1" face="Helvetica,Arial,Geneva,Swiss,SunSans-Regular">
+
+ Include this where you want<br>
+ the link to appear<br>
+ on your HTML&nbsp;page
+ </font>
+ </td>
+ <td valign=top>
+ <textarea rows="5" cols="67"><a href="http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=2522315&id=2522333&s=143441"><img height="15" width="61" alt="The Postal Service - Give Up - Such Great Heights" src="http://ax.phobos.apple.com.edgesuite.net/images/badgeitunes61x15dark.gif" /></a></textarea>
+
+ </td></tr>
+ <tr><td colspan=2><center><br>
+ <TABLE cellpadding="3" cellspacing="2">
+ <TR><TD>
+ <FONT COLOR="#bbbbbb">Step 1: Enter the song, album, and/or artist to which you wish to link. Click &quot;Search&quot;.</font><BR>
+ <FONT COLOR="#bbbbbb">Step 2: Click the drill down arrow </font>
+ <img SRC="/images/linkmaker/arrow_999999_r.gif" BORDER=0 WIDTH=12 ALT="" HEIGHT=12/>
+
+ <FONT COLOR="#bbbbbb"> associated with a specific link on the page.</FONT><BR>
+ <FONT COLOR="#000000">Step 3: Copy and paste the HTML link into your web page.</FONT><BR>
+ </TD></TR>
+ </TABLE><BR>
+ </center></td></tr>
+
+
+
+
+<TR><TD ALIGN=CENTER colspan=2>
+ <TABLE BORDER=0 WIDTH="75%">
+
+ <TR>
+ <TD>
+ The url in the text box on this page points directly to a deep link within the iTunes Store. When a user clicks on it, iTunes will open and navigate to the correct page. The iTunes graphic is included with the code and resides on Apple's servers; all you have to do is copy and paste. If iTunes is not present, the link will automatically take the user to an iTunes download page.
+ </TD>
+ </TR>
+ </TABLE>
+ </TD>
+
+ </TR>
+ </TABLE>
+ </TD>
+ </TR>
+
+ <TR HEIGHT="28">
+ <TD ALIGN="center" VALIGN="middle" WIDTH="721" HEIGHT="28" BACKGROUND="/images/linkmaker/box_bottom.gif">
+ <a href="javascript:history.go(-1);">
+ Back to Search Results
+ </a> | <a href="javascript:history.go(-2);">
+
+ New Search
+ </a>
+ </TD>
+ </TR>
+ </TABLE><P></P>
+
+ </TD></TR>
+ <TR><TD ALIGN=CENTER>
+ The iTunes Link Maker is provided by Apple as an accommodation only.<br>Apple assumes no responsibility for your use of any links, and makes no representation regarding their accuracy or performance. <br>Nothing shall be construed as permission or a grant by Apple in relation to the use of any artist, track or album name,<br> and you agree that any use by you, or result from your use, shall be solely your responsibility.<br>Apple reserves the right to de-activate links at its sole discretion.
+ <br/><br/>
+
+
+ <!-- <a href="MHITMSLinkGeneratorWrapper.FaqUrl">FAQ</a> | -->
+ <a href="mailto:musicstore@apple.com">Contact Us</a>
+ <BR>Copyright &copy; 2008 Apple Inc. All rights reserved.</td></tr>
+ <img width="1" height="1" src="http://metrics.apple.com/b/ss/applesuperglobal/1/G.6--NS?pageName=iTMS+Link+Picker-US&pccr=true&h5=appleitmsna%2Cappleitmsus&ch=iTMS+Link+Picker&g=http%3A%2F%2Fax.phobos.apple.com.edgesuite.net%2FWebObjects%2FMZStoreServices.woa%2Fwa%2FitmsSearchDisplayUrl%3Fdesc%3DThe%2BPostal%2BService%2B-%2BGive%2BUp%2B-%2BSuch%2BGreat%2BHeights%26WOURLEncoding%3DISO8859_1%26lang%3D1%26url%3Dhttp%253A%252F%252Fphobos.apple.com%252FWebObjects%252FMZStore.woa%252Fwa%252FviewAlbum%253Fi%253D2522315%2526id%253D2522333%2526s%253D143441">
+
+ </BODY>
+</HTML>
@@ -1,10 +1,4 @@
-require File.dirname(__FILE__) + '/../lib/itunes_link_maker.rb'
-
-FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
-
-def read_fixture(file)
- open(File.join(FIXTURES_DIR, file)).read
-end
+require File.dirname(__FILE__) + 'spec_helper.rb'
describe ItunesLinkMaker do
setup do
View
@@ -1,6 +1,10 @@
-require File.dirname(__FILE__) + '/../lib/result.rb'
+require File.dirname(__FILE__) + '/spec_helper.rb'
describe ItunesLinkMaker::Result do
+ setup do
+ @open_result = mock('open result', :read => read_fixture('result.html'))
+ end
+
def create_result(options={})
options = {
:name => 'Such Great Heights',
@@ -43,4 +47,16 @@ def create_result(options={})
r2 = create_result(:display_url => 'Different')
r1.should_not == r2
end
+
+ it "should GET the display page when accessing the url" do
+ r = create_result
+ r.should_receive(:open).with("http://ax.phobos.apple.com.edgesuite.net/WebObjects/MZStoreServices.woa/wa/itmsSearchDisplayUrl?desc=The+Postal+Service+-+Give+Up+-+Such+Great+Heights&WOURLEncoding=ISO8859_1&lang=1&url=http%3A%2F%2Fphobos.apple.com%2FWebObjects%2FMZStore.woa%2Fwa%2FviewAlbum%3Fi%3D2522315%26id%3D2522333%26s%3D143441").and_return(@open_result)
+ r.url
+ end
+
+ it "should return the correct url" do
+ r = create_result
+ r.stub!(:open).and_return(@open_result)
+ r.url.should == 'http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=2522315&id=2522333&s=143441'
+ end
end
View
@@ -0,0 +1,7 @@
+require File.dirname(__FILE__) + '/../lib/itunes_link_maker.rb'
+
+FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
+
+def read_fixture(file)
+ open(File.join(FIXTURES_DIR, file)).read
+end

0 comments on commit 2cff0f8

Please sign in to comment.