Platinum Partner

Ruby Client For Amazon Alexa Site Thumbnail (AST) Service

It's scrappy, but it does the job.


require 'cgi'
require 'openssl'
require 'base64'
require 'open-uri'

access_id = 'YOUR_ACCESS_ID'
secret_id = 'YOUR_SECRET_ID'

source_url = ARGV.first

timestamp = Time.now.strftime("%Y-%m-%dT%H:%M:%SZ")
sig = Base64.encode64(OpenSSL::HMAC::digest(OpenSSL::Digest::Digest.new('SHA1'), secret_id, 'Thumbnail' + timestamp)).strip

url = "http://ast.amazonaws.com/Xino?Action=Thumbnail&AWSAccessKeyId=" + access_id
url << "&Signature=" + CGI.escape(sig)
url << "&Timestamp=" + CGI.escape(timestamp)
url << "&Url=" +  source_url

begin
  doc = open(url).read
rescue
  puts "Could not access AWS"
  exit
end

m = doc.match(/\]+exists=\"true\"\>(.+?)\<\//i)

if m && m[1]
  thumb_url = m[1]
  thumb_url.gsub!(/\&/, '&')
  File.open("#{source_url}.jpg", "w") { |f| f.write open(thumb_url).read }
  puts "Saved to #{source_url}.jpg"
elsif m && m.match(/exists=\"false\"/)
  puts "No thumbnail for #{source_url}"
else
  puts "Error"
end
{{ tag }}, {{tag}},

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}
{{ parent.authors[0].realName || parent.author}}

{{ parent.authors[0].tagline || parent.tagline }}

{{ parent.views }} ViewsClicks
Tweet

{{parent.nComments}}