alexa 0.6.3 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.travis.yml +8 -6
- data/Gemfile +0 -4
- data/alexa.gemspec +14 -8
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/alexa.rb +2 -1
- data/lib/alexa/connection.rb +43 -46
- data/lib/alexa/version.rb +1 -1
- metadata +28 -33
- data/test/api/category_browse_test.rb +0 -41
- data/test/api/category_listings_test.rb +0 -37
- data/test/api/sites_linking_in_test.rb +0 -37
- data/test/api/traffic_history_test.rb +0 -58
- data/test/api/url_info_test.rb +0 -130
- data/test/client_test.rb +0 -65
- data/test/connection_test.rb +0 -46
- data/test/fixtures/bad_request.txt +0 -8
- data/test/fixtures/category_browse/card_games.txt +0 -480
- data/test/fixtures/category_listings/card_games.txt +0 -138
- data/test/fixtures/forbidden.txt +0 -7
- data/test/fixtures/sites_linking_in/github_count_3.txt +0 -24
- data/test/fixtures/traffic_history/alexa_error.txt +0 -8
- data/test/fixtures/traffic_history/github.txt +0 -325
- data/test/fixtures/unathorized.txt +0 -7
- data/test/fixtures/url_info/custom-response-group.txt +0 -22
- data/test/fixtures/url_info/empty_group.txt +0 -8
- data/test/fixtures/url_info/github_full.txt +0 -2853
- data/test/fixtures/url_info/github_rank.txt +0 -14
- data/test/helper.rb +0 -22
- data/test/utils_test.rb +0 -54
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 11db0614491c18c079708be97c2b65ff9f05bb9999439e4436c27bb39aec1aea
|
4
|
+
data.tar.gz: 854d04563942132728f9ae59e9a5d3046411f566413c76a21855df032f80be55
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f68b8c4202388d2c6d3874f304aeb1985b3174b9ebd1db92074172fb8923448a6fef932a7b0f80cf9fc6c6c5680643869a8bd2846ed7a8a282739d91c30ddd71
|
7
|
+
data.tar.gz: af94f14db646a36c316c5fbe94b855e7ad7d220b914dd18f5067f2376b0bdc06be3268b1e957a75e2e2eb543e29a1f1a0f2181e986e833a661d1961ce2257043
|
data/.travis.yml
CHANGED
@@ -1,10 +1,12 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
1
|
+
language: ruby
|
2
|
+
cache: bundler
|
3
|
+
|
4
|
+
before_install:
|
5
|
+
- gem install bundler
|
6
|
+
|
4
7
|
rvm:
|
5
|
-
-
|
6
|
-
- 2.
|
7
|
-
- 2.1.1
|
8
|
+
- 2.4
|
9
|
+
- 2.5
|
8
10
|
env:
|
9
11
|
- XML_PARSER=rexml
|
10
12
|
- XML_PARSER=nokogiri
|
data/Gemfile
CHANGED
data/alexa.gemspec
CHANGED
@@ -1,27 +1,33 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require "alexa/version"
|
3
5
|
|
4
6
|
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "alexa"
|
8
|
+
gem.version = Alexa::VERSION
|
5
9
|
gem.authors = ["Wojciech Wnętrzak"]
|
6
10
|
gem.email = ["w.wnetrzak@gmail.com"]
|
7
|
-
|
11
|
+
|
8
12
|
gem.summary = %q{Alexa Web Information Service library}
|
13
|
+
gem.description = %q{Alexa Web Information Service library (AWIS)}
|
9
14
|
gem.homepage = "https://github.com/morgoth/alexa"
|
10
15
|
gem.license = "MIT"
|
11
16
|
|
12
|
-
gem.
|
13
|
-
|
14
|
-
|
15
|
-
gem.
|
17
|
+
gem.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
gem.bindir = "exe"
|
21
|
+
gem.executables = gem.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
16
22
|
gem.require_paths = ["lib"]
|
17
|
-
gem.version = Alexa::VERSION
|
18
23
|
|
19
24
|
gem.required_ruby_version = ">= 1.9.3"
|
20
25
|
|
26
|
+
gem.add_dependency "aws-sigv4"
|
21
27
|
gem.add_dependency "multi_xml", ">= 0.5.0"
|
22
|
-
gem.add_dependency "faraday", "~> 0.8"
|
23
28
|
|
24
29
|
gem.add_development_dependency "minitest", ">= 5.0.0"
|
25
30
|
gem.add_development_dependency "mocha"
|
26
31
|
gem.add_development_dependency "webmock"
|
32
|
+
gem.add_development_dependency "vcr"
|
27
33
|
end
|
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "alexa"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
data/lib/alexa.rb
CHANGED
data/lib/alexa/connection.rb
CHANGED
@@ -1,80 +1,77 @@
|
|
1
1
|
require "cgi"
|
2
|
-
require "
|
3
|
-
require "
|
4
|
-
require "digest/sha1"
|
5
|
-
require "faraday"
|
6
|
-
require "time"
|
2
|
+
require "aws-sigv4"
|
3
|
+
require "net/https"
|
7
4
|
|
8
5
|
module Alexa
|
9
6
|
class Connection
|
10
|
-
|
11
|
-
attr_writer :params
|
7
|
+
attr_reader :params, :secret_access_key, :access_key_id
|
12
8
|
|
13
|
-
|
9
|
+
HEADERS = {
|
10
|
+
"Content-Type" => "application/xml",
|
11
|
+
"Accept" => "application/xml",
|
12
|
+
"User-Agent" => "Ruby alexa gem v#{Alexa::VERSION}"
|
13
|
+
}
|
14
14
|
|
15
15
|
def initialize(credentials = {})
|
16
|
-
|
17
|
-
|
18
|
-
end
|
19
|
-
|
20
|
-
def params
|
21
|
-
@params ||= {}
|
16
|
+
@secret_access_key = credentials.fetch(:secret_access_key)
|
17
|
+
@access_key_id = credentials.fetch(:access_key_id)
|
22
18
|
end
|
23
19
|
|
24
20
|
def get(params = {})
|
25
|
-
|
21
|
+
@params = params
|
26
22
|
handle_response(request).body.force_encoding(Encoding::UTF_8)
|
27
23
|
end
|
28
24
|
|
25
|
+
private
|
26
|
+
|
29
27
|
def handle_response(response)
|
30
|
-
case response
|
31
|
-
when
|
28
|
+
case response
|
29
|
+
when Net::HTTPSuccess
|
32
30
|
response
|
33
|
-
when 300...600
|
34
|
-
if response.body.nil?
|
35
|
-
raise ResponseError.new(nil, response)
|
36
|
-
else
|
37
|
-
xml = MultiXml.parse(response.body)
|
38
|
-
message = xml["Response"]["Errors"]["Error"]["Message"]
|
39
|
-
raise ResponseError.new(message, response)
|
40
|
-
end
|
41
31
|
else
|
42
|
-
raise ResponseError.new(
|
32
|
+
raise ResponseError.new(response.body, response)
|
43
33
|
end
|
44
34
|
end
|
45
35
|
|
46
36
|
def request
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
37
|
+
req = Net::HTTP::Get.new(uri)
|
38
|
+
headers.each do |key, value|
|
39
|
+
req[key] = value
|
40
|
+
end
|
41
|
+
Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
42
|
+
http.request(req)
|
43
|
+
end
|
52
44
|
end
|
53
45
|
|
54
|
-
def
|
55
|
-
|
46
|
+
def uri
|
47
|
+
@uri ||= URI.parse("#{Alexa::API_HOST}/api?" << query)
|
56
48
|
end
|
57
49
|
|
58
|
-
def
|
59
|
-
|
50
|
+
def headers
|
51
|
+
HEADERS.merge(auth_headers)
|
60
52
|
end
|
61
53
|
|
62
|
-
def
|
63
|
-
|
64
|
-
"
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
"Version" => Alexa::API_VERSION
|
69
|
-
}
|
54
|
+
def auth_headers
|
55
|
+
signer.sign_request(
|
56
|
+
http_method: "GET",
|
57
|
+
headers: HEADERS,
|
58
|
+
url: uri.to_s
|
59
|
+
).headers
|
70
60
|
end
|
71
61
|
|
72
|
-
def
|
73
|
-
|
62
|
+
def signer
|
63
|
+
Aws::Sigv4::Signer.new(
|
64
|
+
service: "awis",
|
65
|
+
region: Alexa::API_REGION,
|
66
|
+
access_key_id: access_key_id,
|
67
|
+
secret_access_key: secret_access_key
|
68
|
+
)
|
74
69
|
end
|
75
70
|
|
76
71
|
def query
|
77
|
-
|
72
|
+
params.map do |key, value|
|
73
|
+
"#{key}=#{CGI.escape(value.to_s)}"
|
74
|
+
end.sort!.join("&")
|
78
75
|
end
|
79
76
|
end
|
80
77
|
end
|
data/lib/alexa/version.rb
CHANGED
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alexa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Wojciech Wnętrzak
|
8
8
|
autorequire:
|
9
|
-
bindir:
|
9
|
+
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2018-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: aws-sigv4
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 0
|
19
|
+
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 0
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: multi_xml
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.5.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.5.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: minitest
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +80,20 @@ dependencies:
|
|
80
80
|
- - ">="
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: vcr
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
83
97
|
description: Alexa Web Information Service library (AWIS)
|
84
98
|
email:
|
85
99
|
- w.wnetrzak@gmail.com
|
@@ -94,6 +108,8 @@ files:
|
|
94
108
|
- README.md
|
95
109
|
- Rakefile
|
96
110
|
- alexa.gemspec
|
111
|
+
- bin/console
|
112
|
+
- bin/setup
|
97
113
|
- lib/alexa.rb
|
98
114
|
- lib/alexa/api/base.rb
|
99
115
|
- lib/alexa/api/category_browse.rb
|
@@ -106,27 +122,6 @@ files:
|
|
106
122
|
- lib/alexa/exceptions.rb
|
107
123
|
- lib/alexa/utils.rb
|
108
124
|
- lib/alexa/version.rb
|
109
|
-
- test/api/category_browse_test.rb
|
110
|
-
- test/api/category_listings_test.rb
|
111
|
-
- test/api/sites_linking_in_test.rb
|
112
|
-
- test/api/traffic_history_test.rb
|
113
|
-
- test/api/url_info_test.rb
|
114
|
-
- test/client_test.rb
|
115
|
-
- test/connection_test.rb
|
116
|
-
- test/fixtures/bad_request.txt
|
117
|
-
- test/fixtures/category_browse/card_games.txt
|
118
|
-
- test/fixtures/category_listings/card_games.txt
|
119
|
-
- test/fixtures/forbidden.txt
|
120
|
-
- test/fixtures/sites_linking_in/github_count_3.txt
|
121
|
-
- test/fixtures/traffic_history/alexa_error.txt
|
122
|
-
- test/fixtures/traffic_history/github.txt
|
123
|
-
- test/fixtures/unathorized.txt
|
124
|
-
- test/fixtures/url_info/custom-response-group.txt
|
125
|
-
- test/fixtures/url_info/empty_group.txt
|
126
|
-
- test/fixtures/url_info/github_full.txt
|
127
|
-
- test/fixtures/url_info/github_rank.txt
|
128
|
-
- test/helper.rb
|
129
|
-
- test/utils_test.rb
|
130
125
|
homepage: https://github.com/morgoth/alexa
|
131
126
|
licenses:
|
132
127
|
- MIT
|
@@ -147,7 +142,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
142
|
version: '0'
|
148
143
|
requirements: []
|
149
144
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
145
|
+
rubygems_version: 2.7.6
|
151
146
|
signing_key:
|
152
147
|
specification_version: 4
|
153
148
|
summary: Alexa Web Information Service library
|
@@ -1,41 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
describe Alexa::API::CategoryBrowse do
|
4
|
-
it "raises argument error when path not present" do
|
5
|
-
assert_raises Alexa::ArgumentError, /path/ do
|
6
|
-
Alexa::API::CategoryBrowse.new(:access_key_id => "fake", :secret_access_key => "fake").fetch
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "parsing xml" do
|
11
|
-
before do
|
12
|
-
stub_request(:get, %r{http://awis.amazonaws.com}).to_return(fixture("category_browse/card_games.txt"))
|
13
|
-
@category_browse = Alexa::API::CategoryBrowse.new(:access_key_id => "fake", :secret_access_key => "fake")
|
14
|
-
@category_browse.fetch(:path => "Top/Games/Card_Games")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns categories" do
|
18
|
-
assert_equal 8, @category_browse.categories.size
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns language categories" do
|
22
|
-
assert_equal 20, @category_browse.language_categories.size
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns related categories" do
|
26
|
-
assert_equal 8, @category_browse.related_categories.size
|
27
|
-
end
|
28
|
-
|
29
|
-
it "returns letter bars" do
|
30
|
-
assert_equal 36, @category_browse.letter_bars.size
|
31
|
-
end
|
32
|
-
|
33
|
-
it "has success status code" do
|
34
|
-
assert_equal "Success", @category_browse.status_code
|
35
|
-
end
|
36
|
-
|
37
|
-
it "has request id" do
|
38
|
-
assert_equal "c8bec6fe-84f3-9a8e-7444-47f86c64d74b", @category_browse.request_id
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,37 +0,0 @@
|
|
1
|
-
require "helper"
|
2
|
-
|
3
|
-
describe Alexa::API::CategoryListings do
|
4
|
-
it "raises argument error when path not present" do
|
5
|
-
assert_raises Alexa::ArgumentError, /path/ do
|
6
|
-
Alexa::API::CategoryListings.new(:access_key_id => "fake", :secret_access_key => "fake").fetch
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
describe "parsing xml" do
|
11
|
-
before do
|
12
|
-
stub_request(:get, %r{http://awis.amazonaws.com}).to_return(fixture("category_listings/card_games.txt"))
|
13
|
-
@category_listings = Alexa::API::CategoryListings.new(:access_key_id => "fake", :secret_access_key => "fake")
|
14
|
-
@category_listings.fetch(:path => "Top/Games/Card_Games")
|
15
|
-
end
|
16
|
-
|
17
|
-
it "returns recursive count" do
|
18
|
-
assert_equal 1051, @category_listings.recursive_count
|
19
|
-
end
|
20
|
-
|
21
|
-
it "returns count" do
|
22
|
-
assert_equal 1, @category_listings.count
|
23
|
-
end
|
24
|
-
|
25
|
-
it "returns listings" do
|
26
|
-
assert_equal 20, @category_listings.listings.size
|
27
|
-
end
|
28
|
-
|
29
|
-
it "has success status code" do
|
30
|
-
assert_equal "Success", @category_listings.status_code
|
31
|
-
end
|
32
|
-
|
33
|
-
it "has request id" do
|
34
|
-
assert_equal "a069b6cd-309f-df52-88be-1bd88ab45b7e", @category_listings.request_id
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|