alexa 0.2.2 → 0.3.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/.gitignore +1 -0
- data/.travis.yml +12 -0
- data/Gemfile +5 -0
- data/README.md +61 -0
- data/alexa.gemspec +2 -1
- data/lib/alexa.rb +15 -6
- data/lib/alexa/config.rb +11 -1
- data/lib/alexa/url_info.rb +87 -89
- data/lib/alexa/version.rb +1 -1
- data/test/config_test.rb +3 -3
- data/test/fixtures/custom-response-group.txt +22 -0
- data/test/fixtures/empty_group.txt +8 -0
- data/test/fixtures/forbidden.txt +7 -0
- data/test/fixtures/github_full.txt +2843 -0
- data/test/fixtures/github_rank.txt +14 -0
- data/test/fixtures/unathorized.txt +7 -0
- data/test/helper.rb +17 -4
- data/test/url_info_test.rb +46 -79
- metadata +59 -52
- data/README.markdown +0 -39
- data/test/fixtures/empty.xml +0 -39
- data/test/fixtures/polsl.xml +0 -1275
- data/test/fixtures/polsl_small.xml +0 -16
@@ -0,0 +1,14 @@
|
|
1
|
+
HTTP/1.1 200 OK
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Content-Type: text/xml
|
4
|
+
Transfer-Encoding: chunked
|
5
|
+
Date: Wed, 12 Oct 2011 21:18:48 GMT
|
6
|
+
|
7
|
+
<?xml version="1.0"?>
|
8
|
+
<aws:UrlInfoResponse 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>b9574986-bda8-83e2-cc0b-41457a7168d0</aws:RequestId></aws:OperationRequest><aws:UrlInfoResult><aws:Alexa>
|
9
|
+
|
10
|
+
<aws:TrafficData>
|
11
|
+
<aws:DataUrl type="canonical">github.com/</aws:DataUrl>
|
12
|
+
<aws:Rank>551</aws:Rank>
|
13
|
+
</aws:TrafficData>
|
14
|
+
</aws:Alexa></aws:UrlInfoResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-07-11/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:UrlInfoResponse>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
HTTP/1.1 401 Unauthorized
|
2
|
+
Server: Apache-Coyote/1.1
|
3
|
+
Transfer-Encoding: chunked
|
4
|
+
Date: Tue, 11 Oct 2011 20:16:19 GMT
|
5
|
+
|
6
|
+
<?xml version="1.0"?>
|
7
|
+
<Response><Errors><Error><Code>AuthFailure</Code><Message>AWS was not able to authenticate the request: access credentials are missing</Message></Error></Errors><RequestID>57d5192f-803a-1d6f-a50a-c354840a02b9</RequestID></Response>
|
data/test/helper.rb
CHANGED
@@ -1,11 +1,24 @@
|
|
1
|
-
|
1
|
+
require "bundler/setup"
|
2
2
|
|
3
3
|
require "minitest/autorun"
|
4
|
+
require "fakeweb"
|
4
5
|
require "mocha"
|
5
6
|
|
6
7
|
require "alexa"
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
if ENV["XML_PARSER"]
|
10
|
+
require ENV["XML_PARSER"] if ["nokogiri", "libxml", "ox"].include?(ENV["XML_PARSER"])
|
11
|
+
MultiXml.parser = ENV["XML_PARSER"]
|
12
|
+
end
|
13
|
+
|
14
|
+
class MiniTest::Unit::TestCase
|
15
|
+
def setup
|
16
|
+
FakeWeb.allow_net_connect = false
|
17
|
+
end
|
18
|
+
|
19
|
+
# Recording response is as simple as writing in terminal:
|
20
|
+
# curl -is "http://awis.amazonaws.com/?Action=UrlInfo&AWSAccessKeyId=fake" -X GET > response.txt
|
21
|
+
def fixture(filename)
|
22
|
+
File.read(File.join("test", "fixtures", filename))
|
23
|
+
end
|
11
24
|
end
|
data/test/url_info_test.rb
CHANGED
@@ -23,70 +23,74 @@ describe "Alexa::UlrInfo" do
|
|
23
23
|
assert_equal "awis.amazonaws.com", @alexa.send(:url).host
|
24
24
|
end
|
25
25
|
|
26
|
-
describe "parsing xml returned by options LinksInCount,SiteData" do
|
26
|
+
describe "parsing xml returned by options Rank,LinksInCount,SiteData" do
|
27
27
|
before do
|
28
|
+
FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("custom-response-group.txt"))
|
28
29
|
@alexa.response_group = "Rank,LinksInCount,SiteData"
|
29
|
-
|
30
|
-
@alexa.parse_xml(
|
30
|
+
@alexa.connect
|
31
|
+
@alexa.parse_xml(@alexa.xml_response)
|
31
32
|
end
|
32
33
|
|
33
34
|
it "should return rank" do
|
34
|
-
assert_equal
|
35
|
+
assert_equal 493, @alexa.rank
|
35
36
|
end
|
36
37
|
|
37
38
|
it "should return data url" do
|
38
|
-
assert_equal "
|
39
|
+
assert_equal "github.com/", @alexa.data_url
|
39
40
|
end
|
40
41
|
|
41
42
|
it "should return site title" do
|
42
|
-
assert_equal "
|
43
|
+
assert_equal "GitHub", @alexa.site_title
|
43
44
|
end
|
44
45
|
|
45
46
|
it "should return site description" do
|
46
|
-
|
47
|
+
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."
|
48
|
+
assert_equal expected, @alexa.site_description
|
47
49
|
end
|
48
50
|
|
49
|
-
it "should not
|
51
|
+
it "should not have other attributes" do
|
50
52
|
assert_nil @alexa.language_locale
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
54
|
-
describe "
|
56
|
+
describe "with github.com full response group" do
|
55
57
|
before do
|
56
|
-
|
57
|
-
@alexa.
|
58
|
+
FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("github_full.txt"))
|
59
|
+
@alexa.connect
|
60
|
+
@alexa.parse_xml(@alexa.xml_response)
|
58
61
|
end
|
59
62
|
|
60
63
|
it "should return rank" do
|
61
|
-
assert_equal
|
64
|
+
assert_equal 551, @alexa.rank
|
62
65
|
end
|
63
66
|
|
64
67
|
it "should return data url" do
|
65
|
-
assert_equal "
|
68
|
+
assert_equal "github.com", @alexa.data_url
|
66
69
|
end
|
67
70
|
|
68
71
|
it "should return site title" do
|
69
|
-
assert_equal "
|
72
|
+
assert_equal "GitHub", @alexa.site_title
|
70
73
|
end
|
71
74
|
|
72
75
|
it "should return site description" do
|
73
|
-
|
76
|
+
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."
|
77
|
+
assert_equal expected, @alexa.site_description
|
74
78
|
end
|
75
79
|
|
76
80
|
it "should return language locale" do
|
77
|
-
|
81
|
+
assert_nil @alexa.language_locale
|
78
82
|
end
|
79
83
|
|
80
84
|
it "should return language encoding" do
|
81
|
-
|
85
|
+
assert_nil @alexa.language_encoding
|
82
86
|
end
|
83
87
|
|
84
88
|
it "should return links in count" do
|
85
|
-
assert_equal
|
89
|
+
assert_equal 43819, @alexa.links_in_count
|
86
90
|
end
|
87
91
|
|
88
92
|
it "should return keywords" do
|
89
|
-
|
93
|
+
assert_nil @alexa.keywords
|
90
94
|
end
|
91
95
|
|
92
96
|
it "should return related links" do
|
@@ -94,19 +98,19 @@ describe "Alexa::UlrInfo" do
|
|
94
98
|
end
|
95
99
|
|
96
100
|
it "should return speed_median load time" do
|
97
|
-
assert_equal
|
101
|
+
assert_equal 1031, @alexa.speed_median_load_time
|
98
102
|
end
|
99
103
|
|
100
104
|
it "should return speed percentile" do
|
101
|
-
assert_equal
|
105
|
+
assert_equal 68, @alexa.speed_percentile
|
102
106
|
end
|
103
107
|
|
104
108
|
it "should return rank by country" do
|
105
|
-
assert_equal
|
109
|
+
assert_equal 19, @alexa.rank_by_country.size
|
106
110
|
end
|
107
111
|
|
108
112
|
it "should return rank by city" do
|
109
|
-
assert_equal
|
113
|
+
assert_equal 163, @alexa.rank_by_city.size
|
110
114
|
end
|
111
115
|
|
112
116
|
it "should return usage statistics" do
|
@@ -114,66 +118,29 @@ describe "Alexa::UlrInfo" do
|
|
114
118
|
end
|
115
119
|
end
|
116
120
|
|
117
|
-
describe "
|
118
|
-
|
119
|
-
|
120
|
-
@alexa.
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
assert_nil @alexa.rank
|
125
|
-
end
|
126
|
-
|
127
|
-
it "should return nil from data_url" do
|
128
|
-
assert_equal "404", @alexa.data_url
|
129
|
-
end
|
130
|
-
|
131
|
-
it "should return nil from site_title" do
|
132
|
-
assert_equal "404", @alexa.site_title
|
133
|
-
end
|
134
|
-
|
135
|
-
it "should return nil from site_description" do
|
136
|
-
assert_nil @alexa.site_description
|
137
|
-
end
|
138
|
-
|
139
|
-
it "should return nil from language_locale" do
|
140
|
-
assert_nil @alexa.language_locale
|
141
|
-
end
|
142
|
-
|
143
|
-
it "should return nil from language_encoding" do
|
144
|
-
assert_nil @alexa.language_encoding
|
145
|
-
end
|
146
|
-
|
147
|
-
it "should return nil from links_in_count" do
|
148
|
-
assert_nil @alexa.links_in_count
|
149
|
-
end
|
150
|
-
|
151
|
-
it "should return nil from keywords" do
|
152
|
-
assert_nil @alexa.keywords
|
153
|
-
end
|
154
|
-
|
155
|
-
it "should return nil from related_links" do
|
156
|
-
assert_nil @alexa.related_links
|
157
|
-
end
|
158
|
-
|
159
|
-
it "should return nil from speed_median_load_time" do
|
160
|
-
assert_nil @alexa.speed_median_load_time
|
161
|
-
end
|
162
|
-
|
163
|
-
it "should return nil from speed_percentile" do
|
164
|
-
assert_nil @alexa.speed_percentile
|
165
|
-
end
|
166
|
-
|
167
|
-
it "should return nil from rank_by_country" do
|
168
|
-
assert_nil @alexa.rank_by_country
|
121
|
+
describe "with github.com rank response group" do
|
122
|
+
it "should successfuly connect" do
|
123
|
+
FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("github_rank.txt"))
|
124
|
+
@alexa.response_group = "Rank"
|
125
|
+
@alexa.connect
|
126
|
+
@alexa.parse_xml(@alexa.xml_response)
|
127
|
+
assert_equal 551, @alexa.rank
|
169
128
|
end
|
129
|
+
end
|
170
130
|
|
171
|
-
|
172
|
-
|
131
|
+
describe "parsing xml with failure" do
|
132
|
+
it "should raise error when unathorized" do
|
133
|
+
FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("unathorized.txt"))
|
134
|
+
assert_raises StandardError do
|
135
|
+
@alexa.connect
|
136
|
+
end
|
173
137
|
end
|
174
138
|
|
175
|
-
it "should
|
176
|
-
|
139
|
+
it "should raise error when forbidden" do
|
140
|
+
FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("forbidden.txt"))
|
141
|
+
assert_raises StandardError do
|
142
|
+
@alexa.connect
|
143
|
+
end
|
177
144
|
end
|
178
145
|
end
|
179
146
|
end
|
metadata
CHANGED
@@ -1,53 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa
|
3
|
-
version: !ruby/object:Gem::Version
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.3.0
|
4
5
|
prerelease:
|
5
|
-
version: 0.2.2
|
6
6
|
platform: ruby
|
7
|
-
authors:
|
8
|
-
-
|
7
|
+
authors:
|
8
|
+
- Wojciech Wnętrzak
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
requirement: &id001 !ruby/object:Gem::Requirement
|
12
|
+
date: 2011-12-11 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: multi_xml
|
16
|
+
requirement: &18737420 !ruby/object:Gem::Requirement
|
18
17
|
none: false
|
19
|
-
requirements:
|
20
|
-
- -
|
21
|
-
- !ruby/object:Gem::Version
|
22
|
-
version:
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
23
22
|
type: :runtime
|
24
23
|
prerelease: false
|
25
|
-
version_requirements: *
|
26
|
-
- !ruby/object:Gem::Dependency
|
24
|
+
version_requirements: *18737420
|
25
|
+
- !ruby/object:Gem::Dependency
|
27
26
|
name: mocha
|
28
|
-
requirement: &
|
27
|
+
requirement: &18736900 !ruby/object:Gem::Requirement
|
29
28
|
none: false
|
30
|
-
requirements:
|
31
|
-
- -
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version:
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements: *
|
35
|
+
version_requirements: *18736900
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: fakeweb
|
38
|
+
requirement: &18735980 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *18735980
|
37
47
|
description: Alexa Web Information Service library (AWIS)
|
38
|
-
email:
|
48
|
+
email:
|
39
49
|
- w.wnetrzak@gmail.com
|
40
50
|
executables: []
|
41
|
-
|
42
51
|
extensions: []
|
43
|
-
|
44
52
|
extra_rdoc_files: []
|
45
|
-
|
46
|
-
files:
|
53
|
+
files:
|
47
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
48
56
|
- Gemfile
|
49
57
|
- LICENSE
|
50
|
-
- README.
|
58
|
+
- README.md
|
51
59
|
- Rakefile
|
52
60
|
- alexa.gemspec
|
53
61
|
- lib/alexa.rb
|
@@ -55,43 +63,42 @@ files:
|
|
55
63
|
- lib/alexa/url_info.rb
|
56
64
|
- lib/alexa/version.rb
|
57
65
|
- test/config_test.rb
|
58
|
-
- test/fixtures/
|
59
|
-
- test/fixtures/
|
60
|
-
- test/fixtures/
|
66
|
+
- test/fixtures/custom-response-group.txt
|
67
|
+
- test/fixtures/empty_group.txt
|
68
|
+
- test/fixtures/forbidden.txt
|
69
|
+
- test/fixtures/github_full.txt
|
70
|
+
- test/fixtures/github_rank.txt
|
71
|
+
- test/fixtures/unathorized.txt
|
61
72
|
- test/helper.rb
|
62
73
|
- test/url_info_test.rb
|
63
74
|
homepage: https://github.com/morgoth/alexa
|
64
75
|
licenses: []
|
65
|
-
|
66
76
|
post_install_message:
|
67
77
|
rdoc_options: []
|
68
|
-
|
69
|
-
require_paths:
|
78
|
+
require_paths:
|
70
79
|
- lib
|
71
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
72
81
|
none: false
|
73
|
-
requirements:
|
74
|
-
- -
|
75
|
-
- !ruby/object:Gem::Version
|
76
|
-
|
77
|
-
segments:
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
segments:
|
78
87
|
- 0
|
79
|
-
|
80
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
88
|
+
hash: -4342544955797275684
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
81
90
|
none: false
|
82
|
-
requirements:
|
83
|
-
- -
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
|
86
|
-
segments:
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
segments:
|
87
96
|
- 0
|
88
|
-
|
97
|
+
hash: -4342544955797275684
|
89
98
|
requirements: []
|
90
|
-
|
91
99
|
rubyforge_project:
|
92
|
-
rubygems_version: 1.8.
|
100
|
+
rubygems_version: 1.8.10
|
93
101
|
signing_key:
|
94
102
|
specification_version: 3
|
95
103
|
summary: Alexa Web Information Service library
|
96
104
|
test_files: []
|
97
|
-
|
data/README.markdown
DELETED
@@ -1,39 +0,0 @@
|
|
1
|
-
# Alexa Web Information Service #
|
2
|
-
|
3
|
-
## Installation ##
|
4
|
-
|
5
|
-
```
|
6
|
-
gem install alexa
|
7
|
-
```
|
8
|
-
|
9
|
-
## Usage ##
|
10
|
-
|
11
|
-
``` ruby
|
12
|
-
Alexa.url_info(:access_key_id => "key", :secret_access_key => "secret", :host => "site.com")
|
13
|
-
|
14
|
-
returns object with methods:
|
15
|
-
:xml_response, :rank, :data_url, :site_title, :site_description, :language_locale, :language_encoding,
|
16
|
-
:links_in_count, :keywords, :related_links, :speed_median_load_time, :speed_percentile,
|
17
|
-
:rank_by_country, :rank_by_city, :usage_statistics
|
18
|
-
```
|
19
|
-
|
20
|
-
NOTE: You can specify option `:response_group => "Rank,ContactInfo"` or any other valid group.
|
21
|
-
See: [Docs](http://docs.amazonwebservices.com/AlexaWebInfoService/latest/)
|
22
|
-
Default response group takes all the available options.
|
23
|
-
|
24
|
-
You can set configuration in block like this:
|
25
|
-
|
26
|
-
``` ruby
|
27
|
-
Alexa.config do |c|
|
28
|
-
c.access_key_id = "key"
|
29
|
-
c.secret_access_key = "secret"
|
30
|
-
end
|
31
|
-
```
|
32
|
-
|
33
|
-
## Contributors ##
|
34
|
-
|
35
|
-
* [rmoriz](https://github.com/rmoriz)
|
36
|
-
|
37
|
-
## Copyright ##
|
38
|
-
|
39
|
-
Copyright (c) 2011 Wojciech Wnętrzak. See LICENSE for details.
|