morgoth-alexa 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.
- data/VERSION +1 -1
- data/alexa.gemspec +2 -2
- data/lib/alexa/url_info.rb +24 -3
- data/test/alexa_test.rb +6 -0
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.0.
|
1
|
+
0.0.3
|
data/alexa.gemspec
CHANGED
@@ -2,11 +2,11 @@
|
|
2
2
|
|
3
3
|
Gem::Specification.new do |s|
|
4
4
|
s.name = %q{alexa}
|
5
|
-
s.version = "0.0.
|
5
|
+
s.version = "0.0.3"
|
6
6
|
|
7
7
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
8
8
|
s.authors = ["Wojciech Wnętrzak"]
|
9
|
-
s.date = %q{2009-07-
|
9
|
+
s.date = %q{2009-07-06}
|
10
10
|
s.email = %q{w.wnetrzak@gmail.com}
|
11
11
|
s.extra_rdoc_files = [
|
12
12
|
"LICENSE",
|
data/lib/alexa/url_info.rb
CHANGED
@@ -7,8 +7,8 @@ module Alexa
|
|
7
7
|
:rank_by_country, :rank_by_city, :usage_statistics
|
8
8
|
|
9
9
|
def initialize(options = {} )
|
10
|
-
@access_key_id = options[:access_key_id] or raise ArgumentError.new("you must specify
|
11
|
-
@secret_access_key = options[:secret_access_key] or raise ArgumentError.new("you must specify
|
10
|
+
@access_key_id = options[:access_key_id] or raise ArgumentError.new("you must specify access_key_id")
|
11
|
+
@secret_access_key = options[:secret_access_key] or raise ArgumentError.new("you must specify secret_access_key")
|
12
12
|
@host = options[:host] or raise ArgumentError.new("you must specify host")
|
13
13
|
@response_group = options[:response_group] || RESPONSE_GROUP
|
14
14
|
end
|
@@ -18,7 +18,10 @@ module Alexa
|
|
18
18
|
timestamp = ( Time::now ).utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
|
19
19
|
signature = generate_signature(secret_access_key, action, timestamp)
|
20
20
|
url = generate_url(action, access_key_id, signature, timestamp, response_group, host)
|
21
|
-
|
21
|
+
response = Net::HTTP.start(url.host) do |http|
|
22
|
+
http.get url.request_uri
|
23
|
+
end
|
24
|
+
@xml_response = handle_response(response).body
|
22
25
|
end
|
23
26
|
|
24
27
|
def parse_xml(xml)
|
@@ -45,6 +48,24 @@ module Alexa
|
|
45
48
|
|
46
49
|
private
|
47
50
|
|
51
|
+
def handle_response(response)
|
52
|
+
case response.code.to_i
|
53
|
+
when 200...300
|
54
|
+
response
|
55
|
+
when 300...600
|
56
|
+
if response.body.nil?
|
57
|
+
raise StandardError.new(response)
|
58
|
+
else
|
59
|
+
@xml_response = response.body
|
60
|
+
xml = XmlSimple.xml_in(response.body, 'ForceArray' => false)
|
61
|
+
message = xml['Errors']['Error']['Message']
|
62
|
+
raise StandardError.new(message)
|
63
|
+
end
|
64
|
+
else
|
65
|
+
raise StandardError.new("Unknown code: #{respnse.code}")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
48
69
|
def generate_signature(secret_acces_key, action, timestamp)
|
49
70
|
Base64.encode64( OpenSSL::HMAC.digest( OpenSSL::Digest::Digest.new( "sha1" ), secret_access_key, action + timestamp)).strip
|
50
71
|
end
|
data/test/alexa_test.rb
CHANGED
@@ -123,6 +123,12 @@ class AlexaTest < Test::Unit::TestCase
|
|
123
123
|
end
|
124
124
|
|
125
125
|
end
|
126
|
+
|
127
|
+
should "not raise error when response is OK" do
|
128
|
+
assert_nothing_raised do
|
129
|
+
@alexa.send :handle_response, Net::HTTPOK.new("1.1", "200", "OK")
|
130
|
+
end
|
131
|
+
end
|
126
132
|
end
|
127
133
|
|
128
134
|
should "Raise argumment error if keys or host are not present" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: morgoth-alexa
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- "Wojciech Wn\xC4\x99trzak"
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-07-
|
12
|
+
date: 2009-07-06 00:00:00 -07:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|