awis4ruby 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.txt +4 -0
- data/Manifest.txt +8 -0
- data/README.txt +60 -0
- data/Rakefile +19 -0
- data/bin/awis4ruby +0 -0
- data/lib/awis4ruby.rb +126 -0
- data/lib/url_info.rb +55 -0
- data/test/test_awis4ruby.rb +0 -0
- metadata +64 -0
data/History.txt
ADDED
data/Manifest.txt
ADDED
data/README.txt
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
awis4ruby
|
2
|
+
by VotanWeb
|
3
|
+
http://labs.votanweb.com/awis4ruby/
|
4
|
+
|
5
|
+
== DESCRIPTION:
|
6
|
+
|
7
|
+
AWIS4Ruby simplifies accessing the Alexa Web Information Service by
|
8
|
+
encapsulating all of the network connections and XML parsing into an
|
9
|
+
incredibly easy to use interface.
|
10
|
+
|
11
|
+
== FEATURES/PROBLEMS:
|
12
|
+
|
13
|
+
* Up-to-date Ruby client
|
14
|
+
* Allows simple access to most popular AWIS data
|
15
|
+
|
16
|
+
== SYNOPSIS:
|
17
|
+
|
18
|
+
ACCESS_KEY_ID = "05RTY5ESSE0EDGR68G2"
|
19
|
+
SECRET_ACCESS_KEY = "1tmO+Tgvp0YU/ZOTwUTRYui7JppEc/lSMSD"
|
20
|
+
host = 'votanweb.com'
|
21
|
+
info = AWIS4Ruby::get_url_info(ACCESS_KEY_ID, SECRET_ACCESS_KEY, host)
|
22
|
+
p info.online_since.strftime('%m-%d-%Y')
|
23
|
+
p info.rank # traffic rank
|
24
|
+
|
25
|
+
== REQUIREMENTS:
|
26
|
+
|
27
|
+
* OpenSSL must be installed
|
28
|
+
* Sign up for an Amazon Web Services account at http://aws.amazon.com
|
29
|
+
* Get your Access Key ID and Secret Access Key
|
30
|
+
* Sign up for the Alexa Web Information Service at http://aws.amazon.com/awis
|
31
|
+
* Tell others about this project
|
32
|
+
|
33
|
+
== INSTALL:
|
34
|
+
|
35
|
+
* sudo gem install awis4ruby --include-dependencies
|
36
|
+
|
37
|
+
== LICENSE:
|
38
|
+
|
39
|
+
(The MIT License)
|
40
|
+
|
41
|
+
Copyright (c) 2007 labs.VotanWeb.com
|
42
|
+
|
43
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
44
|
+
a copy of this software and associated documentation files (the
|
45
|
+
'Software'), to deal in the Software without restriction, including
|
46
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
47
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
48
|
+
permit persons to whom the Software is furnished to do so, subject to
|
49
|
+
the following conditions:
|
50
|
+
|
51
|
+
The above copyright notice and this permission notice shall be
|
52
|
+
included in all copies or substantial portions of the Software.
|
53
|
+
|
54
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
55
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
56
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
57
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
58
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
59
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
60
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- ruby -*-
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'hoe'
|
5
|
+
require './lib/awis4ruby.rb'
|
6
|
+
|
7
|
+
Hoe.new('awis4ruby', AWIS4Ruby::VERSION) do |p|
|
8
|
+
p.rubyforge_name = 'awis4ruby'
|
9
|
+
p.author = 'Jay Owack'
|
10
|
+
p.email = 'owack.j@gmail.com'
|
11
|
+
p.summary = 'Simple Ruby client for the Alexa Web Information Service.'
|
12
|
+
p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
13
|
+
p.url = 'http://labs.votanweb.com/awis4ruby/'
|
14
|
+
# p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
|
15
|
+
# p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
|
16
|
+
p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
|
17
|
+
end
|
18
|
+
|
19
|
+
# vim: syntax=Ruby
|
data/bin/awis4ruby
ADDED
File without changes
|
data/lib/awis4ruby.rb
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
require "cgi"
|
2
|
+
require "base64"
|
3
|
+
require "openssl"
|
4
|
+
require "digest/sha1"
|
5
|
+
require "uri"
|
6
|
+
require "net/https"
|
7
|
+
require "rexml/document"
|
8
|
+
require "time"
|
9
|
+
require File.dirname(__FILE__) + "/url_info"
|
10
|
+
|
11
|
+
module AWIS4Ruby
|
12
|
+
|
13
|
+
VERSION = '0.9.0'
|
14
|
+
|
15
|
+
def self.get_url_info(access_key_id, secret_access_key, url)
|
16
|
+
action = "UrlInfo"
|
17
|
+
responseGroup = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks"
|
18
|
+
timestamp = Time.now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
19
|
+
signature = Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new( "sha1" ), secret_access_key, action + timestamp)).strip
|
20
|
+
awis_url = URI.parse(
|
21
|
+
"http://awis.amazonaws.com/?" +
|
22
|
+
{
|
23
|
+
"Action" => action,
|
24
|
+
"AWSAccessKeyId" => access_key_id,
|
25
|
+
"Signature" => signature,
|
26
|
+
"Timestamp" => timestamp,
|
27
|
+
"ResponseGroup" => responseGroup,
|
28
|
+
"Url" => url
|
29
|
+
}.to_a.collect{|item| item.first + "=" + CGI::escape(item.last) }.join("&") # Put key value pairs into http GET format
|
30
|
+
)
|
31
|
+
resp = Net::HTTP.get(awis_url)
|
32
|
+
|
33
|
+
xml = REXML::Document.new(resp)
|
34
|
+
url_info = AWIS4Ruby::UrlInfo.new
|
35
|
+
url_info.awis_url = awis_url
|
36
|
+
url_info.full_xml = resp
|
37
|
+
url_info.domain_name = domain_from_url(url)
|
38
|
+
## traffic rank
|
39
|
+
url_info.rank = element_int xml.elements["//aws:TrafficData/aws:Rank"]
|
40
|
+
## adult content
|
41
|
+
ac = element_text xml.elements["//aws:ContentData/aws:AdultContent"]
|
42
|
+
if ac.eql?("yes")
|
43
|
+
url_info.adult_content = true
|
44
|
+
else
|
45
|
+
url_info.adult_content = false
|
46
|
+
end
|
47
|
+
## contact info
|
48
|
+
url_info.contact_email = element_text xml.elements["//aws:ContactInfo/aws:Email"]
|
49
|
+
url_info.contact_address = element_text xml.elements["//aws:ContactInfo/aws:PhysicalAddress"]
|
50
|
+
url_info.owner_name = element_text xml.elements["//aws:ContactInfo/aws:OwnerName"]
|
51
|
+
url_info.stock_ticker = element_text xml.elements["//aws:CompanyStockTicker"]
|
52
|
+
xml.elements.each("*//aws:PhoneNumber") do |el|
|
53
|
+
url_info.phone_numbers << el.text if el
|
54
|
+
end
|
55
|
+
## site data
|
56
|
+
url_info.site_title = element_text xml.elements["//aws:SiteData/aws:Title"]
|
57
|
+
url_info.site_description = element_text xml.elements["//aws:SiteData/aws:Description"]
|
58
|
+
ol_since = xml.elements["//aws:SiteData/aws:OnlineSince"]
|
59
|
+
#url_info.online_since = element_text xml.elements["//aws:SiteData/aws:OnlineSince"]
|
60
|
+
if ol_since
|
61
|
+
url_info.online_since = Time.local(*(ParseDate.parsedate(ol_since.text)))
|
62
|
+
end
|
63
|
+
## speed
|
64
|
+
url_info.speed_percentile = element_int xml.elements["//aws:Speed/aws:Percentile"]
|
65
|
+
url_info.load_time = element_int xml.elements["//aws:Speed/aws:MedianLoadTime"]
|
66
|
+
# language
|
67
|
+
url_info.language_locale = element_text xml.elements["//aws:Language/aws:Locale"]
|
68
|
+
url_info.language_encoding = element_text xml.elements["//aws:Language/aws:Encoding"]
|
69
|
+
# links in
|
70
|
+
url_info.links_in_count = element_int xml.elements["//aws:LinksInCount"]
|
71
|
+
# keywords
|
72
|
+
xml.elements.to_a("//aws:Keywords/aws:Keyword").collect do |i|
|
73
|
+
url_info.keywords << i.text if i
|
74
|
+
end
|
75
|
+
# related links
|
76
|
+
xml.elements.to_a("//aws:RelatedLink").collect do |i|
|
77
|
+
my_map = Hash.new
|
78
|
+
if i
|
79
|
+
my_map[:url] = element_text i.elements["aws:NavigableUrl"]
|
80
|
+
my_map[:title] = element_text i.elements["aws:Title"]
|
81
|
+
my_map[:relevance] = element_int i.elements["aws:Relevance"]
|
82
|
+
url_info.related_links << my_map
|
83
|
+
end
|
84
|
+
end
|
85
|
+
|
86
|
+
return url_info
|
87
|
+
end
|
88
|
+
|
89
|
+
|
90
|
+
def self.domain_from_url(url)
|
91
|
+
return url.host if url.class == URI::HTTP
|
92
|
+
if url !~ /^\w+:\/\//
|
93
|
+
url = "http://" + url
|
94
|
+
end
|
95
|
+
uri = URI.parse(url)
|
96
|
+
host = uri.host.downcase
|
97
|
+
if(host =~ /^[\w\.-]+\.(\w+\.\w\w\.\w\w)$/) # www.bulldogbreeds.co.uk
|
98
|
+
domain = $1
|
99
|
+
elsif(host =~ /^[\w\.-]+\.(\w+\w\w\.\w\w+)$/) # www.bulldogbreeds.com
|
100
|
+
domain = $1
|
101
|
+
else
|
102
|
+
domain = host
|
103
|
+
end
|
104
|
+
return domain
|
105
|
+
end
|
106
|
+
|
107
|
+
|
108
|
+
def self.element_text(el)
|
109
|
+
if el then el.text
|
110
|
+
else ''
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
|
115
|
+
def self.element_int(el)
|
116
|
+
begin
|
117
|
+
return el.text.to_i if el && el.text
|
118
|
+
rescue
|
119
|
+
return -1
|
120
|
+
end
|
121
|
+
el
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
|
data/lib/url_info.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
|
2
|
+
|
3
|
+
module AWIS4Ruby
|
4
|
+
|
5
|
+
class UrlInfo
|
6
|
+
# ContactInfo
|
7
|
+
attr_accessor :phone_numbers, :owner_name, :contact_email, :contact_address, :stock_ticker,
|
8
|
+
# ContentData
|
9
|
+
:site_title, :site_description, :online_since, :speed_percentile, :load_time,
|
10
|
+
:adult_content, :links_in_count, :language_locale, :language_encoding, :keywords ,
|
11
|
+
# Related
|
12
|
+
:related_links,
|
13
|
+
# TrafficData
|
14
|
+
:rank,
|
15
|
+
# Other
|
16
|
+
:domain_name, :full_xml, :awis_url
|
17
|
+
|
18
|
+
|
19
|
+
def initialize
|
20
|
+
@phone_numbers = []
|
21
|
+
@keywords = []
|
22
|
+
@related_links = []
|
23
|
+
end
|
24
|
+
|
25
|
+
def to_s
|
26
|
+
str = ''
|
27
|
+
self.instance_variables.each do |var_name|
|
28
|
+
cur_var = self.send(var_name.gsub('@', ''))
|
29
|
+
if cur_var.kind_of?(Array)
|
30
|
+
str += "#{var_name}:\n"
|
31
|
+
cur_var.each do |i|
|
32
|
+
if i.class == Hash
|
33
|
+
i.each do |k,v|
|
34
|
+
str += " #{k}: #{v}\n"
|
35
|
+
end
|
36
|
+
else
|
37
|
+
str += " #{i}\n"
|
38
|
+
end
|
39
|
+
end
|
40
|
+
else
|
41
|
+
if var_name =~ /full_xml/
|
42
|
+
str += "#{var_name}: #{cur_var[0..20]}...(abbreviated)\n"
|
43
|
+
else
|
44
|
+
str += "#{var_name}: #{cur_var}\n"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
str
|
49
|
+
end
|
50
|
+
|
51
|
+
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
File without changes
|
metadata
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: awis4ruby
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: 0.9.0
|
7
|
+
date: 2007-08-29 00:00:00 -04:00
|
8
|
+
summary: Simple Ruby client for the Alexa Web Information Service.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: owack.j@gmail.com
|
12
|
+
homepage: http://labs.votanweb.com/awis4ruby/
|
13
|
+
rubyforge_project: awis4ruby
|
14
|
+
description: "== FEATURES/PROBLEMS: * Up-to-date Ruby client * Allows simple access to most popular AWIS data == SYNOPSIS: ACCESS_KEY_ID = \"05RTY5ESSE0EDGR68G2\" SECRET_ACCESS_KEY = \"1tmO+Tgvp0YU/ZOTwUTRYui7JppEc/lSMSD\" host = 'votanweb.com' info = AWIS4Ruby::get_url_info(ACCESS_KEY_ID, SECRET_ACCESS_KEY, host) p info.online_since.strftime('%m-%d-%Y') p info.rank # traffic rank == REQUIREMENTS:"
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: true
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Jay Owack
|
31
|
+
files:
|
32
|
+
- History.txt
|
33
|
+
- Manifest.txt
|
34
|
+
- README.txt
|
35
|
+
- Rakefile
|
36
|
+
- bin/awis4ruby
|
37
|
+
- lib/awis4ruby.rb
|
38
|
+
- lib/url_info.rb
|
39
|
+
- test/test_awis4ruby.rb
|
40
|
+
test_files:
|
41
|
+
- test/test_awis4ruby.rb
|
42
|
+
rdoc_options:
|
43
|
+
- --main
|
44
|
+
- README.txt
|
45
|
+
extra_rdoc_files:
|
46
|
+
- History.txt
|
47
|
+
- Manifest.txt
|
48
|
+
- README.txt
|
49
|
+
executables:
|
50
|
+
- awis4ruby
|
51
|
+
extensions: []
|
52
|
+
|
53
|
+
requirements: []
|
54
|
+
|
55
|
+
dependencies:
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: hoe
|
58
|
+
version_requirement:
|
59
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: 1.3.0
|
64
|
+
version:
|