Skip to content

Instantly share code, notes, and snippets.

@alcides
Created August 14, 2009 21:19
Show Gist options
  • Save alcides/168111 to your computer and use it in GitHub Desktop.
Save alcides/168111 to your computer and use it in GitHub Desktop.
Sinatra TLA
<% 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 %>
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
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