Created
August 14, 2009 21:19
-
-
Save alcides/168111 to your computer and use it in GitHub Desktop.
Sinatra TLA
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<% if @links != nil %> | |
<% if (@links != nil) && (@links["Link"] != nil) %> | |
<div class="adds"> | |
Sponsored by: | |
<ul> | |
<% for link in @links["Link"] %> | |
<li><%= link["BeforeText"][0] %> <a href="<%= link["URL"][0] %>"><%= link["Text"][0] %></a> <%= link["AfterText"][0] %></li> | |
<% end %> | |
</ul> | |
</div> | |
<% else %> | |
<!-- No ads :( --> | |
<% end %> | |
<% else %> | |
<!-- No ads :( --> | |
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'net/http' | |
require 'cgi' | |
require 'xmlsimple' | |
TLA_XML_KEY = "WHATEVER" | |
def tla_get_ads(ref) | |
url = "http://www.text-link-ads.com/xml.php?inventory_key=#{TLA_XML_KEY}&referer="+CGI::escape(ref) | |
requester(url) rescue nil | |
end | |
def requester(url) | |
XmlSimple.xml_in(http_get(url)) | |
end | |
def http_get(url) | |
Net::HTTP.get_response(URI.parse(url)).body.to_s | |
end | |
def fragment_key(name) | |
return "TLA/TIME/#{name}", "TLA/DATA/#{name}" | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'tla' | |
before do | |
@links = tla_get_ads(@request.env['REQUEST_URI']) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment