ralexa 0.0.2 → 0.0.3

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.
@@ -0,0 +1,173 @@
1
+ <?xml version="1.0"?>
2
+ <aws:TopSitesResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://ats.amazonaws.com/doc/2005-11-21"><aws:OperationRequest><aws:RequestId>59620de1-abbc-4966-7f20-b17a55767c15</aws:RequestId></aws:OperationRequest><aws:TopSitesResult><aws:Alexa>
3
+
4
+ <aws:TopSites>
5
+ <aws:Country>
6
+ <aws:CountryName>GLOBAL</aws:CountryName>
7
+ <aws:CountryCode>*</aws:CountryCode>
8
+ <aws:TotalSites>365603</aws:TotalSites>
9
+ <aws:Sites>
10
+ <aws:Site>
11
+ <aws:DataUrl>google.com</aws:DataUrl>
12
+ <aws:Country>
13
+ <aws:Rank>1</aws:Rank>
14
+ <aws:Reach>
15
+ <aws:PerMillion>501800</aws:PerMillion>
16
+ </aws:Reach>
17
+ <aws:PageViews>
18
+ <aws:PerMillion>54926</aws:PerMillion>
19
+ <aws:PerUser>11.63</aws:PerUser>
20
+ </aws:PageViews>
21
+ </aws:Country>
22
+ <aws:Global>
23
+ <aws:Rank>1</aws:Rank>
24
+ </aws:Global>
25
+ </aws:Site>
26
+ <aws:Site>
27
+ <aws:DataUrl>facebook.com</aws:DataUrl>
28
+ <aws:Country>
29
+ <aws:Rank>2</aws:Rank>
30
+ <aws:Reach>
31
+ <aws:PerMillion>440400</aws:PerMillion>
32
+ </aws:Reach>
33
+ <aws:PageViews>
34
+ <aws:PerMillion>51798</aws:PerMillion>
35
+ <aws:PerUser>12.5</aws:PerUser>
36
+ </aws:PageViews>
37
+ </aws:Country>
38
+ <aws:Global>
39
+ <aws:Rank>2</aws:Rank>
40
+ </aws:Global>
41
+ </aws:Site>
42
+ <aws:Site>
43
+ <aws:DataUrl>youtube.com</aws:DataUrl>
44
+ <aws:Country>
45
+ <aws:Rank>3</aws:Rank>
46
+ <aws:Reach>
47
+ <aws:PerMillion>323700</aws:PerMillion>
48
+ </aws:Reach>
49
+ <aws:PageViews>
50
+ <aws:PerMillion>38756</aws:PerMillion>
51
+ <aws:PerUser>12.73</aws:PerUser>
52
+ </aws:PageViews>
53
+ </aws:Country>
54
+ <aws:Global>
55
+ <aws:Rank>3</aws:Rank>
56
+ </aws:Global>
57
+ </aws:Site>
58
+ <aws:Site>
59
+ <aws:DataUrl>yahoo.com</aws:DataUrl>
60
+ <aws:Country>
61
+ <aws:Rank>4</aws:Rank>
62
+ <aws:Reach>
63
+ <aws:PerMillion>222300</aws:PerMillion>
64
+ </aws:Reach>
65
+ <aws:PageViews>
66
+ <aws:PerMillion>13620</aws:PerMillion>
67
+ <aws:PerUser>6.51</aws:PerUser>
68
+ </aws:PageViews>
69
+ </aws:Country>
70
+ <aws:Global>
71
+ <aws:Rank>4</aws:Rank>
72
+ </aws:Global>
73
+ </aws:Site>
74
+ <aws:Site>
75
+ <aws:DataUrl>baidu.com</aws:DataUrl>
76
+ <aws:Country>
77
+ <aws:Rank>5</aws:Rank>
78
+ <aws:Reach>
79
+ <aws:PerMillion>110500</aws:PerMillion>
80
+ </aws:Reach>
81
+ <aws:PageViews>
82
+ <aws:PerMillion>19142</aws:PerMillion>
83
+ <aws:PerUser>18.41</aws:PerUser>
84
+ </aws:PageViews>
85
+ </aws:Country>
86
+ <aws:Global>
87
+ <aws:Rank>5</aws:Rank>
88
+ </aws:Global>
89
+ </aws:Site>
90
+ <aws:Site>
91
+ <aws:DataUrl>wikipedia.org</aws:DataUrl>
92
+ <aws:Country>
93
+ <aws:Rank>6</aws:Rank>
94
+ <aws:Reach>
95
+ <aws:PerMillion>141700</aws:PerMillion>
96
+ </aws:Reach>
97
+ <aws:PageViews>
98
+ <aws:PerMillion>5191</aws:PerMillion>
99
+ <aws:PerUser>3.89</aws:PerUser>
100
+ </aws:PageViews>
101
+ </aws:Country>
102
+ <aws:Global>
103
+ <aws:Rank>6</aws:Rank>
104
+ </aws:Global>
105
+ </aws:Site>
106
+ <aws:Site>
107
+ <aws:DataUrl>live.com</aws:DataUrl>
108
+ <aws:Country>
109
+ <aws:Rank>7</aws:Rank>
110
+ <aws:Reach>
111
+ <aws:PerMillion>106270</aws:PerMillion>
112
+ </aws:Reach>
113
+ <aws:PageViews>
114
+ <aws:PerMillion>6526</aws:PerMillion>
115
+ <aws:PerUser>6.53</aws:PerUser>
116
+ </aws:PageViews>
117
+ </aws:Country>
118
+ <aws:Global>
119
+ <aws:Rank>7</aws:Rank>
120
+ </aws:Global>
121
+ </aws:Site>
122
+ <aws:Site>
123
+ <aws:DataUrl>blogspot.com</aws:DataUrl>
124
+ <aws:Country>
125
+ <aws:Rank>8</aws:Rank>
126
+ <aws:Reach>
127
+ <aws:PerMillion>102250</aws:PerMillion>
128
+ </aws:Reach>
129
+ <aws:PageViews>
130
+ <aws:PerMillion>3324</aws:PerMillion>
131
+ <aws:PerUser>3.45</aws:PerUser>
132
+ </aws:PageViews>
133
+ </aws:Country>
134
+ <aws:Global>
135
+ <aws:Rank>8</aws:Rank>
136
+ </aws:Global>
137
+ </aws:Site>
138
+ <aws:Site>
139
+ <aws:DataUrl>qq.com</aws:DataUrl>
140
+ <aws:Country>
141
+ <aws:Rank>9</aws:Rank>
142
+ <aws:Reach>
143
+ <aws:PerMillion>73830</aws:PerMillion>
144
+ </aws:Reach>
145
+ <aws:PageViews>
146
+ <aws:PerMillion>6274</aws:PerMillion>
147
+ <aws:PerUser>9.03</aws:PerUser>
148
+ </aws:PageViews>
149
+ </aws:Country>
150
+ <aws:Global>
151
+ <aws:Rank>9</aws:Rank>
152
+ </aws:Global>
153
+ </aws:Site>
154
+ <aws:Site>
155
+ <aws:DataUrl>twitter.com</aws:DataUrl>
156
+ <aws:Country>
157
+ <aws:Rank>10</aws:Rank>
158
+ <aws:Reach>
159
+ <aws:PerMillion>82710</aws:PerMillion>
160
+ </aws:Reach>
161
+ <aws:PageViews>
162
+ <aws:PerMillion>3687</aws:PerMillion>
163
+ <aws:PerUser>4.74</aws:PerUser>
164
+ </aws:PageViews>
165
+ </aws:Country>
166
+ <aws:Global>
167
+ <aws:Rank>10</aws:Rank>
168
+ </aws:Global>
169
+ </aws:Site>
170
+ </aws:Sites>
171
+ </aws:Country>
172
+ </aws:TopSites>
173
+ </aws:Alexa></aws:TopSitesResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:TopSitesResponse>
@@ -0,0 +1,55 @@
1
+ require_relative "spec_helper"
2
+
3
+ module Ralexa
4
+ describe Paginator do
5
+
6
+ describe "at 10 per page" do
7
+
8
+ def paginate(items)
9
+ Paginator.new(10, items).pages
10
+ end
11
+
12
+ it "paginates 0 items to 0 pages" do
13
+ paginate(0).size.must_equal 0
14
+ end
15
+
16
+ it "paginates 1 item to 1 page" do
17
+ pages = paginate(1)
18
+ pages.size.must_equal 1
19
+ pages.first.tap do |p|
20
+ p.number.must_equal 1
21
+ p.start.must_equal 1
22
+ p.finish.must_equal 1
23
+ p.count.must_equal 1
24
+ end
25
+ end
26
+
27
+ it "paginates 10 items to 1 page" do
28
+ pages = paginate(10)
29
+ pages.size.must_equal 1
30
+ pages.first.count.must_equal 10
31
+ end
32
+
33
+ it "paginages 25 items to 3 pages" do
34
+ pages = paginate(25)
35
+ pages.size.must_equal 3
36
+
37
+ pages.first.tap do |p|
38
+ p.number.must_equal 1
39
+ p.start.must_equal 1
40
+ p.finish.must_equal 10
41
+ p.count.must_equal 10
42
+ end
43
+
44
+ pages.last.tap do |p|
45
+ p.number.must_equal 3
46
+ p.start.must_equal 21
47
+ p.finish.must_equal 25
48
+ p.count.must_equal 5
49
+ end
50
+ end
51
+
52
+ end
53
+
54
+ end
55
+ end
data/spec/ralexa_spec.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require_relative "spec_helper"
2
2
 
