alexa 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -5,8 +5,8 @@ rvm:
5
5
  - 1.9.2
6
6
  - 1.9.3
7
7
  env:
8
- - XML_PARSER=rexml
9
- - XML_PARSER=nokogiri
10
- - XML_PARSER=libxml
8
+ - ALEXA_XML_PARSER=rexml
9
+ - ALEXA_XML_PARSER=nokogiri
10
+ - ALEXA_XML_PARSER=libxml
11
11
  # does not work yet
12
- # - XML_PARSER=ox
12
+ # - ALEXA_XML_PARSER=ox
data/Gemfile CHANGED
@@ -1,4 +1,4 @@
1
- source :rubygems
1
+ source "https://rubygems.org"
2
2
 
3
3
  gem "minitest", :platform => :ruby_18
4
4
  gem "rake"
data/README.md CHANGED
@@ -27,7 +27,7 @@ You can set configuration in block like this:
27
27
 
28
28
  ``` ruby
29
29
  Alexa.configure do |config|
30
- config.access_key_id = "key"
30
+ config.access_key_id = "key"
31
31
  config.secret_access_key = "secret"
32
32
  end
33
33
  ```
@@ -58,4 +58,4 @@ Support following:
58
58
 
59
59
  ## Copyright
60
60
 
61
- Copyright (c) 2011 Wojciech Wnętrzak. See LICENSE for details.
61
+ Copyright (c) 2012 Wojciech Wnętrzak. See LICENSE for details.
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/alexa/version', __FILE__)
2
+ require File.expand_path("../lib/alexa/version", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.authors = ["Wojciech Wnętrzak"]
@@ -12,11 +12,19 @@ Gem::Specification.new do |gem|
12
12
  gem.files = `git ls-files`.split("\n")
13
13
  gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
14
  gem.name = "alexa"
15
- gem.require_paths = ['lib']
15
+ gem.require_paths = ["lib"]
16
16
  gem.version = Alexa::VERSION
17
17
 
18
- gem.add_dependency "multi_xml"
18
+ gem.add_dependency "multi_xml", ">= 0.5.0"
19
19
 
20
20
  gem.add_development_dependency "mocha"
21
21
  gem.add_development_dependency "fakeweb"
22
+
23
+ gem.post_install_message = %{
24
+
25
+ Gem syntax of 0.4 version of this gem will change with backward incompatibilities.
26
+ If you don't want to update your code, please specify in your Gemfile:
27
+ gem "alexa", "~> 0.3.0"
28
+
29
+ }
22
30
  end
@@ -2,15 +2,13 @@ require "cgi"
2
2
  require "base64"
3
3
  require "openssl"
4
4
  require "digest/sha1"
5
- require "uri"
6
5
  require "net/https"
7
6
  require "time"
8
7
 
9
8
  require "multi_xml"
10
9
 
11
- require "alexa/config"
12
- require "alexa/url_info"
13
10
  require "alexa/version"
11
+ require "alexa/url_info"
14
12
 
15
13
  module Alexa
16
14
  class << self
@@ -26,24 +26,24 @@ class Alexa::UrlInfo
26
26
 
27
27
  def parse_xml(xml)
28
28
  xml = MultiXml.parse(force_encoding(xml))
29
- group = response_group.split(',')
29
+ group = response_group.split(",")
30
30
  alexa = xml["UrlInfoResponse"]["Response"]["UrlInfoResult"]["Alexa"]
31
- @rank = alexa['TrafficData']['Rank'].to_i if group.include?('Rank') && !alexa['TrafficData']['Rank'].nil?
32
- @data_url = alexa['TrafficData']['DataUrl'] if group.include?('Rank')
33
- @rank_by_country = alexa['TrafficData']['RankByCountry']['Country'] if group.include?('RankByCountry') && !alexa['TrafficData']['RankByCountry'].nil?
34
- @rank_by_city = alexa['TrafficData']['RankByCity']['City'] if group.include?('RankByCity') && !alexa['TrafficData']['RankByCity'].nil?
35
- @usage_statistics = alexa['TrafficData']['UsageStatistics']["UsageStatistic"] if group.include?('UsageStats') && !alexa['TrafficData']['UsageStatistics'].nil?
31
+ @rank = alexa["TrafficData"]["Rank"].to_i if group.include?("Rank") && !alexa["TrafficData"]["Rank"].nil?
32
+ @data_url = alexa["TrafficData"]["DataUrl"]["__content__"] if group.include?("Rank")
33
+ @rank_by_country = alexa["TrafficData"]["RankByCountry"]["Country"] if group.include?("RankByCountry") && !alexa["TrafficData"]["RankByCountry"].nil?
34
+ @rank_by_city = alexa["TrafficData"]["RankByCity"]["City"] if group.include?("RankByCity") && !alexa["TrafficData"]["RankByCity"].nil?
35
+ @usage_statistics = alexa["TrafficData"]["UsageStatistics"]["UsageStatistic"] if group.include?("UsageStats") && !alexa["TrafficData"]["UsageStatistics"].nil?
36
36
 
37
- @site_title = alexa['ContentData']['SiteData']['Title'] if group.include?('SiteData')
38
- @site_description = alexa['ContentData']['SiteData']['Description'] if group.include?('SiteData')
39
- @language_locale = alexa['ContentData']['Language']['Locale'] if group.include?('Language') && !alexa['ContentData']['Language'].nil?
40
- @language_encoding = alexa['ContentData']['Language']['Encoding'] if group.include?('Language') && !alexa['ContentData']['Language'].nil?
41
- @links_in_count = alexa['ContentData']['LinksInCount'].to_i if group.include?('LinksInCount') && !alexa['ContentData']['LinksInCount'].nil?
42
- @keywords = alexa['ContentData']['Keywords']['Keyword'] if group.include?('Keywords') && !alexa['ContentData']['Keywords'].nil?
43
- @speed_median_load_time = alexa['ContentData']['Speed']['MedianLoadTime'].to_i if group.include?('Speed') && !alexa['ContentData']['Speed']['MedianLoadTime'].nil?
44
- @speed_percentile = alexa['ContentData']['Speed']['Percentile'].to_i if group.include?('Speed') && !alexa['ContentData']['Speed']['Percentile'].nil?
37
+ @site_title = alexa["ContentData"]["SiteData"]["Title"] if group.include?("SiteData")
38
+ @site_description = alexa["ContentData"]["SiteData"]["Description"] if group.include?("SiteData")
39
+ @language_locale = alexa["ContentData"]["Language"]["Locale"] if group.include?("Language") && !alexa["ContentData"]["Language"].nil?
40
+ @language_encoding = alexa["ContentData"]["Language"]["Encoding"] if group.include?("Language") && !alexa["ContentData"]["Language"].nil?
41
+ @links_in_count = alexa["ContentData"]["LinksInCount"].to_i if group.include?("LinksInCount") && !alexa["ContentData"]["LinksInCount"].nil?
42
+ @keywords = alexa["ContentData"]["Keywords"]["Keyword"] if group.include?("Keywords") && !alexa["ContentData"]["Keywords"].nil?
43
+ @speed_median_load_time = alexa["ContentData"]["Speed"]["MedianLoadTime"].to_i if group.include?("Speed") && !alexa["ContentData"]["Speed"]["MedianLoadTime"].nil?
44
+ @speed_percentile = alexa["ContentData"]["Speed"]["Percentile"].to_i if group.include?("Speed") && !alexa["ContentData"]["Speed"]["Percentile"].nil?
45
45
 
46
- @related_links = alexa['Related']['RelatedLinks']['RelatedLink'] if group.include?('RelatedLinks') && !alexa['Related']['RelatedLinks'].nil?
46
+ @related_links = alexa["Related"]["RelatedLinks"]["RelatedLink"] if group.include?("RelatedLinks") && !alexa["Related"]["RelatedLinks"].nil?
47
47
  end
48
48
 
49
49
  private
@@ -53,7 +53,7 @@ class Alexa::UrlInfo
53
53
  end
54
54
 
55
55
  def force_encoding(xml)
56
- if RUBY_VERSION >= '1.9'
56
+ if RUBY_VERSION >= "1.9"
57
57
  xml.force_encoding(Encoding::UTF_8)
58
58
  else
59
59
  xml
@@ -1,3 +1,3 @@
1
1
  module Alexa
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -6,7 +6,7 @@ describe Alexa do
6
6
  Alexa.secret_access_key = nil
7
7
  end
8
8
 
9
- it "should raise argumment error if access key id is not present" do
9
+ it "raises argumment error if access key id is not present" do
10
10
  assert_raises ArgumentError do
11
11
  Alexa::UrlInfo.new(
12
12
  :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
@@ -15,7 +15,7 @@ describe Alexa do
15
15
  end
16
16
  end
17
17
 
18
- it "should raise argumment error if secret access key is not present" do
18
+ it "raises argumment error if secret access key is not present" do
19
19
  assert_raises ArgumentError do
20
20
  Alexa::UrlInfo.new(
21
21
  :access_key_id => "12345678901234567890",
@@ -24,7 +24,7 @@ describe Alexa do
24
24
  end
25
25
  end
26
26
 
27
- it "should raise argumment error if host is not present" do
27
+ it "raises argumment error if host is not present" do
28
28
  assert_raises ArgumentError do
29
29
  Alexa::UrlInfo.new(
30
30
  :access_key_id => "12345678901234567890",
@@ -6,10 +6,10 @@ require "mocha"
6
6
 
7
7
  require "alexa"
8
8
 
9
- if ENV["XML_PARSER"]
10
- require ENV["XML_PARSER"] if ["nokogiri", "libxml", "ox"].include?(ENV["XML_PARSER"])
11
- MultiXml.parser = ENV["XML_PARSER"]
12
- end
9
+ alexa_xml_parser = ENV["ALEXA_XML_PARSER"] || "rexml"
10
+
11
+ require alexa_xml_parser if ["nokogiri", "libxml", "ox"].include?(alexa_xml_parser)
12
+ MultiXml.parser = alexa_xml_parser
13
13
 
14
14
  class MiniTest::Unit::TestCase
15
15
  def setup
@@ -1,6 +1,6 @@
1
1
  require "helper"
2
2
 
3
- describe "Alexa::UlrInfo" do
3
+ describe Alexa::UrlInfo do
4
4
  before do
5
5
  @alexa = Alexa::UrlInfo.new(
6
6
  :access_key_id => "12345678901234567890",
@@ -9,16 +9,18 @@ describe "Alexa::UlrInfo" do
9
9
  )
10
10
  end
11
11
 
12
- it "should Generate signature" do
12
+ it "generates signature" do
13
13
  @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
14
+
14
15
  assert_equal "5Jql3rds3vL9hyijnYtUIVv1H8Q=", @alexa.send(:signature)
15
16
  end
16
17
 
17
- it "should Generate url" do
18
+ it "generates url" do
18
19
  @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
19
20
  @alexa.response_group = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks"
20
21
  @alexa.host = "heroku.com"
21
22
  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"
23
+
22
24
  assert_equal expected_uri, @alexa.send(:url).request_uri
23
25
  assert_equal "awis.amazonaws.com", @alexa.send(:url).host
24
26
  end
@@ -31,24 +33,25 @@ describe "Alexa::UlrInfo" do
31
33
  @alexa.parse_xml(@alexa.xml_response)
32
34
  end
33
35
 
34
- it "should return rank" do
36
+ it "returns rank" do
35
37
  assert_equal 493, @alexa.rank
36
38
  end
37
39
 
38
- it "should return data url" do
40
+ it "returns data url" do
39
41
  assert_equal "github.com/", @alexa.data_url
40
42
  end
41
43
 
42
- it "should return site title" do
44
+ it "returns site title" do
43
45
  assert_equal "GitHub", @alexa.site_title
44
46
  end
45
47
 
46
- it "should return site description" do
48
+ it "returns site description" do
47
49
  expected = "Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code. Commercial closed source hosting is also available."
50
+
48
51
  assert_equal expected, @alexa.site_description
49
52
  end
50
53
 
51
- it "should not have other attributes" do
54
+ it "does not have other attributes" do
52
55
  assert_nil @alexa.language_locale
53
56
  end
54
57
  end
@@ -60,84 +63,87 @@ describe "Alexa::UlrInfo" do
60
63
  @alexa.parse_xml(@alexa.xml_response)
61
64
  end
62
65
 
63
- it "should return rank" do
66
+ it "returns rank" do
64
67
  assert_equal 551, @alexa.rank
65
68
  end
66
69
 
67
- it "should return data url" do
70
+ it "returns data url" do
68
71
  assert_equal "github.com", @alexa.data_url
69
72
  end
70
73
 
71
- it "should return site title" do
74
+ it "returns site title" do
72
75
  assert_equal "GitHub", @alexa.site_title
73
76
  end
74
77
 
75
- it "should return site description" do
78
+ it "returns site description" do
76
79
  expected = "Online project hosting using Git. Includes source-code browser, in-line editing, wikis, and ticketing. Free for public open-source code. Commercial closed source hosting is also available."
77
80
  assert_equal expected, @alexa.site_description
78
81
  end
79
82
 
80
- it "should return language locale" do
83
+ it "returns language locale" do
81
84
  assert_nil @alexa.language_locale
82
85
  end
83
86
 
84
- it "should return language encoding" do
87
+ it "returns language encoding" do
85
88
  assert_nil @alexa.language_encoding
86
89
  end
87
90
 
88
- it "should return links in count" do
91
+ it "returns links in count" do
89
92
  assert_equal 43819, @alexa.links_in_count
90
93
  end
91
94
 
92
- it "should return keywords" do
95
+ it "returns keywords" do
93
96
  assert_nil @alexa.keywords
94
97
  end
95
98
 
96
- it "should return related links" do
99
+ it "returns related links" do
97
100
  assert_equal 10, @alexa.related_links.size
98
101
  end
99
102
 
100
- it "should return speed_median load time" do
103
+ it "returns speed_median load time" do
101
104
  assert_equal 1031, @alexa.speed_median_load_time
102
105
  end
103
106
 
104
- it "should return speed percentile" do
107
+ it "returns speed percentile" do
105
108
  assert_equal 68, @alexa.speed_percentile
106
109
  end
107
110
 
108
- it "should return rank by country" do
111
+ it "returns rank by country" do
109
112
  assert_equal 19, @alexa.rank_by_country.size
110
113
  end
111
114
 
112
- it "should return rank by city" do
115
+ it "returns rank by city" do
113
116
  assert_equal 163, @alexa.rank_by_city.size
114
117
  end
115
118
 
116
- it "should return usage statistics" do
119
+ it "returns usage statistics" do
117
120
  assert_equal 4, @alexa.usage_statistics.size
118
121
  end
119
122
  end
120
123
 
121
124
  describe "with github.com rank response group" do
122
- it "should successfuly connect" do
125
+ it "successfuly connects" do
123
126
  FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("github_rank.txt"))
124
127
  @alexa.response_group = "Rank"
125
128
  @alexa.connect
126
129
  @alexa.parse_xml(@alexa.xml_response)
130
+
127
131
  assert_equal 551, @alexa.rank
128
132
  end
129
133
  end
130
134
 
131
135
  describe "parsing xml with failure" do
132
- it "should raise error when unathorized" do
136
+ it "raises error when unathorized" do
133
137
  FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("unathorized.txt"))
138
+
134
139
  assert_raises StandardError do
135
140
  @alexa.connect
136
141
  end
137
142
  end
138
143
 
139
- it "should raise error when forbidden" do
144
+ it "raises error when forbidden" do
140
145
  FakeWeb.register_uri(:get, %r{http://awis.amazonaws.com}, :response => fixture("forbidden.txt"))
146
+
141
147
  assert_raises StandardError do
142
148
  @alexa.connect
143
149
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: alexa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,22 +9,27 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-11 00:00:00.000000000 Z
12
+ date: 2012-08-02 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_xml
16
- requirement: &18737420 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: '0'
21
+ version: 0.5.0
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *18737420
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.5.0
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: mocha
27
- requirement: &18736900 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *18736900
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: fakeweb
38
- requirement: &18735980 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,7 +53,12 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *18735980
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  description: Alexa Web Information Service library (AWIS)
48
63
  email:
49
64
  - w.wnetrzak@gmail.com
@@ -59,7 +74,6 @@ files:
59
74
  - Rakefile
60
75
  - alexa.gemspec
61
76
  - lib/alexa.rb
62
- - lib/alexa/config.rb
63
77
  - lib/alexa/url_info.rb
64
78
  - lib/alexa/version.rb
65
79
  - test/config_test.rb
@@ -73,7 +87,17 @@ files:
73
87
  - test/url_info_test.rb
74
88
  homepage: https://github.com/morgoth/alexa
75
89
  licenses: []
76
- post_install_message:
90
+ post_install_message: ! '
91
+
92
+
93
+ Gem syntax of 0.4 version of this gem will change with backward incompatibilities.
94
+
95
+ If you don''t want to update your code, please specify in your Gemfile:
96
+
97
+ gem "alexa", "~> 0.3.0"
98
+
99
+
100
+ '
77
101
  rdoc_options: []
78
102
  require_paths:
79
103
  - lib
@@ -85,7 +109,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
85
109
  version: '0'
86
110
  segments:
87
111
  - 0
88
- hash: -4342544955797275684
112
+ hash: 2191053239788630908
89
113
  required_rubygems_version: !ruby/object:Gem::Requirement
90
114
  none: false
91
115
  requirements:
@@ -94,10 +118,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
94
118
  version: '0'
95
119
  segments:
96
120
  - 0
97
- hash: -4342544955797275684
121
+ hash: 2191053239788630908
98
122
  requirements: []
99
123
  rubyforge_project:
100
- rubygems_version: 1.8.10
124
+ rubygems_version: 1.8.24
101
125
  signing_key:
102
126
  specification_version: 3
103
127
  summary: Alexa Web Information Service library
@@ -1,25 +0,0 @@
1
- require "singleton"
2
-
3
- module Alexa
4
- class Config
5
- include Singleton
6
- attr_reader :access_key_id, :secret_access_key
7
-
8
- def access_key_id=(key)
9
- puts "Depracation warning: Alexa.config.access_key_id= is deprecated. Use Alexa.access_key_id="
10
- Alexa.access_key_id = key
11
- end
12
-
13
- def secret_access_key=(key)
14
- puts "Depracation warning: Alexa.config.secret_access_key= is deprecated. Use Alexa.secret_access_key="
15
- Alexa.secret_access_key = key
16
- end
17
- end
18
-
19
- def self.config
20
- if block_given?
21
- yield Config.instance
22
- end
23
- Config.instance
24
- end
25
- end