alexa 0.3.1 → 0.4.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.
Files changed (38) hide show
  1. data/.travis.yml +4 -5
  2. data/Gemfile +1 -0
  3. data/README.md +76 -21
  4. data/alexa.gemspec +1 -9
  5. data/lib/alexa.rb +11 -22
  6. data/lib/alexa/api/category_browse.rb +62 -0
  7. data/lib/alexa/api/category_listings.rb +66 -0
  8. data/lib/alexa/api/sites_linking_in.rb +41 -0
  9. data/lib/alexa/api/traffic_history.rb +45 -0
  10. data/lib/alexa/api/url_info.rb +108 -0
  11. data/lib/alexa/client.rb +30 -0
  12. data/lib/alexa/connection.rb +86 -0
  13. data/lib/alexa/exceptions.rb +17 -0
  14. data/lib/alexa/utils.rb +19 -0
  15. data/lib/alexa/version.rb +1 -1
  16. data/test/api/category_browse_test.rb +27 -0
  17. data/test/api/category_listings_test.rb +19 -0
  18. data/test/api/sites_linking_in_test.rb +23 -0
  19. data/test/api/traffic_history_test.rb +24 -0
  20. data/test/api/url_info_test.rb +112 -0
  21. data/test/client_test.rb +65 -0
  22. data/test/connection_test.rb +37 -0
  23. data/test/fixtures/bad_request.txt +8 -0
  24. data/test/fixtures/category_browse/card_games.txt +480 -0
  25. data/test/fixtures/category_listings/card_games.txt +138 -0
  26. data/test/fixtures/sites_linking_in/github_count_3.txt +24 -0
  27. data/test/fixtures/traffic_history/alexa_example.txt +37 -0
  28. data/test/fixtures/traffic_history/github_range_2.txt +8 -0
  29. data/test/fixtures/{custom-response-group.txt → url_info/custom-response-group.txt} +0 -0
  30. data/test/fixtures/{empty_group.txt → url_info/empty_group.txt} +0 -0
  31. data/test/fixtures/{github_full.txt → url_info/github_full.txt} +0 -0
  32. data/test/fixtures/{github_rank.txt → url_info/github_rank.txt} +0 -0
  33. data/test/helper.rb +6 -8
  34. data/test/utils_test.rb +54 -0
  35. metadata +33 -23
  36. data/lib/alexa/url_info.rb +0 -109
  37. data/test/config_test.rb +0 -35
  38. data/test/url_info_test.rb +0 -152