3
- require "ralexa"
4
-
5
3
  describe Ralexa do
6
4
 
7
5
  describe ".session" do
data/spec/session_spec.rb CHANGED
@@ -1,7 +1,5 @@
1
1
  require_relative "spec_helper"
2
2
 
3
- require "ralexa/session"
4
-
5
3
  module Ralexa
6
4
  describe Session do
7
5
 
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  gem "minitest"
2
2
  require "minitest/autorun"
3
+
3
4
  $LOAD_PATH.unshift "./lib"
5
+ require "ralexa"
4
6
 
5
7
  def fixture(filename)
6
8
  File.read("#{File.dirname(__FILE__)}/fixtures/#{filename}")
@@ -1,7 +1,5 @@
1
1
  require_relative "spec_helper"
2
2
 
3
- require "ralexa/top_sites"
4
-
5
3
  module Ralexa
6
4
  describe TopSites do
7
5
 
@@ -9,31 +7,75 @@ module Ralexa
9
7
  let(:client) { MiniTest::Mock.new }
10
8
 
11
9
  describe "#global" do
12
- before do
13
- expect_parameters = {
10
+ def expected_params(start, count)
11
+ {
14
12
  "Action" => "TopSites",
15
13
  "ResponseGroup" => "Country",
14
+ "Start" => start,
15
+ "Count" => count,
16
16
  }
17
- client.expect :get, fixture("global.xml"),
18
- ["ats.amazonaws.com", "/", expect_parameters]
19
17
  end
20
- it "fetches, parses and returns top sites" do
21
- top_sites_match_fixture(top_sites.global)
18
+ describe "requesting ten sites" do
19
+ before do
20
+ client.expect :get, fixture("global-top10.xml"),
21
+ ["ats.amazonaws.com", "/", expected_params(1, 10)]
22
+ end
23
+ it "fetches, parses and returns top ten sites" do
24
+ sites = top_sites.global(10).to_a
25
+ sites.size.must_equal 10
26
+ [ sites.first.rank, sites.last.rank ].must_equal [ 1, 10 ]
27
+
28
+ g = sites.first
29
+ g.url.must_equal "google.com"
30
+ g.rank.must_equal 1
31
+ g.reach.must_equal 501_800_000_000
32
+ g.page_views.must_equal 54_926_000_000
33
+ g.page_views_per_user.must_equal 11.63
34
+ end
35
+ end
36
+ describe "requesting 150 sites" do
37
+ before do
38
+ client.expect :get, fixture("global-page1.xml"),
39
+ ["ats.amazonaws.com", "/", expected_params(1, 100)]
40
+ client.expect :get, fixture("global-page2.xml"),
41
+ ["ats.amazonaws.com", "/", expected_params(101, 50)]
42
+ end
43
+ it "fetches, parses and returns top ten sites" do
44
+ sites = top_sites.global(150).to_a
45
+ sites.size.must_equal 150
46
+ [ sites.first.rank, sites.last.rank ].must_equal [ 1, 150 ]
47
+ end
48
+ end
49
+ it "raises error if Count (or Start) are specified" do
50
+ ->{
51
+ top_sites.global(10, "Count" => 2)
52
+ }.must_raise PaginatingCollection::Error
22
53
  end
23
54
  end
24
55
 
25
56
  describe "#country" do
26
- before do
27
- expect_parameters = {
57
+ def expected_params(start, count)
58
+ {
28
59
  "Action" => "TopSites",
29
60
  "ResponseGroup" => "Country",
30
61
  "CountryCode" => "AU",
62
+ "Start" => start,
63
+ "Count" => count,
31
64
  }
32
- client.expect :get, fixture("global.xml"),
33
- ["ats.amazonaws.com", "/", expect_parameters]
65
+ end
66
+ before do
67
+ client.expect :get, fixture("global-top10.xml"),
68
+ ["ats.amazonaws.com", "/", expected_params(1, 10)]
34
69
  end
35
70
  it "fetches, parses and returns top sites for specified country" do
36
- top_sites_match_fixture(top_sites.country("AU"))
71
+ sites = top_sites.country("AU", 10).to_a
72
+ sites.size.must_equal 10
73
+ sites.last.url.must_equal "twitter.com"
74
+ end
75
+ it "raises error if Start (or Count) are specified" do
76
+ ->{
77
+ top_sites.country("AU", 10, start: 2)
78
+ }.must_raise PaginatingCollection::Error
37
79
  end
38
80
  end
39
81
 
@@ -49,8 +91,8 @@ module Ralexa
49
91
 
50
92
  it "fetches, parses and returns countries" do
51
93
  countries = top_sites.list_countries
52
- countries.size.must_equal 2
53
- a, u = countries
94
+ countries.to_a.size.must_equal 2
95
+ a, u = countries.to_a
54
96
 
55
97
  u.name.must_equal "United States"
56
98
  u.code.must_equal "US"
@@ -66,22 +108,5 @@ module Ralexa
66
108
  end
67
109
  end
68
110
 
69
- def top_sites_match_fixture(sites)
70
- sites.size.must_equal 2
71
- w, b = sites
72
-
73
- w.url.must_equal "wikipedia.org"
74
- w.rank.must_equal 6
75
- w.reach.must_equal 143_000_000_000
76
- w.page_views.must_equal 5_219_000_000
77
- w.page_views_per_user.must_equal 3.88
78
-
79
- b.url.must_equal "bbc.co.uk"
80
- b.rank.must_equal 52
81
- b.reach.must_equal 20_540_000_000
82
- b.page_views.must_equal 898_500_000
83
- b.page_views_per_user.must_equal 4.65
84
- end
85
-
86
111
  end
87
112
  end
@@ -1,7 +1,6 @@
1
1
  require_relative "spec_helper"
2
2
 
3
3
  require "addressable/uri"
4
- require "ralexa/uri_signer"
5
4
 
6
5
  module Ralexa
7
6
  describe UriSigner do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ralexa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-03-26 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
16
- requirement: &70311985014320 !ruby/object:Gem::Requirement
16
+ requirement: &70339587667200 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70311985014320
24
+ version_requirements: *70339587667200
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: nokogiri
27
- requirement: &70311985013900 !ruby/object:Gem::Requirement
27
+ requirement: &70339587666780 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70311985013900
35
+ version_requirements: *70339587666780
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: minitest
38
- requirement: &70311985013480 !ruby/object:Gem::Requirement
38
+ requirement: &70339587666360 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *70311985013480
46
+ version_requirements: *70339587666360
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: rake
49
- requirement: &70311985013060 !ruby/object:Gem::Requirement
49
+ requirement: &70339587665940 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :development
56
56
  prerelease: false
57
- version_requirements: *70311985013060
57
+ version_requirements: *70339587665940
58
58
  description: Ruby client for Amazon Alexa APIs.
59
59
  email:
60
60
  - paul@annesley.cc
@@ -68,9 +68,12 @@ files:
68
68
  - README.md
69
69
  - Rakefile
70
70
  - lib/ralexa.rb
71
- - lib/ralexa/abstract_xml_service.rb
71
+ - lib/ralexa/abstract_service.rb
72
72
  - lib/ralexa/canonicalized_query_string.rb
73
73
  - lib/ralexa/client.rb
74
+ - lib/ralexa/lazy_collection.rb
75
+ - lib/ralexa/paginating_collection.rb
76
+ - lib/ralexa/paginator.rb
74
77
  - lib/ralexa/session.rb
75
78
  - lib/ralexa/top_sites.rb
76
79
  - lib/ralexa/uri_signer.rb
@@ -78,8 +81,11 @@ files:
78
81
  - ralexa.gemspec
79
82
  - spec/canonicalized_query_string_spec.rb
80
83
  - spec/client_spec.rb
81
- - spec/fixtures/global.xml
84
+ - spec/fixtures/global-page1.xml
85
+ - spec/fixtures/global-page2.xml
86
+ - spec/fixtures/global-top10.xml
82
87
  - spec/fixtures/list_countries.xml
88
+ - spec/paginator_spec.rb
83
89
  - spec/ralexa_spec.rb
84
90
  - spec/session_spec.rb
85
91
  - spec/spec_helper.rb
@@ -112,8 +118,11 @@ summary: Ruby client for Amazon Alexa APIs such as TopSites.
112
118
  test_files:
113
119
  - spec/canonicalized_query_string_spec.rb
114
120
  - spec/client_spec.rb
115
- - spec/fixtures/global.xml
121
+ - spec/fixtures/global-page1.xml
122
+ - spec/fixtures/global-page2.xml
123
+ - spec/fixtures/global-top10.xml
116
124
  - spec/fixtures/list_countries.xml
125
+ - spec/paginator_spec.rb
117
126
  - spec/ralexa_spec.rb
118
127
  - spec/session_spec.rb
119
128
  - spec/spec_helper.rb
@@ -1,27 +0,0 @@
1
- require "nokogiri"
2
-
3
- module Ralexa
4
- class AbstractXmlService
5
-
6
- def initialize(client)
7
- @client = client
8
- end
9
-
10
- private
11
-
12
- # Returns the response as an XML document stripped of namespaces.
13
- def dispatch(*params)
14
- Nokogiri::XML.parse(
15
- @client.get(host, path, merged_params(*params))
16
- ).remove_namespaces!
17
- end
18
-
19
- # A hash of the provided params hashes merged into the default_params.
20
- def merged_params(*params)
21
- params.reduce(default_params) do |merged_params, params|
22
- merged_params.merge(params)
23
- end
24
- end
25
-
26
- end
27
- end
@@ -1,45 +0,0 @@
1
- <?xml version="1.0"?>
2
- <aws:TopSitesResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:Response xmlns:aws="http://ats.amazonaws.com/doc/2005-11-21"><aws:OperationRequest><aws:RequestId>8a6c3a3f-a3c8-48d8-4775-3914d8f36e88</aws:RequestId></aws:OperationRequest><aws:TopSitesResult><aws:Alexa>
3
-
4
- <aws:TopSites>
5
- <aws:Country>
6
- <aws:CountryName>GLOBAL</aws:CountryName>
7
- <aws:CountryCode>*</aws:CountryCode>
8
- <aws:TotalSites>366720</aws:TotalSites>
9
- <aws:Sites>
10
- <aws:Site>
11
- <aws:DataUrl>wikipedia.org</aws:DataUrl>
12
- <aws:Country>
13
- <aws:Rank>6</aws:Rank>
14
- <aws:Reach>
15
- <aws:PerMillion>143000</aws:PerMillion>
16
- </aws:Reach>
17
- <aws:PageViews>
18
- <aws:PerMillion>5219</aws:PerMillion>
19
- <aws:PerUser>3.88</aws:PerUser>
20
- </aws:PageViews>
21
- </aws:Country>
22
- <aws:Global>
23
- <aws:Rank>6</aws:Rank>
24
- </aws:Global>
25
- </aws:Site>
26
- <aws:Site>
27
- <aws:DataUrl>bbc.co.uk</aws:DataUrl>
28
- <aws:Country>
29
- <aws:Rank>52</aws:Rank>
30
- <aws:Reach>
31
- <aws:PerMillion>20540</aws:PerMillion>
32
- </aws:Reach>
33
- <aws:PageViews>
34
- <aws:PerMillion>898.5</aws:PerMillion>
35
- <aws:PerUser>4.65</aws:PerUser>
36
- </aws:PageViews>
37
- </aws:Country>
38
- <aws:Global>
39
- <aws:Rank>52</aws:Rank>
40
- </aws:Global>
41
- </aws:Site>
42
- </aws:Sites>
43
- </aws:Country>
44
- </aws:TopSites>
45
- </aws:Alexa></aws:TopSitesResult><aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/"><aws:StatusCode>Success</aws:StatusCode></aws:ResponseStatus></aws:Response></aws:TopSitesResponse>