morgoth-alexa 0.0.4 → 0.0.5
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/README.rdoc +3 -0
- data/VERSION +1 -1
- data/alexa.gemspec +3 -3
- data/lib/alexa/url_info.rb +9 -1
- data/test/alexa_test.rb +28 -24
- data/test/test_helper.rb +2 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -11,6 +11,9 @@
|
|
11
11
|
:links_in_count, :keywords, :related_links, :speed_median_load_time, :speed_percentile,
|
12
12
|
:rank_by_country, :rank_by_city, :usage_statistics
|
13
13
|
|
14
|
+
== Contributors
|
15
|
+
* rmoriz[http://github.com/rmoriz]
|
16
|
+
|
14
17
|
== Copyright
|
15
18
|
|
16
19
|
Copyright (c) 2009 Wojciech Wnętrzak. See LICENSE for details.
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.5
|
data/alexa.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{alexa}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.5"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Wojciech Wnętrzak"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-23}
|
10
10
|
s.email = %q{w.wnetrzak@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
@@ -31,7 +31,7 @@ Gem::Specification.new do |s|
|
|
31
31
|
s.homepage = %q{http://github.com/morgoth/alexa}
|
32
32
|
s.rdoc_options = ["--charset=UTF-8"]
|
33
33
|
s.require_paths = ["lib"]
|
34
|
-
s.rubygems_version = %q{1.3.
|
34
|
+
s.rubygems_version = %q{1.3.5}
|
35
35
|
s.summary = %q{Alexa Web Information Service library}
|
36
36
|
s.test_files = [
|
37
37
|
"test/alexa_test.rb",
|
data/lib/alexa/url_info.rb
CHANGED
@@ -25,7 +25,7 @@ module Alexa
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def parse_xml(xml)
|
28
|
-
xml = XmlSimple.xml_in(
|
28
|
+
xml = XmlSimple.xml_in(force_encoding(xml), 'ForceArray' => false)
|
29
29
|
group = response_group.split(',')
|
30
30
|
alexa = xml['Response']['UrlInfoResult']['Alexa']
|
31
31
|
@rank = alexa['TrafficData']['Rank'].to_i if group.include?('Rank') and !alexa['TrafficData']['Rank'].empty?
|
@@ -48,6 +48,14 @@ module Alexa
|
|
48
48
|
|
49
49
|
private
|
50
50
|
|
51
|
+
def force_encoding(xml)
|
52
|
+
if RUBY_VERSION >= '1.9'
|
53
|
+
xml.force_encoding(Encoding::UTF_8)
|
54
|
+
else
|
55
|
+
xml
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
def handle_response(response)
|
52
60
|
case response.code.to_i
|
53
61
|
when 200...300
|
data/test/alexa_test.rb
CHANGED
@@ -4,10 +4,10 @@ class AlexaTest < Test::Unit::TestCase
|
|
4
4
|
context "Alexa::UrlInfo" do
|
5
5
|
setup do
|
6
6
|
@alexa = Alexa::UrlInfo.new(
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
7
|
+
:access_key_id => "12345678901234567890",
|
8
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
|
9
|
+
:host => "some.host"
|
10
|
+
)
|
11
11
|
end
|
12
12
|
|
13
13
|
should "Generate signature" do
|
@@ -15,17 +15,21 @@ class AlexaTest < Test::Unit::TestCase
|
|
15
15
|
assert_equal "I1mPdBy+flhhzqqUaamNq9gq190=", signature
|
16
16
|
end
|
17
17
|
|
18
|
-
should "
|
18
|
+
should "Generate url" do
|
19
19
|
url = @alexa.send( :generate_url,
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
20
|
+
"UrlInfo",
|
21
|
+
@alexa.access_key_id,
|
22
|
+
"I1mPdBy+flhhzqqUaamNq9gq190=",
|
23
|
+
'2009-07-03T07:22:24.000Z',
|
24
|
+
"Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks",
|
25
|
+
"heroku.com"
|
26
|
+
)
|
27
|
+
if RUBY_VERSION >= '1.9'
|
28
|
+
expected_uri = "/?Action=UrlInfo&AWSAccessKeyId=12345678901234567890&Signature=I1mPdBy%2BflhhzqqUaamNq9gq190%3D&Timestamp=2009-07-03T07%3A22%3A24.000Z&ResponseGroup=Rank%2CContactInfo%2CAdultContent%2CSpeed%2CLanguage%2CKeywords%2COwnedDomains%2CLinksInCount%2CSiteData%2CRelatedLinks&Url=heroku.com"
|
29
|
+
else
|
30
|
+
expected_uri = "/?Action=UrlInfo&Signature=I1mPdBy%2BflhhzqqUaamNq9gq190%3D&AWSAccessKeyId=12345678901234567890&Url=heroku.com&Timestamp=2009-07-03T07%3A22%3A24.000Z&ResponseGroup=Rank%2CContactInfo%2CAdultContent%2CSpeed%2CLanguage%2CKeywords%2COwnedDomains%2CLinksInCount%2CSiteData%2CRelatedLinks"
|
31
|
+
assert_equal expected_uri, url.request_uri
|
32
|
+
end
|
29
33
|
assert_equal "awis.amazonaws.com", url.host
|
30
34
|
end
|
31
35
|
|
@@ -196,25 +200,25 @@ class AlexaTest < Test::Unit::TestCase
|
|
196
200
|
end
|
197
201
|
|
198
202
|
should "Raise argumment error if keys or host are not present" do
|
199
|
-
assert_raise ArgumentError
|
203
|
+
assert_raise ArgumentError do
|
200
204
|
Alexa::UrlInfo.new(
|
201
|
-
|
202
|
-
|
205
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
|
206
|
+
:host => "some.host"
|
203
207
|
)
|
204
208
|
end
|
205
209
|
|
206
|
-
assert_raise ArgumentError
|
210
|
+
assert_raise ArgumentError do
|
207
211
|
Alexa::UrlInfo.new(
|
208
|
-
|
209
|
-
|
212
|
+
:access_key_id => "12345678901234567890",
|
213
|
+
:host => "some.host"
|
210
214
|
)
|
211
215
|
end
|
212
216
|
|
213
|
-
assert_raise ArgumentError
|
217
|
+
assert_raise ArgumentError do
|
214
218
|
Alexa::UrlInfo.new(
|
215
|
-
|
216
|
-
|
219
|
+
:access_key_id => "12345678901234567890",
|
220
|
+
:secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
|
217
221
|
)
|
218
222
|
end
|
219
223
|
end
|
220
|
-
end
|
224
|
+
end
|
data/test/test_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morgoth-alexa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Wojciech Wn\xC4\x99trzak"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-23 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|