alexa 0.3.1 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +4 -5
- data/Gemfile +1 -0
- data/README.md +76 -21
- data/alexa.gemspec +1 -9
- data/lib/alexa.rb +11 -22
- data/lib/alexa/api/category_browse.rb +62 -0
- data/lib/alexa/api/category_listings.rb +66 -0
- data/lib/alexa/api/sites_linking_in.rb +41 -0
- data/lib/alexa/api/traffic_history.rb +45 -0
- data/lib/alexa/api/url_info.rb +108 -0
- data/lib/alexa/client.rb +30 -0
- data/lib/alexa/connection.rb +86 -0
- data/lib/alexa/exceptions.rb +17 -0
- data/lib/alexa/utils.rb +19 -0
- data/lib/alexa/version.rb +1 -1
- data/test/api/category_browse_test.rb +27 -0
- data/test/api/category_listings_test.rb +19 -0
- data/test/api/sites_linking_in_test.rb +23 -0
- data/test/api/traffic_history_test.rb +24 -0
- data/test/api/url_info_test.rb +112 -0
- data/test/client_test.rb +65 -0
- data/test/connection_test.rb +37 -0
- data/test/fixtures/bad_request.txt +8 -0
- data/test/fixtures/category_browse/card_games.txt +480 -0
- data/test/fixtures/category_listings/card_games.txt +138 -0
- data/test/fixtures/sites_linking_in/github_count_3.txt +24 -0
- data/test/fixtures/traffic_history/alexa_example.txt +37 -0
- data/test/fixtures/traffic_history/github_range_2.txt +8 -0
- data/test/fixtures/{custom-response-group.txt → url_info/custom-response-group.txt} +0 -0
- data/test/fixtures/{empty_group.txt → url_info/empty_group.txt} +0 -0
- data/test/fixtures/{github_full.txt → url_info/github_full.txt} +0 -0
- data/test/fixtures/{github_rank.txt → url_info/github_rank.txt} +0 -0
- data/test/helper.rb +6 -8
- data/test/utils_test.rb +54 -0
- metadata +33 -23
- data/lib/alexa/url_info.rb +0 -109
- data/test/config_test.rb +0 -35
- data/test/url_info_test.rb +0 -152
@@ -0,0 +1,138 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Content-Type: text/xml
|
4
|
+
Transfer-Encoding: chunked
|
5
|
+
Date: Wed, 08 Aug 2012 20:25:27 GMT
|
6
|
+
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<aws:CategoryListingsResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>a069b6cd-309f-df52-88be-1bd88ab45b7e</aws:RequestId></aws:OperationRequest><aws:CategoryListingsResult><aws:Alexa>
|
9
|
+
|
10
|
+
<aws:CategoryListings>
|
11
|
+
<aws:RecursiveCount>1051</aws:RecursiveCount>
|
12
|
+
<aws:Count>1</aws:Count>
|
13
|
+
<aws:Listings>
|
14
|
+
<aws:Listing>
|
15
|
+
<aws:DataUrl type="navigable">http://ace2three.com/</aws:DataUrl>
|
16
|
+
<aws:Title>Ace2Three - the best Indian Rummy</aws:Title>
|
17
|
+
<aws:PopularityRank>7523</aws:PopularityRank>
|
18
|
+
<aws:Description>Play Indian Rummy and Win real cash prizes. Play rummy against live players in single and multi-table tournaments.</aws:Description>
|
19
|
+
</aws:Listing>
|
20
|
+
<aws:Listing>
|
21
|
+
<aws:DataUrl type="navigable">http://www.pagat.com/</aws:DataUrl>
|
22
|
+
<aws:Title>Rules of Card Games</aws:Title>
|
23
|
+
<aws:PopularityRank>26435</aws:PopularityRank>
|
24
|
+
<aws:Description>A collection of hundreds of card and tile game rules arranged alphabetically, categorically, and geographically.</aws:Description>
|
25
|
+
</aws:Listing>
|
26
|
+
<aws:Listing>
|
27
|
+
<aws:DataUrl type="navigable">http://www.acbl.org/</aws:DataUrl>
|
28
|
+
<aws:Title>American Contract Bridge League</aws:Title>
|
29
|
+
<aws:PopularityRank>40302</aws:PopularityRank>
|
30
|
+
<aws:Description>Organizes the game in North America. Includes tournaments calendar and results, places to play, events, shopping, members information, and learning resources. Official site.</aws:Description>
|
31
|
+
</aws:Listing>
|
32
|
+
<aws:Listing>
|
33
|
+
<aws:DataUrl type="navigable">http://www.sjgames.com/illuminati/</aws:DataUrl>
|
34
|
+
<aws:Title>Steve Jackson Games</aws:Title>
|
35
|
+
<aws:PopularityRank>59502</aws:PopularityRank>
|
36
|
+
<aws:Description>Official publishers site.</aws:Description>
|
37
|
+
</aws:Listing>
|
38
|
+
<aws:Listing>
|
39
|
+
<aws:DataUrl type="navigable">http://www.worldbridge.org/</aws:DataUrl>
|
40
|
+
<aws:Title>World Bridge Federation</aws:Title>
|
41
|
+
<aws:PopularityRank>64636</aws:PopularityRank>
|
42
|
+
<aws:Description>The official site of the body responsible for organizing world championships.</aws:Description>
|
43
|
+
</aws:Listing>
|
44
|
+
<aws:Listing>
|
45
|
+
<aws:DataUrl type="navigable">http://duncanbridgecenter.com/</aws:DataUrl>
|
46
|
+
<aws:Title>Duncan Bridge Center</aws:Title>
|
47
|
+
<aws:PopularityRank>66267</aws:PopularityRank>
|
48
|
+
<aws:Description>Offers schedules, results and information on the Coachella Valley Bridge Foundation.</aws:Description>
|
49
|
+
</aws:Listing>
|
50
|
+
<aws:Listing>
|
51
|
+
<aws:DataUrl type="navigable">http://www.bridgewebs.com/</aws:DataUrl>
|
52
|
+
<aws:Title>BridgeWebs</aws:Title>
|
53
|
+
<aws:PopularityRank>76726</aws:PopularityRank>
|
54
|
+
<aws:Description>Enables bridge clubs and associations to provide a web site complete with calendar, news and results service. Offers interface with scoring and dealing programs.</aws:Description>
|
55
|
+
</aws:Listing>
|
56
|
+
<aws:Listing>
|
57
|
+
<aws:DataUrl type="navigable">http://www.ecatsbridge.com/</aws:DataUrl>
|
58
|
+
<aws:Title>ECatsBridge</aws:Title>
|
59
|
+
<aws:PopularityRank>95359</aws:PopularityRank>
|
60
|
+
<aws:Description>Provides news, events, documents, links, virtual club pages and simultaneous pairs service.</aws:Description>
|
61
|
+
</aws:Listing>
|
62
|
+
<aws:Listing>
|
63
|
+
<aws:DataUrl type="navigable">http://bridgeinindia.homestead.com/</aws:DataUrl>
|
64
|
+
<aws:Title>Bridge in India</aws:Title>
|
65
|
+
<aws:PopularityRank>99147</aws:PopularityRank>
|
66
|
+
<aws:AverageReview>3.5</aws:AverageReview>
|
67
|
+
<aws:Description>National and international events covered. Offers links, calendar, forum and articles.</aws:Description>
|
68
|
+
</aws:Listing>
|
69
|
+
<aws:Listing>
|
70
|
+
<aws:DataUrl type="navigable">http://www.setgame.com/set/index.html</aws:DataUrl>
|
71
|
+
<aws:Title>Set Enterprises</aws:Title>
|
72
|
+
<aws:PopularityRank>106470</aws:PopularityRank>
|
73
|
+
<aws:Description>Original publisher's site.</aws:Description>
|
74
|
+
</aws:Listing>
|
75
|
+
<aws:Listing>
|
76
|
+
<aws:DataUrl type="navigable">http://bridgeindia.com/</aws:DataUrl>
|
77
|
+
<aws:Title>Bridge in India</aws:Title>
|
78
|
+
<aws:PopularityRank>109157</aws:PopularityRank>
|
79
|
+
<aws:Description>Covers international bridge events, offering calendar, entry details and bulletins. Includes articles on theory and play, plus information on the Laws.</aws:Description>
|
80
|
+
</aws:Listing>
|
81
|
+
<aws:Listing>
|
82
|
+
<aws:DataUrl type="navigable">http://www.pagat.com/rummy/</aws:DataUrl>
|
83
|
+
<aws:Title>Pagat</aws:Title>
|
84
|
+
<aws:PopularityRank>110214</aws:PopularityRank>
|
85
|
+
<aws:Description>Resource with rules on many card games including a detailed section on Rummy games.</aws:Description>
|
86
|
+
</aws:Listing>
|
87
|
+
<aws:Listing>
|
88
|
+
<aws:DataUrl type="navigable">http://justsolitaire.com/</aws:DataUrl>
|
89
|
+
<aws:Title>Just Solitaire</aws:Title>
|
90
|
+
<aws:PopularityRank>111527</aws:PopularityRank>
|
91
|
+
<aws:Description>Description of 26 solitaire games, which can be played on the website. History of solitaire.</aws:Description>
|
92
|
+
</aws:Listing>
|
93
|
+
<aws:Listing>
|
94
|
+
<aws:DataUrl type="navigable">http://www.ebu.co.uk/</aws:DataUrl>
|
95
|
+
<aws:Title>English Bridge Union</aws:Title>
|
96
|
+
<aws:PopularityRank>117434</aws:PopularityRank>
|
97
|
+
<aws:Description>Organizes bridge in England. Provides schedule and results of national tournaments, bridge teaching programme, membership information. Official site.</aws:Description>
|
98
|
+
</aws:Listing>
|
99
|
+
<aws:Listing>
|
100
|
+
<aws:DataUrl type="navigable">http://rummy.com/</aws:DataUrl>
|
101
|
+
<aws:Title>Rummy</aws:Title>
|
102
|
+
<aws:PopularityRank>133384</aws:PopularityRank>
|
103
|
+
<aws:Description>Rules on Rummy games such as Gin Rummy and Rummy 500 with terms and scoring data.</aws:Description>
|
104
|
+
</aws:Listing>
|
105
|
+
<aws:Listing>
|
106
|
+
<aws:DataUrl type="navigable">http://www.bridgefederation.ch/</aws:DataUrl>
|
107
|
+
<aws:Title>Federation Suisse de Bridge</aws:Title>
|
108
|
+
<aws:PopularityRank>133774</aws:PopularityRank>
|
109
|
+
<aws:Description>Presents a calendar of tournaments and player rankings. Official site.</aws:Description>
|
110
|
+
</aws:Listing>
|
111
|
+
<aws:Listing>
|
112
|
+
<aws:DataUrl type="navigable">http://www.pattayabridge.com/</aws:DataUrl>
|
113
|
+
<aws:Title>Pattaya Bridge Club</aws:Title>
|
114
|
+
<aws:PopularityRank>134879</aws:PopularityRank>
|
115
|
+
<aws:Description>A friendly bridge club that meets 3 times a week in Pattaya, Thailand, Asia. The web-site contains loads of bridge information, conventions, Notrump bidding etc. old and new.</aws:Description>
|
116
|
+
</aws:Listing>
|
117
|
+
<aws:Listing>
|
118
|
+
<aws:DataUrl type="navigable">http://www.eurobridge.org/</aws:DataUrl>
|
119
|
+
<aws:Title>European Bridge League</aws:Title>
|
120
|
+
<aws:PopularityRank>153237</aws:PopularityRank>
|
121
|
+
<aws:Description>A body composed of national organizations that organizes continent-wide events and represents European bridge at the world federation. Official site.</aws:Description>
|
122
|
+
</aws:Listing>
|
123
|
+
<aws:Listing>
|
124
|
+
<aws:DataUrl type="navigable">http://ginrummy.com/</aws:DataUrl>
|
125
|
+
<aws:Title>Gin Rummy</aws:Title>
|
126
|
+
<aws:PopularityRank>156913</aws:PopularityRank>
|
127
|
+
<aws:Description>Guide to Gin Rummy rules and variations with info on how to keep score in gin.</aws:Description>
|
128
|
+
</aws:Listing>
|
129
|
+
<aws:Listing>
|
130
|
+
<aws:DataUrl type="navigable">http://www.bridgeblogging.com/</aws:DataUrl>
|
131
|
+
<aws:Title>Bridge Blogging</aws:Title>
|
132
|
+
<aws:PopularityRank>159816</aws:PopularityRank>
|
133
|
+
<aws:Description>Collects the blogs of several notable bridge writers, including Bobby Wolff; posts "Aces on Bridge" column online.</aws:Description>
|
134
|
+
</aws:Listing>
|
135
|
+
</aws:Listings>
|
136
|
+
<aws:ReviewersRaveListings/>
|
137
|
+
</aws:CategoryListings>
|
138
|
+
</aws:Alexa></aws:CategoryListingsResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:CategoryListingsResponse>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Content-Type: text/xml
|
4
|
+
Transfer-Encoding: chunked
|
5
|
+
Date: Wed, 08 Aug 2012 09:12:13 GMT
|
6
|
+
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<aws:SitesLinkingInResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11"><aws:OperationRequest><aws:RequestId>abb553a3-035f-8d12-f353-40532a087b52</aws:RequestId></aws:OperationRequest><aws:SitesLinkingInResult><aws:Alexa>
|
9
|
+
|
10
|
+
<aws:SitesLinkingIn>
|
11
|
+
<aws:Site>
|
12
|
+
<aws:Title>google.com</aws:Title>
|
13
|
+
<aws:Url>code.google.com:80/a/eclipselabs.org/p/m2eclipse-android-integration</aws:Url>
|
14
|
+
</aws:Site>
|
15
|
+
<aws:Site>
|
16
|
+
<aws:Title>youtube.com</aws:Title>
|
17
|
+
<aws:Url>youtube.com:80</aws:Url>
|
18
|
+
</aws:Site>
|
19
|
+
<aws:Site>
|
20
|
+
<aws:Title>yahoo.com</aws:Title>
|
21
|
+
<aws:Url>answers.yahoo.com:80/question/index?qid=20100925181127AAFmizQ</aws:Url>
|
22
|
+
</aws:Site>
|
23
|
+
</aws:SitesLinkingIn>
|
24
|
+
</aws:Alexa></aws:SitesLinkingInResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:SitesLinkingInResponse>
|
@@ -0,0 +1,37 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Content-Type: text/xml
|
4
|
+
Transfer-Encoding: chunked
|
5
|
+
Date: Wed, 08 Aug 2012 13:42:33 GMT
|
6
|
+
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<aws:TrafficHistoryResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
|
9
|
+
<aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11">
|
10
|
+
<aws:OperationRequest><aws:RequestId>39ab4736-ec1a-492d-924b-d0d768d2692d</aws:RequestId>
|
11
|
+
</aws:OperationRequest>
|
12
|
+
<aws:TrafficHistoryResult>
|
13
|
+
<aws:Alexa>
|
14
|
+
<aws:TrafficHistory>
|
15
|
+
<aws:Range>31</aws:Range>
|
16
|
+
<aws:Site>amazon.com</aws:Site>
|
17
|
+
<aws:Start>2005-01-01</aws:Start>
|
18
|
+
<aws:HistoricalData>
|
19
|
+
<aws:Data>
|
20
|
+
<aws:Date>2005-01-01</aws:Date>
|
21
|
+
<aws:PageViews>
|
22
|
+
<aws:PerMillion>2801</aws:PerMillion>
|
23
|
+
<aws:PerUser>5.0</aws:PerUser>
|
24
|
+
</aws:PageViews>
|
25
|
+
<aws:Rank>18</aws:Rank>
|
26
|
+
<aws:Reach>
|
27
|
+
<aws:PerMillion>26041</aws:PerMillion>
|
28
|
+
</aws:Reach>
|
29
|
+
</aws:Data>
|
30
|
+
</aws:HistoricalData>
|
31
|
+
</aws:TrafficHistory>
|
32
|
+
</aws:Alexa>
|
33
|
+
</aws:TrafficHistoryResult>
|
34
|
+
<aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
|
35
|
+
<aws:StatusCode>Success</aws:StatusCode>
|
36
|
+
</aws:ResponseStatus></aws:Response>
|
37
|
+
</aws:TrafficHistoryResponse>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Content-Type: text/xml
|
4
|
+
Transfer-Encoding: chunked
|
5
|
+
Date: Wed, 08 Aug 2012 16:30:55 GMT
|
6
|
+
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<aws:TrafficHistoryResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:Response><aws:ResponseStatus><aws:StatusCode>AlexaError</aws:StatusCode><aws:StatusMessage>Request could not be execute due to an Alexa error</aws:StatusMessage></aws:ResponseStatus></aws:Response></aws:TrafficHistoryResponse>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/helper.rb
CHANGED
@@ -1,23 +1,21 @@
|
|
1
|
-
require "bundler/setup"
|
2
|
-
|
3
1
|
require "minitest/autorun"
|
4
|
-
require "
|
2
|
+
require "webmock/minitest"
|
5
3
|
require "mocha"
|
6
4
|
|
7
5
|
require "alexa"
|
8
6
|
|
9
|
-
|
7
|
+
xml_parser = ENV["XML_PARSER"] || "libxml"
|
10
8
|
|
11
|
-
require
|
12
|
-
MultiXml.parser =
|
9
|
+
require xml_parser if ["nokogiri", "libxml", "ox"].include?(xml_parser)
|
10
|
+
MultiXml.parser = xml_parser
|
13
11
|
|
14
12
|
class MiniTest::Unit::TestCase
|
15
13
|
def setup
|
16
|
-
|
14
|
+
WebMock.disable_net_connect!
|
17
15
|
end
|
18
16
|
|
19
17
|
# Recording response is as simple as writing in terminal:
|
20
|
-
# curl -is "http://awis.amazonaws.com/?Action=UrlInfo&AWSAccessKeyId=fake"
|
18
|
+
# curl -is -X GET "http://awis.amazonaws.com/?Action=UrlInfo&AWSAccessKeyId=fake" > response.txt
|
21
19
|
def fixture(filename)
|
22
20
|
File.read(File.join("test", "fixtures", filename))
|
23
21
|
end
|
data/test/utils_test.rb
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
require "helper"
|
2
|
+
|
3
|
+
describe Alexa::Utils do
|
4
|
+
describe "#safe_retrieve" do
|
5
|
+
it "returns nested hash value" do
|
6
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
7
|
+
assert_equal "Value!", Alexa::Utils.safe_retrieve(hash, :first, :second, :third)
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns partial hash when not all keys given" do
|
11
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
12
|
+
assert_equal({:third => "Value!"}, Alexa::Utils.safe_retrieve(hash, :first, :second))
|
13
|
+
end
|
14
|
+
|
15
|
+
it "returns nil when key not found in hash" do
|
16
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
17
|
+
assert_nil Alexa::Utils.safe_retrieve(hash, :non_exisiting)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "returns nil when one of keys not found in hash" do
|
21
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
22
|
+
assert_nil Alexa::Utils.safe_retrieve(hash, :first, :non_exisiting)
|
23
|
+
end
|
24
|
+
|
25
|
+
it "returns nil when given more keys than present in hash" do
|
26
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
27
|
+
assert_nil Alexa::Utils.safe_retrieve(hash, :first, :second, :third, :fourth)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns nil when non hash object given" do
|
31
|
+
assert_nil Alexa::Utils.safe_retrieve("And Now for Something Completely Different")
|
32
|
+
end
|
33
|
+
|
34
|
+
it "returns nil when no keys given" do
|
35
|
+
hash = {:first => {:second => {:third => "Value!"}}}
|
36
|
+
assert_nil Alexa::Utils.safe_retrieve(hash)
|
37
|
+
end
|
38
|
+
|
39
|
+
it "does not return incidental value" do
|
40
|
+
hash = {nil => "value"}
|
41
|
+
assert_nil Alexa::Utils.safe_retrieve(hash)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe "#camelize" do
|
46
|
+
it "uppercases word" do
|
47
|
+
assert_equal "Big", Alexa::Utils.camelize("big")
|
48
|
+
end
|
49
|
+
|
50
|
+
it "removes underscores" do
|
51
|
+
assert_equal "BigBen", Alexa::Utils.camelize("big_ben")
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-08-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: multi_xml
|
@@ -44,7 +44,7 @@ dependencies:
|
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: '0'
|
46
46
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
47
|
+
name: webmock
|
48
48
|
requirement: !ruby/object:Gem::Requirement
|
49
49
|
none: false
|
50
50
|
requirements:
|
@@ -74,30 +74,40 @@ files:
|
|
74
74
|
- Rakefile
|
75
75
|
- alexa.gemspec
|
76
76
|
- lib/alexa.rb
|
77
|
-
- lib/alexa/
|
77
|
+
- lib/alexa/api/category_browse.rb
|
78
|
+
- lib/alexa/api/category_listings.rb
|
79
|
+
- lib/alexa/api/sites_linking_in.rb
|
80
|
+
- lib/alexa/api/traffic_history.rb
|
81
|
+
- lib/alexa/api/url_info.rb
|
82
|
+
- lib/alexa/client.rb
|
83
|
+
- lib/alexa/connection.rb
|
84
|
+
- lib/alexa/exceptions.rb
|
85
|
+
- lib/alexa/utils.rb
|
78
86
|
- lib/alexa/version.rb
|
79
|
-
- test/
|
80
|
-
- test/
|
81
|
-
- test/
|
87
|
+
- test/api/category_browse_test.rb
|
88
|
+
- test/api/category_listings_test.rb
|
89
|
+
- test/api/sites_linking_in_test.rb
|
90
|
+
- test/api/traffic_history_test.rb
|
91
|
+
- test/api/url_info_test.rb
|
92
|
+
- test/client_test.rb
|
93
|
+
- test/connection_test.rb
|
94
|
+
- test/fixtures/bad_request.txt
|
95
|
+
- test/fixtures/category_browse/card_games.txt
|
96
|
+
- test/fixtures/category_listings/card_games.txt
|
82
97
|
- test/fixtures/forbidden.txt
|
83
|
-
- test/fixtures/
|
84
|
-
- test/fixtures/
|
98
|
+
- test/fixtures/sites_linking_in/github_count_3.txt
|
99
|
+
- test/fixtures/traffic_history/alexa_example.txt
|
100
|
+
- test/fixtures/traffic_history/github_range_2.txt
|
85
101
|
- test/fixtures/unathorized.txt
|
102
|
+
- test/fixtures/url_info/custom-response-group.txt
|
103
|
+
- test/fixtures/url_info/empty_group.txt
|
104
|
+
- test/fixtures/url_info/github_full.txt
|
105
|
+
- test/fixtures/url_info/github_rank.txt
|
86
106
|
- test/helper.rb
|
87
|
-
- test/
|
107
|
+
- test/utils_test.rb
|
88
108
|
homepage: https://github.com/morgoth/alexa
|
89
109
|
licenses: []
|
90
|
-
post_install_message:
|
91
|
-
|
92
|
-
|
93
|
-
Gem syntax of 0.4 version of this gem will change with backward incompatibilities.
|
94
|
-
|
95
|
-
If you don''t want to update your code, please specify in your Gemfile:
|
96
|
-
|
97
|
-
gem "alexa", "~> 0.3.0"
|
98
|
-
|
99
|
-
|
100
|
-
'
|
110
|
+
post_install_message:
|
101
111
|
rdoc_options: []
|
102
112
|
require_paths:
|
103
113
|
- lib
|
@@ -109,7 +119,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
109
119
|
version: '0'
|
110
120
|
segments:
|
111
121
|
- 0
|
112
|
-
hash:
|
122
|
+
hash: 3321764807879107613
|
113
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
124
|
none: false
|
115
125
|
requirements:
|
@@ -118,7 +128,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
118
128
|
version: '0'
|
119
129
|
segments:
|
120
130
|
- 0
|
121
|
-
hash:
|
131
|
+
hash: 3321764807879107613
|
122
132
|
requirements: []
|
123
133
|
rubyforge_project:
|
124
134
|
rubygems_version: 1.8.24
|
data/lib/alexa/url_info.rb
DELETED
@@ -1,109 +0,0 @@
|
|
1
|
-
class Alexa::UrlInfo
|
2
|
-
API_VERSION = "2005-07-11"
|
3
|
-
HOST = "awis.amazonaws.com"
|
4
|
-
RESPONSE_GROUP = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks,RankByCountry,RankByCity,UsageStats"
|
5
|
-
|
6
|
-
attr_accessor :host, :response_group
|
7
|
-
attr_reader :xml_response, :rank, :data_url, :site_title, :site_description, :language_locale, :language_encoding,
|
8
|
-
:links_in_count, :keywords, :related_links, :speed_median_load_time, :speed_percentile,
|
9
|
-
:rank_by_country, :rank_by_city, :usage_statistics
|
10
|
-
|
11
|
-
def initialize(options = {})
|
12
|
-
Alexa.access_key_id = options.fetch(:access_key_id, Alexa.access_key_id)
|
13
|
-
Alexa.secret_access_key = options.fetch(:secret_access_key, Alexa.secret_access_key)
|
14
|
-
raise ArgumentError.new("You must specify access_key_id") if Alexa.access_key_id.nil?
|
15
|
-
raise ArgumentError.new("You must specify secret_access_key") if Alexa.secret_access_key.nil?
|
16
|
-
self.host = options[:host] or raise ArgumentError.new("You must specify host")
|
17
|
-
self.response_group = options.fetch(:response_group, RESPONSE_GROUP)
|
18
|
-
end
|
19
|
-
|
20
|
-
def connect
|
21
|
-
response = Net::HTTP.start(url.host) do |http|
|
22
|
-
http.get url.request_uri
|
23
|
-
end
|
24
|
-
@xml_response = handle_response(response).body
|
25
|
-
end
|
26
|
-
|
27
|
-
def parse_xml(xml)
|
28
|
-
xml = MultiXml.parse(force_encoding(xml))
|
29
|
-
group = response_group.split(",")
|
30
|
-
alexa = xml["UrlInfoResponse"]["Response"]["UrlInfoResult"]["Alexa"]
|
31
|
-
@rank = alexa["TrafficData"]["Rank"].to_i if group.include?("Rank") && !alexa["TrafficData"]["Rank"].nil?
|
32
|
-
@data_url = alexa["TrafficData"]["DataUrl"]["__content__"] if group.include?("Rank")
|
33
|
-
@rank_by_country = alexa["TrafficData"]["RankByCountry"]["Country"] if group.include?("RankByCountry") && !alexa["TrafficData"]["RankByCountry"].nil?
|
34
|
-
@rank_by_city = alexa["TrafficData"]["RankByCity"]["City"] if group.include?("RankByCity") && !alexa["TrafficData"]["RankByCity"].nil?
|
35
|
-
@usage_statistics = alexa["TrafficData"]["UsageStatistics"]["UsageStatistic"] if group.include?("UsageStats") && !alexa["TrafficData"]["UsageStatistics"].nil?
|
36
|
-
|
37
|
-
@site_title = alexa["ContentData"]["SiteData"]["Title"] if group.include?("SiteData")
|
38
|
-
@site_description = alexa["ContentData"]["SiteData"]["Description"] if group.include?("SiteData")
|
39
|
-
@language_locale = alexa["ContentData"]["Language"]["Locale"] if group.include?("Language") && !alexa["ContentData"]["Language"].nil?
|
40
|
-
@language_encoding = alexa["ContentData"]["Language"]["Encoding"] if group.include?("Language") && !alexa["ContentData"]["Language"].nil?
|
41
|
-
@links_in_count = alexa["ContentData"]["LinksInCount"].to_i if group.include?("LinksInCount") && !alexa["ContentData"]["LinksInCount"].nil?
|
42
|
-
@keywords = alexa["ContentData"]["Keywords"]["Keyword"] if group.include?("Keywords") && !alexa["ContentData"]["Keywords"].nil?
|
43
|
-
@speed_median_load_time = alexa["ContentData"]["Speed"]["MedianLoadTime"].to_i if group.include?("Speed") && !alexa["ContentData"]["Speed"]["MedianLoadTime"].nil?
|
44
|
-
@speed_percentile = alexa["ContentData"]["Speed"]["Percentile"].to_i if group.include?("Speed") && !alexa["ContentData"]["Speed"]["Percentile"].nil?
|
45
|
-
|
46
|
-
@related_links = alexa["Related"]["RelatedLinks"]["RelatedLink"] if group.include?("RelatedLinks") && !alexa["Related"]["RelatedLinks"].nil?
|
47
|
-
end
|
48
|
-
|
49
|
-
private
|
50
|
-
|
51
|
-
def timestamp
|
52
|
-
@timestamp ||= Time::now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
53
|
-
end
|
54
|
-
|
55
|
-
def force_encoding(xml)
|
56
|
-
if RUBY_VERSION >= "1.9"
|
57
|
-
xml.force_encoding(Encoding::UTF_8)
|
58
|
-
else
|
59
|
-
xml
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
def handle_response(response)
|
64
|
-
case response.code.to_i
|
65
|
-
when 200...300
|
66
|
-
response
|
67
|
-
when 300...600
|
68
|
-
if response.body.nil?
|
69
|
-
raise StandardError.new(response)
|
70
|
-
else
|
71
|
-
@xml_response = response.body
|
72
|
-
xml = MultiXml.parse(@xml_response)
|
73
|
-
message = xml["Response"]["Errors"]["Error"]["Message"]
|
74
|
-
raise StandardError.new(message)
|
75
|
-
end
|
76
|
-
else
|
77
|
-
raise StandardError.new("Unknown code: #{respnse.code}")
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def signature
|
82
|
-
Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), Alexa.secret_access_key, sign)).strip
|
83
|
-
end
|
84
|
-
|
85
|
-
def url
|
86
|
-
URI.parse("http://#{HOST}/?" + query + "&Signature=" + CGI::escape(signature))
|
87
|
-
end
|
88
|
-
|
89
|
-
def params_without_signature
|
90
|
-
{
|
91
|
-
"Action" => "UrlInfo",
|
92
|
-
"AWSAccessKeyId" => Alexa.access_key_id,
|
93
|
-
"ResponseGroup" => response_group,
|
94
|
-
"SignatureMethod" => "HmacSHA1",
|
95
|
-
"SignatureVersion" => "2",
|
96
|
-
"Timestamp" => timestamp,
|
97
|
-
"Url" => host,
|
98
|
-
"Version" => API_VERSION
|
99
|
-
}
|
100
|
-
end
|
101
|
-
|
102
|
-
def sign
|
103
|
-
"GET\n" + HOST + "\n/\n" + query
|
104
|
-
end
|
105
|
-
|
106
|
-
def query
|
107
|
-
params_without_signature.map { |key, value| "#{key}=#{CGI::escape(value)}" }.sort.join("&")
|
108
|
-
end
|
109
|
-
end
|