data/test/config_test.rb DELETED
@@ -1,35 +0,0 @@
1
- require "helper"
2
-
3
- describe Alexa do
4
- before do
5
- Alexa.access_key_id = nil
6
- Alexa.secret_access_key = nil
7
- end
8
-
9
- it "raises argumment error if access key id is not present" do
10
- assert_raises ArgumentError do
11
- Alexa::UrlInfo.new(
12
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
13
- :host => "some.host"
14
- )
15
- end
16
- end
17
-
18
- it "raises argumment error if secret access key is not present" do
19
- assert_raises ArgumentError do
20
- Alexa::UrlInfo.new(
21
- :access_key_id => "12345678901234567890",
22
- :host => "some.host"
23
- )
24
- end
25
- end
26
-
27
- it "raises argumment error if host is not present" do
28
- assert_raises ArgumentError do
29
- Alexa::UrlInfo.new(
30
- :access_key_id => "12345678901234567890",
31
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
32
- )
33
- end
34
- end
35
- end
@@ -1,152 +0,0 @@
1
- require "helper"
2
-
3
- describe Alexa::UrlInfo do
4
- before do
5
- @alexa = Alexa::UrlInfo.new(
6
- :access_key_id => "12345678901234567890",
7
- :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
8
- :host => "some.host"
9
- )
10
- end
11
-
12
- it "generates signature" do
13
- @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
14
-
15
- assert_equal "5Jql3rds3vL9hyijnYtUIVv1H8Q=", @alexa.send(:signature)
16
- end
17
-
18
- it "generates url" do
19
- @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
20
- @alexa.response_group = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks"
21
- @alexa.host = "heroku.com"
22
- expected_uri = "/?AWSAccessKeyId=12345678901234567890&Action=UrlInfo&ResponseGroup=Rank%2CContactInfo%2CAdultContent%2CSpeed%2CLanguage%2CKeywords%2COwnedDomains%2CLinksInCount%2CSiteData%2CRelatedLinks&SignatureMethod=HmacSHA1&SignatureVersion=2&Timestamp=2009-07-03T07%3A22%3A24.000Z&Url=heroku.com&Version=2005-07-11&Signature=H9VtDwXGXT5O8NodLOlsc2wIfv8%3D"
23
-
24
- assert_equal expected_uri, @alexa.send(:url).request_uri
25
- assert_equal "awis.amazonaws.com", @alexa.send(:url).host
26
- end
27
-
28
- describe "parsing xml returned by options Rank,LinksInCount,SiteData" do
29
- before do
30
- FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("custom-response-group.txt"))
31
- @alexa.response_group = "Rank,LinksInCount,SiteData"
32
- @alexa.connect
33
- @alexa.parse_xml(@alexa.xml_response)
34
- end
35
-
36
- it "returns rank" do
37
- assert_equal 493, @alexa.rank
38
- end
39
-
40
- it "returns data url" do
41
- assert_equal "github.com/", @alexa.data_url
42
- end
43
-
44
- it "returns site title" do
45
- assert_equal "GitHub", @alexa.site_title
46
- end
47
-
48
- it "returns site description" do
49
- expected = "Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code. Commercial closed source hosting is also available."
50
-
51
- assert_equal expected, @alexa.site_description
52
- end
53
-
54
- it "does not have other attributes" do
55
- assert_nil @alexa.language_locale
56
- end
57
- end
58
-
59
- describe "with github.com full response group" do
60
- before do
61
- FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("github_full.txt"))
62
- @alexa.connect
63
- @alexa.parse_xml(@alexa.xml_response)
64
- end
65
-
66
- it "returns rank" do
67
- assert_equal 551, @alexa.rank
68
- end
69
-
70
- it "returns data url" do
71
- assert_equal "github.com", @alexa.data_url
72
- end
73
-
74
- it "returns site title" do
75
- assert_equal "GitHub", @alexa.site_title
76
- end
77
-
78
- it "returns site description" do
79
- expected = "Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code. Commercial closed source hosting is also available."
80
- assert_equal expected, @alexa.site_description
81
- end
82
-
83
- it "returns language locale" do
84
- assert_nil @alexa.language_locale
85
- end
86
-
87
- it "returns language encoding" do
88
- assert_nil @alexa.language_encoding
89
- end
90
-
91
- it "returns links in count" do
92
- assert_equal 43819, @alexa.links_in_count
93
- end
94
-
95
- it "returns keywords" do
96
- assert_nil @alexa.keywords
97
- end
98
-
99
- it "returns related links" do
100
- assert_equal 10, @alexa.related_links.size
101
- end
102
-
103
- it "returns speed_median load time" do
104
- assert_equal 1031, @alexa.speed_median_load_time
105
- end
106
-
107
- it "returns speed percentile" do
108
- assert_equal 68, @alexa.speed_percentile
109
- end
110
-
111
- it "returns rank by country" do
112
- assert_equal 19, @alexa.rank_by_country.size
113
- end
114
-
115
- it "returns rank by city" do
116
- assert_equal 163, @alexa.rank_by_city.size
117
- end
118
-
119
- it "returns usage statistics" do
120
- assert_equal 4, @alexa.usage_statistics.size
121
- end
122
- end
123
-
124
- describe "with github.com rank response group" do
125
- it "successfuly connects" do
126
- FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("github_rank.txt"))
127
- @alexa.response_group = "Rank"
128
- @alexa.connect
129
- @alexa.parse_xml(@alexa.xml_response)
130
-
131
- assert_equal 551, @alexa.rank
132
- end
133
- end
134
-
135
- describe "parsing xml with failure" do
136
- it "raises error when unathorized" do
137
- FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("unathorized.txt"))
138
-
139
- assert_raises StandardError do
140
- @alexa.connect
141
- end
142
- end
143
-
144
- it "raises error when forbidden" do
145
- FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("forbidden.txt"))
146
-
147
- assert_raises StandardError do
148
- @alexa.connect
149
- end
150
- end
151
- end
152
- end