awis-wrapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +41 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +49 -0
- data/VERSION +1 -0
- data/awis-wrapper.gemspec +73 -0
- data/lib/awis-wrapper.rb +194 -0
- data/spec/awis-wrapper_spec.rb +56 -0
- data/spec/fixtures/bad_request.xml +1 -0
- data/spec/fixtures/url_info.xml +259 -0
- data/spec/fixtures/wrong_request.xml +2 -0
- data/spec/fixtures/wrong_response.xml +9 -0
- data/spec/spec_helper.rb +13 -0
- metadata +178 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.2.1)
|
5
|
+
fakeweb (1.3.0)
|
6
|
+
git (1.2.5)
|
7
|
+
jeweler (1.8.4)
|
8
|
+
bundler (~> 1.0)
|
9
|
+
git (>= 1.2.5)
|
10
|
+
rake
|
11
|
+
rdoc
|
12
|
+
json (1.7.7)
|
13
|
+
multi_json (1.6.1)
|
14
|
+
nokogiri (1.5.6)
|
15
|
+
rake (10.0.3)
|
16
|
+
rdoc (3.12.2)
|
17
|
+
json (~> 1.4)
|
18
|
+
rspec (2.13.0)
|
19
|
+
rspec-core (~> 2.13.0)
|
20
|
+
rspec-expectations (~> 2.13.0)
|
21
|
+
rspec-mocks (~> 2.13.0)
|
22
|
+
rspec-core (2.13.1)
|
23
|
+
rspec-expectations (2.13.0)
|
24
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
25
|
+
rspec-mocks (2.13.0)
|
26
|
+
simplecov (0.7.1)
|
27
|
+
multi_json (~> 1.0)
|
28
|
+
simplecov-html (~> 0.7.1)
|
29
|
+
simplecov-html (0.7.1)
|
30
|
+
|
31
|
+
PLATFORMS
|
32
|
+
ruby
|
33
|
+
|
34
|
+
DEPENDENCIES
|
35
|
+
bundler
|
36
|
+
fakeweb
|
37
|
+
jeweler (~> 1.8.4)
|
38
|
+
nokogiri
|
39
|
+
rdoc (~> 3.12)
|
40
|
+
rspec
|
41
|
+
simplecov
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2013 Vincent.Z
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= awis-wrapper
|
2
|
+
|
3
|
+
This is the wrapper for AWIS service, this thought derive from Ishango2 project.
|
4
|
+
|
5
|
+
== Contributing to awis-wrapper
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet.
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it.
|
9
|
+
* Fork the project.
|
10
|
+
* Start a feature/bugfix branch.
|
11
|
+
* Commit and push until you are happy with your contribution.
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2013 Vincent.Z. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'rubygems'
|
4
|
+
require 'bundler'
|
5
|
+
begin
|
6
|
+
Bundler.setup(:default, :development)
|
7
|
+
rescue Bundler::BundlerError => e
|
8
|
+
$stderr.puts e.message
|
9
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
10
|
+
exit e.status_code
|
11
|
+
end
|
12
|
+
require 'rake'
|
13
|
+
|
14
|
+
require 'jeweler'
|
15
|
+
Jeweler::Tasks.new do |gem|
|
16
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
17
|
+
gem.name = "awis-wrapper"
|
18
|
+
gem.homepage = "http://github.com/zhu1230/awis-wrapper"
|
19
|
+
gem.license = "MIT"
|
20
|
+
gem.summary = %Q{Wrapper for AWIS service}
|
21
|
+
gem.description = %Q{Easy to use, to navigate around the response}
|
22
|
+
gem.email = "zhu1230@gmail.com"
|
23
|
+
gem.authors = ["Vincent.Z"]
|
24
|
+
# dependencies defined in Gemfile
|
25
|
+
end
|
26
|
+
Jeweler::RubygemsDotOrgTasks.new
|
27
|
+
|
28
|
+
require 'rspec/core'
|
29
|
+
require 'rspec/core/rake_task'
|
30
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
31
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
32
|
+
end
|
33
|
+
|
34
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
35
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
36
|
+
spec.rcov = true
|
37
|
+
end
|
38
|
+
|
39
|
+
task :default => :spec
|
40
|
+
|
41
|
+
require 'rdoc/task'
|
42
|
+
Rake::RDocTask.new do |rdoc|
|
43
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
44
|
+
|
45
|
+
rdoc.rdoc_dir = 'rdoc'
|
46
|
+
rdoc.title = "awis-wrapper #{version}"
|
47
|
+
rdoc.rdoc_files.include('README*')
|
48
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
49
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = "awis-wrapper"
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Vincent.Z"]
|
12
|
+
s.date = "2013-03-14"
|
13
|
+
s.description = "Easy to use, to navigate around the response"
|
14
|
+
s.email = "zhu1230@gmail.com"
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"awis-wrapper.gemspec",
|
29
|
+
"lib/awis-wrapper.rb",
|
30
|
+
"spec/awis-wrapper_spec.rb",
|
31
|
+
"spec/fixtures/bad_request.xml",
|
32
|
+
"spec/fixtures/url_info.xml",
|
33
|
+
"spec/fixtures/wrong_request.xml",
|
34
|
+
"spec/fixtures/wrong_response.xml",
|
35
|
+
"spec/spec_helper.rb"
|
36
|
+
]
|
37
|
+
s.homepage = "http://github.com/zhu1230/awis-wrapper"
|
38
|
+
s.licenses = ["MIT"]
|
39
|
+
s.require_paths = ["lib"]
|
40
|
+
s.rubygems_version = "1.8.23"
|
41
|
+
s.summary = "Wrapper for AWIS service"
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
s.specification_version = 3
|
45
|
+
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
|
+
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
48
|
+
s.add_development_dependency(%q<rspec>, [">= 0"])
|
49
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
50
|
+
s.add_development_dependency(%q<bundler>, [">= 0"])
|
51
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.8.4"])
|
52
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
53
|
+
s.add_development_dependency(%q<fakeweb>, [">= 0"])
|
54
|
+
else
|
55
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
56
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
57
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
58
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
59
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
60
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
61
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<nokogiri>, [">= 0"])
|
65
|
+
s.add_dependency(%q<rspec>, [">= 0"])
|
66
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
67
|
+
s.add_dependency(%q<bundler>, [">= 0"])
|
68
|
+
s.add_dependency(%q<jeweler>, ["~> 1.8.4"])
|
69
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
70
|
+
s.add_dependency(%q<fakeweb>, [">= 0"])
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
data/lib/awis-wrapper.rb
ADDED
@@ -0,0 +1,194 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2013 vincent zhu
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining
|
5
|
+
# a copy of this software and associated documentation files (the
|
6
|
+
# "Software"), to deal in the Software without restriction, including
|
7
|
+
# without limitation the rights to use, copy, modify, merge, publish,
|
8
|
+
# distribute, sublicense, and/or sell copies of the Software, and to
|
9
|
+
# permit persons to whom the Software is furnished to do so, subject to
|
10
|
+
# the following conditions:
|
11
|
+
#
|
12
|
+
# The above copyright notice and this permission notice shall be
|
13
|
+
# included in all copies or substantial portions of the Software.
|
14
|
+
#
|
15
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
16
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
17
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
18
|
+
# IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
19
|
+
# CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
20
|
+
# TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
21
|
+
# SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
22
|
+
#++
|
23
|
+
|
24
|
+
require "cgi"
|
25
|
+
require "base64"
|
26
|
+
require "openssl"
|
27
|
+
require "digest/sha1"
|
28
|
+
require "uri"
|
29
|
+
require "net/https"
|
30
|
+
require "time"
|
31
|
+
require "nokogiri"
|
32
|
+
|
33
|
+
module Amazon
|
34
|
+
|
35
|
+
class RequestError < StandardError; end
|
36
|
+
|
37
|
+
class Awis
|
38
|
+
|
39
|
+
NAMESPACE = {:aws => "http://awis.amazonaws.com/doc/2005-07-11"}
|
40
|
+
AWIS_DOMAIN = 'awis.amazonaws.com'
|
41
|
+
|
42
|
+
@@options = {
|
43
|
+
:action => "UrlInfo",
|
44
|
+
:responsegroup => "Rank"
|
45
|
+
}
|
46
|
+
|
47
|
+
@@debug = false
|
48
|
+
|
49
|
+
# Default service options
|
50
|
+
def self.options
|
51
|
+
@@options
|
52
|
+
end
|
53
|
+
|
54
|
+
# Set default service options
|
55
|
+
def self.options=(opts)
|
56
|
+
@@options = opts
|
57
|
+
end
|
58
|
+
|
59
|
+
# Get debug flag.
|
60
|
+
def self.debug
|
61
|
+
@@debug
|
62
|
+
end
|
63
|
+
|
64
|
+
# Set debug flag to true or false.
|
65
|
+
def self.debug=(dbg)
|
66
|
+
@@debug = dbg
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.configure(&proc)
|
70
|
+
raise ArgumentError, "Block is required." unless block_given?
|
71
|
+
yield @@options
|
72
|
+
end
|
73
|
+
|
74
|
+
def self.get_info(domain)
|
75
|
+
url = self.prepare_url(domain)
|
76
|
+
log "Request URL: #{url}"
|
77
|
+
res = Net::HTTP.get_response(url)
|
78
|
+
unless res.kind_of? Net::HTTPSuccess
|
79
|
+
raise Amazon::RequestError, "HTTP Response: #{res.code} #{res.message} #{res.body}"
|
80
|
+
end
|
81
|
+
log "Response text: #{res.body}"
|
82
|
+
Response.new(res.body)
|
83
|
+
end
|
84
|
+
|
85
|
+
# Response object returned after a REST call to Amazon service.
|
86
|
+
class Response
|
87
|
+
# XML input is in string format
|
88
|
+
def initialize(xml)
|
89
|
+
@doc = Nokogiri::XML(xml)
|
90
|
+
@namespace = Awis::NAMESPACE
|
91
|
+
end
|
92
|
+
|
93
|
+
def doc
|
94
|
+
@doc
|
95
|
+
end
|
96
|
+
|
97
|
+
def test
|
98
|
+
@doc.xpath("//aws:Country", {:aws => "http://awis.amazonaws.com/doc/2005-07-11"})
|
99
|
+
end
|
100
|
+
|
101
|
+
def xpath(path)
|
102
|
+
@doc.xpath(path, @namesapce)
|
103
|
+
end
|
104
|
+
|
105
|
+
def get(tag)
|
106
|
+
Element.new @doc.at_xpath("//aws:#{tag.capitalize}", @namespace)
|
107
|
+
end
|
108
|
+
|
109
|
+
def get_all(tag)
|
110
|
+
@doc.xpath("//aws:#{tag.capitalize}", @namespace).collect{|data|Element.new data}
|
111
|
+
end
|
112
|
+
|
113
|
+
# Return error code
|
114
|
+
def error
|
115
|
+
@doc.xpath("//aws:StatusMessage").first.content
|
116
|
+
end
|
117
|
+
|
118
|
+
# Return error message.
|
119
|
+
def success?
|
120
|
+
(@doc.xpath "//aws:StatusCode").first.content == "Success"
|
121
|
+
end
|
122
|
+
|
123
|
+
#returns inner html of any tag in awis response i.e resp.rank => 3
|
124
|
+
def method_missing(methodId)
|
125
|
+
puts methodId
|
126
|
+
@doc.send methodId
|
127
|
+
end
|
128
|
+
|
129
|
+
end
|
130
|
+
|
131
|
+
class Element
|
132
|
+
def initialize(arg)
|
133
|
+
@node = arg
|
134
|
+
end
|
135
|
+
|
136
|
+
def method_missing(methodId)
|
137
|
+
result = @node.xpath(".//aws:#{methodId.capitalize}", Awis::NAMESPACE)
|
138
|
+
if result
|
139
|
+
result.collect do |r|
|
140
|
+
Element.new r
|
141
|
+
end
|
142
|
+
else
|
143
|
+
result
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
def to_s
|
148
|
+
@node.content
|
149
|
+
end
|
150
|
+
|
151
|
+
|
152
|
+
end
|
153
|
+
|
154
|
+
protected
|
155
|
+
|
156
|
+
def self.log(s)
|
157
|
+
return unless self.debug
|
158
|
+
if defined? RAILS_DEFAULT_LOGGER
|
159
|
+
RAILS_DEFAULT_LOGGER.error(s)
|
160
|
+
elsif defined? LOGGER
|
161
|
+
LOGGER.error(s)
|
162
|
+
else
|
163
|
+
puts s
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
private
|
168
|
+
|
169
|
+
# Converts a hash into a query string (e.g. {a => 1, b => 2} becomes "a=1&b=2")
|
170
|
+
def self.escape_query(query)
|
171
|
+
query.to_a.collect { |item| item.first + '=' + CGI::escape(item.last.to_s) }.join('&')
|
172
|
+
end
|
173
|
+
|
174
|
+
def self.prepare_url(domain)
|
175
|
+
query = {
|
176
|
+
'AWSAccessKeyId' => self.options[:aws_access_key_id],
|
177
|
+
'Action' => self.options[:action],
|
178
|
+
'ResponseGroup' => self.options[:responsegroup],
|
179
|
+
'SignatureMethod' => 'HmacSHA1',
|
180
|
+
'SignatureVersion' => 2,
|
181
|
+
'Timestamp' => Time.now.utc.iso8601,
|
182
|
+
'Url' => domain
|
183
|
+
}
|
184
|
+
awis_domain = Amazon::Awis::AWIS_DOMAIN
|
185
|
+
URI.parse("http://#{awis_domain}/?" + escape_query(query.merge({
|
186
|
+
'Signature' => Base64.encode64(
|
187
|
+
OpenSSL::HMAC.digest(
|
188
|
+
'sha1', self.options[:aws_secret_key],
|
189
|
+
"GET\n#{awis_domain}\n/\n" + escape_query(query).strip)).chomp
|
190
|
+
})))
|
191
|
+
end
|
192
|
+
end
|
193
|
+
|
194
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
|
2
|
+
|
3
|
+
describe "AwisWrapper" do
|
4
|
+
|
5
|
+
context "with all correct configuration" do
|
6
|
+
|
7
|
+
let(:url_info) { IO.read(Pathname.new(File.expand_path(File.dirname(__FILE__))).join("fixtures", "url_info.xml")) }
|
8
|
+
|
9
|
+
let(:bad_request) { IO.read(Pathname.new(File.expand_path(File.dirname(__FILE__))).join("fixtures", "bad_request.xml")) }
|
10
|
+
|
11
|
+
let(:wrong_response) { IO.read(Pathname.new(File.expand_path(File.dirname(__FILE__))).join("fixtures", "wrong_response.xml")) }
|
12
|
+
|
13
|
+
before(:each) do
|
14
|
+
Amazon::Awis.options = {:aws_access_key_id => "test_123", :aws_secret_key => "test_456"}
|
15
|
+
end
|
16
|
+
|
17
|
+
it "would return the correct url" do
|
18
|
+
Amazon::Awis.options[:action] = 'UrlInfo'
|
19
|
+
Amazon::Awis.options[:responsegroup] = 'RankByCountry'
|
20
|
+
FakeWeb.register_uri(:get, %r{http://#{Amazon::Awis::AWIS_DOMAIN}/?.*}, body: url_info)
|
21
|
+
response = Amazon::Awis.get_info("yahoo.com")
|
22
|
+
response.doc.should_not be_nil
|
23
|
+
response.success?.should == true
|
24
|
+
response.get_all("country").size.should == 34
|
25
|
+
end
|
26
|
+
|
27
|
+
it "return bad url with the wrong action" do
|
28
|
+
Amazon::Awis.options[:action] = 'wrong_action123'
|
29
|
+
Amazon::Awis.options[:responsegroup] = 'RankByCountry'
|
30
|
+
FakeWeb.register_uri(:get, %r{http://#{Amazon::Awis::AWIS_DOMAIN}/?.*}, body: bad_request, :status => ["400", "Bad Request"])
|
31
|
+
expect { Amazon::Awis::get_info("yahoo.com") }.to raise_error(Amazon::RequestError)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "return error code with wrong response group" do
|
35
|
+
Amazon::Awis.options[:action] = 'UrlInfo'
|
36
|
+
Amazon::Awis.options[:responsegroup] = 'RankByzzzzzCsountry' # made one typo for this example
|
37
|
+
FakeWeb.register_uri(:get, %r{http://#{Amazon::Awis::AWIS_DOMAIN}/?.*}, body: wrong_response)
|
38
|
+
response = Amazon::Awis.get_info('yahoo.com')
|
39
|
+
response.success?.should == false
|
40
|
+
response.error.should == "The following response groups are invalid: RankByCsountry"
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
end
|
45
|
+
|
46
|
+
context "with missing configuration" do
|
47
|
+
|
48
|
+
let(:wrong_request) { IO.read(Pathname.new(File.expand_path(File.dirname(__FILE__))).join('fixtures', 'wrong_request.xml')) }
|
49
|
+
|
50
|
+
it "would arise error" do
|
51
|
+
FakeWeb.register_uri(:get, %r{http://#{Amazon::Awis::AWIS_DOMAIN}/?.*}, body: wrong_request, :status => ["403", "Forbidden"])
|
52
|
+
expect { Amazon::Awis::get_info("yahoo.com") }.to raise_error(Amazon::RequestError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<Response><Errors><Error><Code>InvalidAction</Code><Message>The action UrlzInfo is not valid for this web service.</Message></Error></Errors><RequestID>c47adb51-1661-a917-d296-217fb0b27ef1</RequestID></Response>
|
@@ -0,0 +1,259 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
|
3
|
+
<aws:Response xmlns:aws="http://awis.amazonaws.com/doc/2005-07-11">
|
4
|
+
<aws:OperationRequest>
|
5
|
+
<aws:RequestId>d886604f-0c96-bf90-3f0d-802f75465f09</aws:RequestId>
|
6
|
+
</aws:OperationRequest>
|
7
|
+
<aws:UrlInfoResult>
|
8
|
+
<aws:Alexa>
|
9
|
+
|
10
|
+
<aws:TrafficData>
|
11
|
+
<aws:DataUrl type="canonical">yahoo.com/</aws:DataUrl>
|
12
|
+
<aws:RankByCountry>
|
13
|
+
<aws:Country Code="US">
|
14
|
+
<aws:Rank>4</aws:Rank>
|
15
|
+
<aws:Contribution>
|
16
|
+
<aws:PageViews>35.5%</aws:PageViews>
|
17
|
+
<aws:Users>33.3%</aws:Users>
|
18
|
+
</aws:Contribution>
|
19
|
+
</aws:Country>
|
20
|
+
<aws:Country Code="IN">
|
21
|
+
<aws:Rank>5</aws:Rank>
|
22
|
+
<aws:Contribution>
|
23
|
+
<aws:PageViews>10.3%</aws:PageViews>
|
24
|
+
<aws:Users>8.9%</aws:Users>
|
25
|
+
</aws:Contribution>
|
26
|
+
</aws:Country>
|
27
|
+
<aws:Country Code="TW">
|
28
|
+
<aws:Rank>1</aws:Rank>
|
29
|
+
<aws:Contribution>
|
30
|
+
<aws:PageViews>10.8%</aws:PageViews>
|
31
|
+
<aws:Users>3.8%</aws:Users>
|
32
|
+
</aws:Contribution>
|
33
|
+
</aws:Country>
|
34
|
+
<aws:Country Code="GB">
|
35
|
+
<aws:Rank>8</aws:Rank>
|
36
|
+
<aws:Contribution>
|
37
|
+
<aws:PageViews>2.5%</aws:PageViews>
|
38
|
+
<aws:Users>3.2%</aws:Users>
|
39
|
+
</aws:Contribution>
|
40
|
+
</aws:Country>
|
41
|
+
<aws:Country Code="IR">
|
42
|
+
<aws:Rank>2</aws:Rank>
|
43
|
+
<aws:Contribution>
|
44
|
+
<aws:PageViews>2.8%</aws:PageViews>
|
45
|
+
<aws:Users>3.2%</aws:Users>
|
46
|
+
</aws:Contribution>
|
47
|
+
</aws:Country>
|
48
|
+
<aws:Country Code="BR">
|
49
|
+
<aws:Rank>9</aws:Rank>
|
50
|
+
<aws:Contribution>
|
51
|
+
<aws:PageViews>2.0%</aws:PageViews>
|
52
|
+
<aws:Users>2.9%</aws:Users>
|
53
|
+
</aws:Contribution>
|
54
|
+
</aws:Country>
|
55
|
+
<aws:Country Code="ID">
|
56
|
+
<aws:Rank>6</aws:Rank>
|
57
|
+
<aws:Contribution>
|
58
|
+
<aws:PageViews>2.9%</aws:PageViews>
|
59
|
+
<aws:Users>2.8%</aws:Users>
|
60
|
+
</aws:Contribution>
|
61
|
+
</aws:Country>
|
62
|
+
<aws:Country Code="MX">
|
63
|
+
<aws:Rank>6</aws:Rank>
|
64
|
+
<aws:Contribution>
|
65
|
+
<aws:PageViews>2.1%</aws:PageViews>
|
66
|
+
<aws:Users>2.3%</aws:Users>
|
67
|
+
</aws:Contribution>
|
68
|
+
</aws:Country>
|
69
|
+
<aws:Country Code="CN">
|
70
|
+
<aws:Rank>36</aws:Rank>
|
71
|
+
<aws:Contribution>
|
72
|
+
<aws:PageViews>1.5%</aws:PageViews>
|
73
|
+
<aws:Users>2.2%</aws:Users>
|
74
|
+
</aws:Contribution>
|
75
|
+
</aws:Country>
|
76
|
+
<aws:Country Code="CA">
|
77
|
+
<aws:Rank>5</aws:Rank>
|
78
|
+
<aws:Contribution>
|
79
|
+
<aws:PageViews>2.1%</aws:PageViews>
|
80
|
+
<aws:Users>2.1%</aws:Users>
|
81
|
+
</aws:Contribution>
|
82
|
+
</aws:Country>
|
83
|
+
<aws:Country Code="IT">
|
84
|
+
<aws:Rank>6</aws:Rank>
|
85
|
+
<aws:Contribution>
|
86
|
+
<aws:PageViews>1.2%</aws:PageViews>
|
87
|
+
<aws:Users>2.0%</aws:Users>
|
88
|
+
</aws:Contribution>
|
89
|
+
</aws:Country>
|
90
|
+
<aws:Country Code="FR">
|
91
|
+
<aws:Rank>10</aws:Rank>
|
92
|
+
<aws:Contribution>
|
93
|
+
<aws:PageViews>1.4%</aws:PageViews>
|
94
|
+
<aws:Users>1.9%</aws:Users>
|
95
|
+
</aws:Contribution>
|
96
|
+
</aws:Country>
|
97
|
+
<aws:Country Code="DE">
|
98
|
+
<aws:Rank>10</aws:Rank>
|
99
|
+
<aws:Contribution>
|
100
|
+
<aws:PageViews>1.1%</aws:PageViews>
|
101
|
+
<aws:Users>1.7%</aws:Users>
|
102
|
+
</aws:Contribution>
|
103
|
+
</aws:Country>
|
104
|
+
<aws:Country Code="NG">
|
105
|
+
<aws:Rank>4</aws:Rank>
|
106
|
+
<aws:Contribution>
|
107
|
+
<aws:PageViews>1.5%</aws:PageViews>
|
108
|
+
<aws:Users>1.5%</aws:Users>
|
109
|
+
</aws:Contribution>
|
110
|
+
</aws:Country>
|
111
|
+
<aws:Country Code="ES">
|
112
|
+
<aws:Rank>7</aws:Rank>
|
113
|
+
<aws:Contribution>
|
114
|
+
<aws:PageViews>0.9%</aws:PageViews>
|
115
|
+
<aws:Users>1.5%</aws:Users>
|
116
|
+
</aws:Contribution>
|
117
|
+
</aws:Country>
|
118
|
+
<aws:Country Code="PH">
|
119
|
+
<aws:Rank>5</aws:Rank>
|
120
|
+
<aws:Contribution>
|
121
|
+
<aws:PageViews>1.4%</aws:PageViews>
|
122
|
+
<aws:Users>1.2%</aws:Users>
|
123
|
+
</aws:Contribution>
|
124
|
+
</aws:Country>
|
125
|
+
<aws:Country Code="PK">
|
126
|
+
<aws:Rank>4</aws:Rank>
|
127
|
+
<aws:Contribution>
|
128
|
+
<aws:PageViews>1.0%</aws:PageViews>
|
129
|
+
<aws:Users>1.2%</aws:Users>
|
130
|
+
</aws:Contribution>
|
131
|
+
</aws:Country>
|
132
|
+
<aws:Country Code="AU">
|
133
|
+
<aws:Rank>5</aws:Rank>
|
134
|
+
<aws:Contribution>
|
135
|
+
<aws:PageViews>0.8%</aws:PageViews>
|
136
|
+
<aws:Users>1.1%</aws:Users>
|
137
|
+
</aws:Contribution>
|
138
|
+
</aws:Country>
|
139
|
+
<aws:Country Code="EG">
|
140
|
+
<aws:Rank>5</aws:Rank>
|
141
|
+
<aws:Contribution>
|
142
|
+
<aws:PageViews>0.7%</aws:PageViews>
|
143
|
+
<aws:Users>1.0%</aws:Users>
|
144
|
+
</aws:Contribution>
|
145
|
+
</aws:Country>
|
146
|
+
<aws:Country Code="RO">
|
147
|
+
<aws:Rank>5</aws:Rank>
|
148
|
+
<aws:Contribution>
|
149
|
+
<aws:PageViews>0.7%</aws:PageViews>
|
150
|
+
<aws:Users>1.0%</aws:Users>
|
151
|
+
</aws:Contribution>
|
152
|
+
</aws:Country>
|
153
|
+
<aws:Country Code="MY">
|
154
|
+
<aws:Rank>6</aws:Rank>
|
155
|
+
<aws:Contribution>
|
156
|
+
<aws:PageViews>0.7%</aws:PageViews>
|
157
|
+
<aws:Users>0.9%</aws:Users>
|
158
|
+
</aws:Contribution>
|
159
|
+
</aws:Country>
|
160
|
+
<aws:Country Code="AR">
|
161
|
+
<aws:Rank>7</aws:Rank>
|
162
|
+
<aws:Contribution>
|
163
|
+
<aws:PageViews>0.6%</aws:PageViews>
|
164
|
+
<aws:Users>0.9%</aws:Users>
|
165
|
+
</aws:Contribution>
|
166
|
+
</aws:Country>
|
167
|
+
<aws:Country Code="HK">
|
168
|
+
<aws:Rank>4</aws:Rank>
|
169
|
+
<aws:Contribution>
|
170
|
+
<aws:PageViews>1.5%</aws:PageViews>
|
171
|
+
<aws:Users>0.8%</aws:Users>
|
172
|
+
</aws:Contribution>
|
173
|
+
</aws:Country>
|
174
|
+
<aws:Country Code="TH">
|
175
|
+
<aws:Rank>6</aws:Rank>
|
176
|
+
<aws:Contribution>
|
177
|
+
<aws:PageViews>0.6%</aws:PageViews>
|
178
|
+
<aws:Users>0.7%</aws:Users>
|
179
|
+
</aws:Contribution>
|
180
|
+
</aws:Country>
|
181
|
+
<aws:Country Code="SA">
|
182
|
+
<aws:Rank>6</aws:Rank>
|
183
|
+
<aws:Contribution>
|
184
|
+
<aws:PageViews>0.5%</aws:PageViews>
|
185
|
+
<aws:Users>0.7%</aws:Users>
|
186
|
+
</aws:Contribution>
|
187
|
+
</aws:Country>
|
188
|
+
<aws:Country Code="VN">
|
189
|
+
<aws:Rank>8</aws:Rank>
|
190
|
+
<aws:Contribution>
|
191
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
192
|
+
<aws:Users>0.6%</aws:Users>
|
193
|
+
</aws:Contribution>
|
194
|
+
</aws:Country>
|
195
|
+
<aws:Country Code="SG">
|
196
|
+
<aws:Rank>5</aws:Rank>
|
197
|
+
<aws:Contribution>
|
198
|
+
<aws:PageViews>0.6%</aws:PageViews>
|
199
|
+
<aws:Users>0.6%</aws:Users>
|
200
|
+
</aws:Contribution>
|
201
|
+
</aws:Country>
|
202
|
+
<aws:Country Code="ZA">
|
203
|
+
<aws:Rank>5</aws:Rank>
|
204
|
+
<aws:Contribution>
|
205
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
206
|
+
<aws:Users>0.6%</aws:Users>
|
207
|
+
</aws:Contribution>
|
208
|
+
</aws:Country>
|
209
|
+
<aws:Country Code="CO">
|
210
|
+
<aws:Rank>6</aws:Rank>
|
211
|
+
<aws:Contribution>
|
212
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
213
|
+
<aws:Users>0.6%</aws:Users>
|
214
|
+
</aws:Contribution>
|
215
|
+
</aws:Country>
|
216
|
+
<aws:Country Code="RU">
|
217
|
+
<aws:Rank>31</aws:Rank>
|
218
|
+
<aws:Contribution>
|
219
|
+
<aws:PageViews>0.3%</aws:PageViews>
|
220
|
+
<aws:Users>0.6%</aws:Users>
|
221
|
+
</aws:Contribution>
|
222
|
+
</aws:Country>
|
223
|
+
<aws:Country Code="KR">
|
224
|
+
<aws:Rank>12</aws:Rank>
|
225
|
+
<aws:Contribution>
|
226
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
227
|
+
<aws:Users>0.6%</aws:Users>
|
228
|
+
</aws:Contribution>
|
229
|
+
</aws:Country>
|
230
|
+
<aws:Country Code="BD">
|
231
|
+
<aws:Rank>4</aws:Rank>
|
232
|
+
<aws:Contribution>
|
233
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
234
|
+
<aws:Users>0.6%</aws:Users>
|
235
|
+
</aws:Contribution>
|
236
|
+
</aws:Country>
|
237
|
+
<aws:Country Code="GR">
|
238
|
+
<aws:Rank>6</aws:Rank>
|
239
|
+
<aws:Contribution>
|
240
|
+
<aws:PageViews>0.4%</aws:PageViews>
|
241
|
+
<aws:Users>0.5%</aws:Users>
|
242
|
+
</aws:Contribution>
|
243
|
+
</aws:Country>
|
244
|
+
<aws:Country Code="O">
|
245
|
+
<aws:Rank/>
|
246
|
+
<aws:Contribution>
|
247
|
+
<aws:PageViews>9.5%</aws:PageViews>
|
248
|
+
<aws:Users>12.7%</aws:Users>
|
249
|
+
</aws:Contribution>
|
250
|
+
</aws:Country>
|
251
|
+
</aws:RankByCountry>
|
252
|
+
</aws:TrafficData>
|
253
|
+
</aws:Alexa>
|
254
|
+
</aws:UrlInfoResult>
|
255
|
+
<aws:ResponseStatus xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
|
256
|
+
<aws:StatusCode>Success</aws:StatusCode>
|
257
|
+
</aws:ResponseStatus>
|
258
|
+
</aws:Response>
|
259
|
+
</aws:UrlInfoResponse>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<?xml version="1.0"?>
|
2
|
+
<aws:UrlInfoResponse xmlns:aws="http://alexa.amazonaws.com/doc/2005-10-05/">
|
3
|
+
<aws:Response>
|
4
|
+
<aws:ResponseStatus>
|
5
|
+
<aws:StatusCode>InvalidResponseGroups</aws:StatusCode>
|
6
|
+
<aws:StatusMessage>The following response groups are invalid: RankByCsountry</aws:StatusMessage>
|
7
|
+
</aws:ResponseStatus>
|
8
|
+
</aws:Response>
|
9
|
+
</aws:UrlInfoResponse>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'awis-wrapper'
|
5
|
+
require 'fakeweb'
|
6
|
+
|
7
|
+
# Requires supporting files with custom matchers and macros, etc,
|
8
|
+
# in ./support/ and its subdirectories.
|
9
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: awis-wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Vincent.Z
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-14 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: nokogiri
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rdoc
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.12'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3.12'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: bundler
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ! '>='
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ! '>='
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: jeweler
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ~>
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: 1.8.4
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ~>
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: 1.8.4
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: simplecov
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :development
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
- !ruby/object:Gem::Dependency
|
111
|
+
name: fakeweb
|
112
|
+
requirement: !ruby/object:Gem::Requirement
|
113
|
+
none: false
|
114
|
+
requirements:
|
115
|
+
- - ! '>='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
none: false
|
122
|
+
requirements:
|
123
|
+
- - ! '>='
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description: Easy to use, to navigate around the response
|
127
|
+
email: zhu1230@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files:
|
131
|
+
- LICENSE.txt
|
132
|
+
- README.rdoc
|
133
|
+
files:
|
134
|
+
- .document
|
135
|
+
- .rspec
|
136
|
+
- Gemfile
|
137
|
+
- Gemfile.lock
|
138
|
+
- LICENSE.txt
|
139
|
+
- README.rdoc
|
140
|
+
- Rakefile
|
141
|
+
- VERSION
|
142
|
+
- awis-wrapper.gemspec
|
143
|
+
- lib/awis-wrapper.rb
|
144
|
+
- spec/awis-wrapper_spec.rb
|
145
|
+
- spec/fixtures/bad_request.xml
|
146
|
+
- spec/fixtures/url_info.xml
|
147
|
+
- spec/fixtures/wrong_request.xml
|
148
|
+
- spec/fixtures/wrong_response.xml
|
149
|
+
- spec/spec_helper.rb
|
150
|
+
homepage: http://github.com/zhu1230/awis-wrapper
|
151
|
+
licenses:
|
152
|
+
- MIT
|
153
|
+
post_install_message:
|
154
|
+
rdoc_options: []
|
155
|
+
require_paths:
|
156
|
+
- lib
|
157
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
158
|
+
none: false
|
159
|
+
requirements:
|
160
|
+
- - ! '>='
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
segments:
|
164
|
+
- 0
|
165
|
+
hash: 3170519927619946549
|
166
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
167
|
+
none: false
|
168
|
+
requirements:
|
169
|
+
- - ! '>='
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 1.8.23
|
175
|
+
signing_key:
|
176
|
+
specification_version: 3
|
177
|
+
summary: Wrapper for AWIS service
|
178
|
+
test_files: []
|