alexa 0.2.1 → 0.2.2

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.
@@ -1,28 +1,39 @@
1
- = Alexa Web Information Service
1
+ # Alexa Web Information Service #
2
2
 
3
- == Usage
4
- Alexa.url_info(:access_key_id => 'key', :secret_access_key => 'secret', :host => 'site.com')
5
- # also you can specify option :response_group => 'Rank,ContactInfo' or any other valid group,
6
- # see: http://docs.amazonwebservices.com/AlexaWebInfoService/2005-07-11/
7
- # default response group takes all the available options
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")
8
13
 
9
14
  returns object with methods:
10
15
  :xml_response, :rank, :data_url, :site_title, :site_description, :language_locale, :language_encoding,
11
16
  :links_in_count, :keywords, :related_links, :speed_median_load_time, :speed_percentile,
12
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.
13
23
 
14
24
  You can set configuration in block like this:
25
+
26
+ ``` ruby
15
27
  Alexa.config do |c|
16
28
  c.access_key_id = "key"
17
29
  c.secret_access_key = "secret"
18
30
  end
31
+ ```
19
32
 
20
- == Installation
21
- gem install alexa
33
+ ## Contributors ##
22
34
 
23
- == Contributors
24
- * rmoriz[http://github.com/rmoriz]
35
+ * [rmoriz](https://github.com/rmoriz)
25
36
 
26
- == Copyright
37
+ ## Copyright ##
27
38
 
28
39
  Copyright (c) 2011 Wojciech Wnętrzak. See LICENSE for details.
data/alexa.gemspec CHANGED
@@ -1,25 +1,21 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
3
- require "alexa/version"
2
+ require File.expand_path('../lib/alexa/version', __FILE__)
4
3
 
5
- Gem::Specification.new do |s|
6
- s.name = "alexa"
7
- s.version = Alexa::VERSION
8
- s.platform = Gem::Platform::RUBY
9
- s.authors = ["Wojciech Wnętrzak"]
10
- s.email = ["w.wnetrzak@gmail.com"]
11
- s.homepage = "https://github.com/morgoth/alexa"
12
- s.summary = %q{Alexa Web Information Service library}
13
- s.description = %q{Alexa Web Information Service library (AWIS)}
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Wojciech Wnętrzak"]
6
+ gem.email = ["w.wnetrzak@gmail.com"]
7
+ gem.description = %q{Alexa Web Information Service library (AWIS)}
8
+ gem.summary = %q{Alexa Web Information Service library}
9
+ gem.homepage = "https://github.com/morgoth/alexa"
14
10
 
15
- s.rubyforge_project = "alexa"
11
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
12
+ gem.files = `git ls-files`.split("\n")
13
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ gem.name = "alexa"
15
+ gem.require_paths = ['lib']
16
+ gem.version = Alexa::VERSION
16
17
 
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
- s.require_paths = ["lib"]
18
+ gem.add_dependency "xml-simple"
21
19
 
22
- s.add_dependency "xml-simple"
23
-
24
- s.add_development_dependency "mocha"
20
+ gem.add_development_dependency "mocha"
25
21
  end
@@ -1,6 +1,7 @@
1
1
  module Alexa
2
2
  class UrlInfo
3
3
  API_VERSION = "2005-07-11"
4
+ HOST = "awis.amazonaws.com"
4
5
  RESPONSE_GROUP = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks,RankByCountry,RankByCity,UsageStats"
5
6
 
6
7
  attr_accessor :host, :response_group, :xml_response,
@@ -79,21 +80,32 @@ module Alexa
79
80
  end
80
81
 
81
82
  def signature
82
- @signature ||= Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), Alexa.config.secret_access_key, "UrlInfo" + timestamp)).strip
83
+ Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), Alexa.config.secret_access_key, sign)).strip
83
84
  end
84
85
 
85
86
  def url
