A
Andy
Hi guys, I'm very new to this Ruby language.
I only have basic experience of creating Intranet applications using ASP
and an MS Access Database.
I'm trying to adapt some code from the www.Alexa.com 's example code but
don't know if what I'm trying to attempt is out of my depth.
In its simplicisty this is what i'm trying to achieve,
connecting to an access database to return the web addresses for 1,000
firms, using the following Ruby code to query Alexa statistics and then
insert the result back into the access database.
#/usr/bin/ruby
require "cgi"
require "base64"
require "openssl"
require "digest/sha1"
require "uri"
require "net/https"
require "rexml/document"
require "time"
ACCESS_KEY_ID = "--- Replace with your access key id ---"
SECRET_ACCESS_KEY = "--- Replace with your secret access key ---"
action = "UrlInfo"
responseGroup = "Rank"
url = "yahoo.com"
timestamp = ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
signature = Base64.encode64( OpenSSL::HMAC.digest(
OpenSSL:igest:igest.new( "sha1" ), SECRET_ACCESS_KEY, action +
timestamp)).strip
url = URI.parse(
"http://awis.amazonaws.com/onca/xml?" +
{
"Action" => action,
"AWSAccessKeyId" => ACCESS_KEY_ID,
"Signature" => signature,
"Timestamp" => timestamp,
"ResponseGroup" => responseGroup,
"Url" => url
}.to_a.collect{|item| item.first + "=" +
CGI::escape(item.last) }.join("&") # Put key value pairs into http
GET format
)
print "\n\nRequest:\n\n"
print url
xml = REXML:ocument.new( Net::HTTP.get(url) )
print "\n\nResponse:\n\n"
xml.write
Any help would be greatly appreciated ....
Cheers Andy
I only have basic experience of creating Intranet applications using ASP
and an MS Access Database.
I'm trying to adapt some code from the www.Alexa.com 's example code but
don't know if what I'm trying to attempt is out of my depth.
In its simplicisty this is what i'm trying to achieve,
connecting to an access database to return the web addresses for 1,000
firms, using the following Ruby code to query Alexa statistics and then
insert the result back into the access database.
#/usr/bin/ruby
require "cgi"
require "base64"
require "openssl"
require "digest/sha1"
require "uri"
require "net/https"
require "rexml/document"
require "time"
ACCESS_KEY_ID = "--- Replace with your access key id ---"
SECRET_ACCESS_KEY = "--- Replace with your secret access key ---"
action = "UrlInfo"
responseGroup = "Rank"
url = "yahoo.com"
timestamp = ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
signature = Base64.encode64( OpenSSL::HMAC.digest(
OpenSSL:igest:igest.new( "sha1" ), SECRET_ACCESS_KEY, action +
timestamp)).strip
url = URI.parse(
"http://awis.amazonaws.com/onca/xml?" +
{
"Action" => action,
"AWSAccessKeyId" => ACCESS_KEY_ID,
"Signature" => signature,
"Timestamp" => timestamp,
"ResponseGroup" => responseGroup,
"Url" => url
}.to_a.collect{|item| item.first + "=" +
CGI::escape(item.last) }.join("&") # Put key value pairs into http
GET format
)
print "\n\nRequest:\n\n"
print url
xml = REXML:ocument.new( Net::HTTP.get(url) )
print "\n\nResponse:\n\n"
xml.write
Any help would be greatly appreciated ....
Cheers Andy