86
- URI.parse("http://awis.amazonaws.com/?" +
87
- {
88
- "Action" => "UrlInfo",
89
- "AWSAccessKeyId" => Alexa.config.access_key_id,
90
- "Signature" => signature,
91
- "Timestamp" => timestamp,
92
- "ResponseGroup" => response_group,
93
- "Url" => host,
94
- "Version" => API_VERSION
95
- }.map { |key, value| "#{key}=#{CGI::escape(value)}" }.sort.join("&")
96
- )
87
+ URI.parse("http://#{HOST}/?" + query + "&Signature=" + CGI::escape(signature))
88
+ end
89
+
90
+ def params_without_signature
91
+ {
92
+ "Action" => "UrlInfo",
93
+ "AWSAccessKeyId" => Alexa.config.access_key_id,
94
+ "ResponseGroup" => response_group,
95
+ "SignatureMethod" => "HmacSHA1",
96
+ "SignatureVersion" => "2",
97
+ "Timestamp" => timestamp,
98
+ "Url" => host,
99
+ "Version" => API_VERSION
100
+ }
101
+ end
102
+
103
+ def sign
104
+ "GET\n" + HOST + "\n/\n" + query
105
+ end
106
+
107
+ def query
108
+ params_without_signature.map { |key, value| "#{key}=#{CGI::escape(value)}" }.sort.join("&")
97
109
  end
98
110
  end
99
111
  end
data/lib/alexa/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Alexa
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -11,14 +11,14 @@ describe "Alexa::UlrInfo" do
11
11
 
12
12
  it "should Generate signature" do
13
13
  @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
14
- assert_equal "I1mPdBy+flhhzqqUaamNq9gq190=", @alexa.send(:signature)
14
+ assert_equal "5Jql3rds3vL9hyijnYtUIVv1H8Q=", @alexa.send(:signature)
15
15
  end
16
16
 
17
17
  it "should Generate url" do
18
18
  @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
19
19
  @alexa.response_group = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks"
20
20
  @alexa.host = "heroku.com"
21
- expected_uri = "/?AWSAccessKeyId=12345678901234567890&Action=UrlInfo&ResponseGroup=Rank%2CContactInfo%2CAdultContent%2CSpeed%2CLanguage%2CKeywords%2COwnedDomains%2CLinksInCount%2CSiteData%2CRelatedLinks&Signature=I1mPdBy%2BflhhzqqUaamNq9gq190%3D&Timestamp=2009-07-03T07%3A22%3A24.000Z&Url=heroku.com&Version=2005-07-11"
21
+ expected_uri = "/?AWSAccessKeyId=12345678901234567890&Action=UrlInfo&ResponseGroup=Rank%2CContactInfo%2CAdultContent%2CSpeed%2CLanguage%2CKeywords%2COwnedDomains%2CLinksInCount%2CSiteData%2CRelatedLinks&SignatureMethod=HmacSHA1&SignatureVersion=2&Timestamp=2009-07-03T07%3A22%3A24.000Z&Url=heroku.com&Version=2005-07-11&Signature=H9VtDwXGXT5O8NodLOlsc2wIfv8%3D"
22
22
  assert_equal expected_uri, @alexa.send(:url).request_uri
23
23
  assert_equal "awis.amazonaws.com", @alexa.send(:url).host
24
24
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: alexa
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - "Wojciech Wn\xC4\x99trzak"
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-05 00:00:00 Z
13
+ date: 2011-06-22 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: xml-simple
@@ -47,7 +47,7 @@ files:
47
47
  - .gitignore
48
48
  - Gemfile
49
49
  - LICENSE
50
- - README.rdoc
50
+ - README.markdown
51
51
  - Rakefile
52
52
  - alexa.gemspec
53
53
  - lib/alexa.rb
@@ -73,7 +73,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
73
73
  requirements:
74
74
  - - ">="
75
75
  - !ruby/object:Gem::Version
76
- hash: -3761737575741442318
76
+ hash: 3945594913730495291
77
77
  segments:
78
78
  - 0
79
79
  version: "0"
@@ -82,14 +82,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  requirements:
83
83
  - - ">="
84
84
  - !ruby/object:Gem::Version
85
- hash: -3761737575741442318
85
+ hash: 3945594913730495291
86
86
  segments:
87
87
  - 0
88
88
  version: "0"
89
89
  requirements: []
90
90
 
91
- rubyforge_project: alexa
92
- rubygems_version: 1.8.0
91
+ rubyforge_project:
92
+ rubygems_version: 1.8.5
93
93
  signing_key:
94
94
  specification_version: 3
95
95
  summary: Alexa Web Information Service library