alexa 0.1.1 → 0.2.0
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/.gitignore +1 -0
- data/alexa.gemspec +1 -0
- data/lib/alexa/config.rb +2 -2
- data/lib/alexa/url_info.rb +43 -41
- data/lib/alexa/version.rb +1 -1
- data/test/config_test.rb +24 -26
- data/test/helper.rb +3 -3
- data/test/url_info_test.rb +142 -149
- metadata +17 -19
- data/Gemfile.lock +0 -23
    
        data/.gitignore
    CHANGED
    
    
    
        data/alexa.gemspec
    CHANGED
    
    
    
        data/lib/alexa/config.rb
    CHANGED
    
    
    
        data/lib/alexa/url_info.rb
    CHANGED
    
    | @@ -1,55 +1,57 @@ | |
| 1 1 | 
             
            module Alexa
         | 
| 2 2 | 
             
              class UrlInfo
         | 
| 3 | 
            +
                API_VERSION = "2005-07-11"
         | 
| 3 4 | 
             
                RESPONSE_GROUP = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks,RankByCountry,RankByCity,UsageStats"
         | 
| 5 | 
            +
             | 
| 4 6 | 
             
                attr_accessor :host, :response_group, :xml_response,
         | 
| 5 7 | 
             
                  :rank, :data_url, :site_title, :site_description, :language_locale, :language_encoding,
         | 
| 6 8 | 
             
                  :links_in_count, :keywords, :related_links, :speed_median_load_time, :speed_percentile,
         | 
| 7 9 | 
             
                  :rank_by_country, :rank_by_city, :usage_statistics
         | 
| 8 10 |  | 
| 9 11 | 
             
                def initialize(options = {})
         | 
| 10 | 
            -
                  Alexa.config.access_key_id = options | 
| 11 | 
            -
                  Alexa.config.secret_access_key = options | 
| 12 | 
            -
                  raise ArgumentError.new(" | 
| 13 | 
            -
                  raise ArgumentError.new(" | 
| 14 | 
            -
                   | 
| 15 | 
            -
                   | 
| 12 | 
            +
                  Alexa.config.access_key_id = options.fetch(:access_key_id, Alexa.config.access_key_id)
         | 
| 13 | 
            +
                  Alexa.config.secret_access_key = options.fetch(:secret_access_key, Alexa.config.secret_access_key)
         | 
| 14 | 
            +
                  raise ArgumentError.new("You must specify access_key_id") if Alexa.config.access_key_id.nil?
         | 
| 15 | 
            +
                  raise ArgumentError.new("You must specify secret_access_key") if Alexa.config.secret_access_key.nil?
         | 
| 16 | 
            +
                  self.host = options[:host] or raise ArgumentError.new("You must specify host")
         | 
| 17 | 
            +
                  self.response_group = options.fetch(:response_group, RESPONSE_GROUP)
         | 
| 16 18 | 
             
                end
         | 
| 17 19 |  | 
| 18 20 | 
             
                def connect
         | 
| 19 | 
            -
                  action = "UrlInfo"
         | 
| 20 | 
            -
                  timestamp = Time::now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
         | 
| 21 | 
            -
                  signature = generate_signature(Alexa.config.secret_access_key, action, timestamp)
         | 
| 22 | 
            -
                  url = generate_url(action, Alexa.config.access_key_id, signature, timestamp, response_group, host)
         | 
| 23 21 | 
             
                  response = Net::HTTP.start(url.host) do |http|
         | 
| 24 22 | 
             
                    http.get url.request_uri
         | 
| 25 23 | 
             
                  end
         | 
| 26 | 
            -
                   | 
| 24 | 
            +
                  self.xml_response = handle_response(response).body
         | 
| 27 25 | 
             
                end
         | 
| 28 26 |  | 
| 29 27 | 
             
                def parse_xml(xml)
         | 
| 30 28 | 
             
                  xml = XmlSimple.xml_in(force_encoding(xml), 'ForceArray' => false)
         | 
| 31 29 | 
             
                  group = response_group.split(',')
         | 
| 32 30 | 
             
                  alexa = xml['Response']['UrlInfoResult']['Alexa']
         | 
| 33 | 
            -
                   | 
| 34 | 
            -
                   | 
| 35 | 
            -
                   | 
| 36 | 
            -
                   | 
| 37 | 
            -
                   | 
| 31 | 
            +
                  self.rank = alexa['TrafficData']['Rank'].to_i if group.include?('Rank') and !alexa['TrafficData']['Rank'].empty?
         | 
| 32 | 
            +
                  self.data_url = alexa['TrafficData']['DataUrl']['content'] if group.include?('Rank')
         | 
| 33 | 
            +
                  self.rank_by_country = alexa['TrafficData']['RankByCountry']['Country'] if group.include?('RankByCountry')
         | 
| 34 | 
            +
                  self.rank_by_city = alexa['TrafficData']['RankByCity']['City'] if group.include?('RankByCity')
         | 
| 35 | 
            +
                  self.usage_statistics = alexa['TrafficData']['UsageStatistics']["UsageStatistic"] if group.include?('UsageStats') and !alexa['TrafficData']['UsageStatistics'].nil?
         | 
| 38 36 |  | 
| 39 | 
            -
                   | 
| 40 | 
            -
                   | 
| 41 | 
            -
                   | 
| 42 | 
            -
                   | 
| 43 | 
            -
                   | 
| 44 | 
            -
                   | 
| 45 | 
            -
                   | 
| 46 | 
            -
                   | 
| 37 | 
            +
                  self.site_title = alexa['ContentData']['SiteData']['Title'] if group.include?('SiteData')
         | 
| 38 | 
            +
                  self.site_description = alexa['ContentData']['SiteData']['Description'] if group.include?('SiteData')
         | 
| 39 | 
            +
                  self.language_locale = alexa['ContentData']['Language']['Locale'] if group.include?('Language')
         | 
| 40 | 
            +
                  self.language_encoding = alexa['ContentData']['Language']['Encoding'] if group.include?('Language')
         | 
| 41 | 
            +
                  self.links_in_count = alexa['ContentData']['LinksInCount'].to_i if group.include?('LinksInCount') and !alexa['ContentData']['LinksInCount'].empty?
         | 
| 42 | 
            +
                  self.keywords = alexa['ContentData']['Keywords']['Keyword'] if group.include?('Keywords')
         | 
| 43 | 
            +
                  self.speed_median_load_time = alexa['ContentData']['Speed']['MedianLoadTime'].to_i if group.include?('Speed') and !alexa['ContentData']['Speed']['MedianLoadTime'].empty?
         | 
| 44 | 
            +
                  self.speed_percentile = alexa['ContentData']['Speed']['Percentile'].to_i if group.include?('Speed') and !alexa['ContentData']['Speed']['Percentile'].empty?
         | 
| 47 45 |  | 
| 48 | 
            -
                   | 
| 46 | 
            +
                  self.related_links = alexa['Related']['RelatedLinks']['RelatedLink'] if group.include?('RelatedLinks')
         | 
| 49 47 | 
             
                end
         | 
| 50 48 |  | 
| 51 49 | 
             
                private
         | 
| 52 50 |  | 
| 51 | 
            +
                def timestamp
         | 
| 52 | 
            +
                  @timestamp ||= Time::now.utc.strftime("%Y-%m-%dT%H:%M:%S.000Z")
         | 
| 53 | 
            +
                end
         | 
| 54 | 
            +
             | 
| 53 55 | 
             
                def force_encoding(xml)
         | 
| 54 56 | 
             
                  if RUBY_VERSION >= '1.9'
         | 
| 55 57 | 
             
                    xml.force_encoding(Encoding::UTF_8)
         | 
| @@ -66,7 +68,7 @@ module Alexa | |
| 66 68 | 
             
                    if response.body.nil?
         | 
| 67 69 | 
             
                      raise StandardError.new(response)
         | 
| 68 70 | 
             
                    else
         | 
| 69 | 
            -
                       | 
| 71 | 
            +
                      self.xml_response = response.body
         | 
| 70 72 | 
             
                      xml = XmlSimple.xml_in(response.body, 'ForceArray' => false)
         | 
| 71 73 | 
             
                      message = xml['Errors']['Error']['Message']
         | 
| 72 74 | 
             
                      raise StandardError.new(message)
         | 
| @@ -76,22 +78,22 @@ module Alexa | |
| 76 78 | 
             
                  end
         | 
| 77 79 | 
             
                end
         | 
| 78 80 |  | 
| 79 | 
            -
                def  | 
| 80 | 
            -
                  Base64.encode64( | 
| 81 | 
            +
                def signature
         | 
| 82 | 
            +
                  @signature ||= Base64.encode64(OpenSSL::HMAC.digest(OpenSSL::Digest::Digest.new("sha1"), Alexa.config.secret_access_key, "UrlInfo" + timestamp)).strip
         | 
| 81 83 | 
             
                end
         | 
| 82 84 |  | 
| 83 | 
            -
                def  | 
| 84 | 
            -
                   | 
| 85 | 
            -
             | 
| 86 | 
            -
                       | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 92 | 
            -
             | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 85 | 
            +
                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 | 
            +
                  )
         | 
| 95 97 | 
             
                end
         | 
| 96 98 | 
             
              end
         | 
| 97 | 
            -
            end
         | 
| 99 | 
            +
            end
         | 
    
        data/lib/alexa/version.rb
    CHANGED
    
    
    
        data/test/config_test.rb
    CHANGED
    
    | @@ -1,38 +1,36 @@ | |
| 1 1 | 
             
            require 'helper'
         | 
| 2 2 |  | 
| 3 3 | 
             
            class ConfigTest < Test::Unit::TestCase
         | 
| 4 | 
            -
               | 
| 5 | 
            -
                 | 
| 6 | 
            -
             | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
                end
         | 
| 4 | 
            +
              def setup
         | 
| 5 | 
            +
                # Config is singleton
         | 
| 6 | 
            +
                Alexa.config.access_key_id = nil
         | 
| 7 | 
            +
                Alexa.config.secret_access_key = nil
         | 
| 8 | 
            +
              end
         | 
| 10 9 |  | 
| 11 | 
            -
             | 
| 12 | 
            -
             | 
| 13 | 
            -
             | 
| 14 | 
            -
                    :secret_access_key => | 
| 10 | 
            +
              should "raise argumment error if access key id is not present" do
         | 
| 11 | 
            +
                assert_raise ArgumentError do
         | 
| 12 | 
            +
                  Alexa::UrlInfo.new(
         | 
| 13 | 
            +
                    :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
         | 
| 15 14 | 
             
                    :host => "some.host"
         | 
| 16 | 
            -
             | 
| 17 | 
            -
                  end
         | 
| 15 | 
            +
                  )
         | 
| 18 16 | 
             
                end
         | 
| 17 | 
            +
              end
         | 
| 19 18 |  | 
| 20 | 
            -
             | 
| 21 | 
            -
             | 
| 22 | 
            -
             | 
| 23 | 
            -
                    :access_key_id => | 
| 19 | 
            +
              should "raise argumment error if secret access key is not present" do
         | 
| 20 | 
            +
                assert_raise ArgumentError do
         | 
| 21 | 
            +
                  Alexa::UrlInfo.new(
         | 
| 22 | 
            +
                    :access_key_id => "12345678901234567890",
         | 
| 24 23 | 
             
                    :host => "some.host"
         | 
| 25 | 
            -
             | 
| 26 | 
            -
                  end
         | 
| 24 | 
            +
                  )
         | 
| 27 25 | 
             
                end
         | 
| 26 | 
            +
              end
         | 
| 28 27 |  | 
| 29 | 
            -
             | 
| 30 | 
            -
             | 
| 31 | 
            -
             | 
| 32 | 
            -
                    :access_key_id => | 
| 33 | 
            -
                    :secret_access_key => | 
| 34 | 
            -
             | 
| 35 | 
            -
                  end
         | 
| 28 | 
            +
              should "raise argumment error if host is not present" do
         | 
| 29 | 
            +
                assert_raise ArgumentError do
         | 
| 30 | 
            +
                  Alexa::UrlInfo.new(
         | 
| 31 | 
            +
                    :access_key_id => "12345678901234567890",
         | 
| 32 | 
            +
                    :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF"
         | 
| 33 | 
            +
                  )
         | 
| 36 34 | 
             
                end
         | 
| 37 35 | 
             
              end
         | 
| 38 | 
            -
            end
         | 
| 36 | 
            +
            end
         | 
    
        data/test/helper.rb
    CHANGED
    
    | @@ -1,14 +1,14 @@ | |
| 1 | 
            -
            Bundler. | 
| 1 | 
            +
            Bundler.setup
         | 
| 2 2 | 
             
            require "test/unit"
         | 
| 3 | 
            +
            require "mocha"
         | 
| 3 4 | 
             
            require "shoulda"
         | 
| 4 5 |  | 
| 5 6 | 
             
            $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
         | 
| 6 7 | 
             
            $LOAD_PATH.unshift(File.dirname(__FILE__))
         | 
| 7 | 
            -
            require  | 
| 8 | 
            +
            require "alexa"
         | 
| 8 9 |  | 
| 9 10 | 
             
            class Test::Unit::TestCase
         | 
| 10 11 | 
             
              def fixture_file(filename)
         | 
| 11 | 
            -
                return '' if filename == ''
         | 
| 12 12 | 
             
                file_path = File.expand_path(File.dirname(__FILE__) + '/fixtures/' + filename)
         | 
| 13 13 | 
             
                File.read(file_path)
         | 
| 14 14 | 
             
              end
         | 
    
        data/test/url_info_test.rb
    CHANGED
    
    | @@ -1,195 +1,188 @@ | |
| 1 | 
            -
            require  | 
| 1 | 
            +
            require "helper"
         | 
| 2 2 |  | 
| 3 3 | 
             
            class UrlInfoTest < Test::Unit::TestCase
         | 
| 4 | 
            -
               | 
| 4 | 
            +
              def setup
         | 
| 5 | 
            +
                @alexa = Alexa::UrlInfo.new(
         | 
| 6 | 
            +
                  :access_key_id => "12345678901234567890",
         | 
| 7 | 
            +
                  :secret_access_key => "qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDF",
         | 
| 8 | 
            +
                  :host => "some.host"
         | 
| 9 | 
            +
                )
         | 
| 10 | 
            +
              end
         | 
| 11 | 
            +
             | 
| 12 | 
            +
              should "Generate signature" do
         | 
| 13 | 
            +
                @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
         | 
| 14 | 
            +
                assert_equal "I1mPdBy+flhhzqqUaamNq9gq190=", @alexa.send(:signature)
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
             | 
| 17 | 
            +
              should "Generate url" do
         | 
| 18 | 
            +
                @alexa.stubs(:timestamp).returns("2009-07-03T07:22:24.000Z")
         | 
| 19 | 
            +
                @alexa.response_group = "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks"
         | 
| 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"
         | 
| 22 | 
            +
                assert_equal expected_uri, @alexa.send(:url).request_uri
         | 
| 23 | 
            +
                assert_equal "awis.amazonaws.com", @alexa.send(:url).host
         | 
| 24 | 
            +
              end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
              context "should parse xml return by options LinksInCount,SiteData" do
         | 
| 5 27 | 
             
                setup do
         | 
| 6 | 
            -
                  @alexa =  | 
| 7 | 
            -
             | 
| 8 | 
            -
             | 
| 9 | 
            -
             | 
| 10 | 
            -
                  )
         | 
| 11 | 
            -
                end
         | 
| 12 | 
            -
             | 
| 13 | 
            -
                should "Generate signature" do
         | 
| 14 | 
            -
                  signature = @alexa.send :generate_signature, Alexa.config.secret_access_key, "UrlInfo", '2009-07-03T07:22:24.000Z'
         | 
| 15 | 
            -
                  assert_equal "I1mPdBy+flhhzqqUaamNq9gq190=", signature
         | 
| 16 | 
            -
                end
         | 
| 17 | 
            -
             | 
| 18 | 
            -
                should "Generate url" do
         | 
| 19 | 
            -
                  url = @alexa.send(:generate_url,
         | 
| 20 | 
            -
                  "UrlInfo",
         | 
| 21 | 
            -
                  Alexa.config.access_key_id,
         | 
| 22 | 
            -
                  "I1mPdBy+flhhzqqUaamNq9gq190=",
         | 
| 23 | 
            -
                  '2009-07-03T07:22:24.000Z',
         | 
| 24 | 
            -
                  "Rank,ContactInfo,AdultContent,Speed,Language,Keywords,OwnedDomains,LinksInCount,SiteData,RelatedLinks",
         | 
| 25 | 
            -
                  "heroku.com"
         | 
| 26 | 
            -
                  )
         | 
| 27 | 
            -
                  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"
         | 
| 28 | 
            -
                  assert_equal expected_uri, url.request_uri
         | 
| 29 | 
            -
                  assert_equal "awis.amazonaws.com", url.host
         | 
| 30 | 
            -
                end
         | 
| 31 | 
            -
             | 
| 32 | 
            -
                context "should parse xml return by options LinksInCount,SiteData and" do
         | 
| 33 | 
            -
                  setup do
         | 
| 34 | 
            -
                    @alexa.response_group = "Rank,LinksInCount,SiteData"
         | 
| 35 | 
            -
                    xml = fixture_file('polsl_small.xml')
         | 
| 36 | 
            -
                    @alexa.parse_xml(xml)
         | 
| 37 | 
            -
                  end
         | 
| 28 | 
            +
                  @alexa.response_group = "Rank,LinksInCount,SiteData"
         | 
| 29 | 
            +
                  xml = fixture_file('polsl_small.xml')
         | 
| 30 | 
            +
                  @alexa.parse_xml(xml)
         | 
| 31 | 
            +
                end
         | 
| 38 32 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
             | 
| 41 | 
            -
             | 
| 33 | 
            +
                should "return rank" do
         | 
| 34 | 
            +
                  assert_equal 86020, @alexa.rank
         | 
| 35 | 
            +
                end
         | 
| 42 36 |  | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 37 | 
            +
                should "return data url" do
         | 
| 38 | 
            +
                  assert_equal "polsl.pl/", @alexa.data_url
         | 
| 39 | 
            +
                end
         | 
| 46 40 |  | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 41 | 
            +
                should "return site title" do
         | 
| 42 | 
            +
                  assert_equal "Silesian University of Technology", @alexa.site_title
         | 
| 43 | 
            +
                end
         | 
| 50 44 |  | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 45 | 
            +
                should "return site description" do
         | 
| 46 | 
            +
                  assert_equal "About the university, studies, faculties and departments, photo gallery.", @alexa.site_description
         | 
| 47 | 
            +
                end
         | 
| 54 48 |  | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
                    end
         | 
| 59 | 
            -
                    assert_nil @alexa.language_locale
         | 
| 49 | 
            +
                should "not crash" do
         | 
| 50 | 
            +
                  assert_nothing_raised do
         | 
| 51 | 
            +
                    @alexa.language_locale
         | 
| 60 52 | 
             
                  end
         | 
| 53 | 
            +
                  assert_nil @alexa.language_locale
         | 
| 61 54 | 
             
                end
         | 
| 55 | 
            +
              end
         | 
| 62 56 |  | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 57 | 
            +
              context "should parse xml with all options" do
         | 
| 58 | 
            +
                setup do
         | 
| 59 | 
            +
                  xml = fixture_file('polsl.xml')
         | 
| 60 | 
            +
                  @alexa.parse_xml(xml)
         | 
| 61 | 
            +
                end
         | 
| 68 62 |  | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 63 | 
            +
                should "return rank" do
         | 
| 64 | 
            +
                  assert_equal 86020, @alexa.rank
         | 
| 65 | 
            +
                end
         | 
| 72 66 |  | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 67 | 
            +
                should "return data url" do
         | 
| 68 | 
            +
                  assert_equal "polsl.pl", @alexa.data_url
         | 
| 69 | 
            +
                end
         | 
| 76 70 |  | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 71 | 
            +
                should "return site title" do
         | 
| 72 | 
            +
                  assert_equal "Silesian University of Technology", @alexa.site_title
         | 
| 73 | 
            +
                end
         | 
| 80 74 |  | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 75 | 
            +
                should "return site description" do
         | 
| 76 | 
            +
                  assert_equal "About the university, studies, faculties and departments, photo gallery.", @alexa.site_description
         | 
| 77 | 
            +
                end
         | 
| 84 78 |  | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 79 | 
            +
                should "return language locale" do
         | 
| 80 | 
            +
                  assert_equal "pl-PL", @alexa.language_locale
         | 
| 81 | 
            +
                end
         | 
| 88 82 |  | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
             | 
| 83 | 
            +
                should "return language encoding" do
         | 
| 84 | 
            +
                  assert_equal "iso-8859-2", @alexa.language_encoding
         | 
| 85 | 
            +
                end
         | 
| 92 86 |  | 
| 93 | 
            -
             | 
| 94 | 
            -
             | 
| 95 | 
            -
             | 
| 87 | 
            +
                should "return links in count" do
         | 
| 88 | 
            +
                  assert_equal 281, @alexa.links_in_count
         | 
| 89 | 
            +
                end
         | 
| 96 90 |  | 
| 97 | 
            -
             | 
| 98 | 
            -
             | 
| 99 | 
            -
             | 
| 91 | 
            +
                should "return keywords" do
         | 
| 92 | 
            +
                  assert_equal ["Polska", "Regionalne", "Gliwice"], @alexa.keywords
         | 
| 93 | 
            +
                end
         | 
| 100 94 |  | 
| 101 | 
            -
             | 
| 102 | 
            -
             | 
| 103 | 
            -
             | 
| 95 | 
            +
                should "return related links" do
         | 
| 96 | 
            +
                  assert_equal 10, @alexa.related_links.size
         | 
| 97 | 
            +
                end
         | 
| 104 98 |  | 
| 105 | 
            -
             | 
| 106 | 
            -
             | 
| 107 | 
            -
             | 
| 99 | 
            +
                should "return speed_median load time" do
         | 
| 100 | 
            +
                  assert_equal 266, @alexa.speed_median_load_time
         | 
| 101 | 
            +
                end
         | 
| 108 102 |  | 
| 109 | 
            -
             | 
| 110 | 
            -
             | 
| 111 | 
            -
             | 
| 103 | 
            +
                should "return speed percentile" do
         | 
| 104 | 
            +
                  assert_equal 98, @alexa.speed_percentile
         | 
| 105 | 
            +
                end
         | 
| 112 106 |  | 
| 113 | 
            -
             | 
| 114 | 
            -
             | 
| 115 | 
            -
             | 
| 107 | 
            +
                should "return rank by country" do
         | 
| 108 | 
            +
                  assert_equal 3, @alexa.rank_by_country.size
         | 
| 109 | 
            +
                end
         | 
| 116 110 |  | 
| 117 | 
            -
             | 
| 118 | 
            -
             | 
| 119 | 
            -
             | 
| 111 | 
            +
                should "return rank by city" do
         | 
| 112 | 
            +
                  assert_equal 68, @alexa.rank_by_city.size
         | 
| 113 | 
            +
                end
         | 
| 120 114 |  | 
| 121 | 
            -
             | 
| 122 | 
            -
             | 
| 123 | 
            -
                  end
         | 
| 115 | 
            +
                should "return usage statistics" do
         | 
| 116 | 
            +
                  assert_equal 4, @alexa.usage_statistics.size
         | 
| 124 117 | 
             
                end
         | 
| 118 | 
            +
              end
         | 
| 125 119 |  | 
| 126 | 
            -
             | 
| 127 | 
            -
             | 
| 128 | 
            -
             | 
| 129 | 
            -
             | 
| 130 | 
            -
             | 
| 120 | 
            +
              context "should not crash when parsing empty xml response" do
         | 
| 121 | 
            +
                setup do
         | 
| 122 | 
            +
                  xml = fixture_file('empty.xml')
         | 
| 123 | 
            +
                  @alexa.parse_xml(xml)
         | 
| 124 | 
            +
                end
         | 
| 131 125 |  | 
| 132 | 
            -
             | 
| 133 | 
            -
             | 
| 134 | 
            -
             | 
| 126 | 
            +
                should "return nil from rank" do
         | 
| 127 | 
            +
                  assert_nil @alexa.rank
         | 
| 128 | 
            +
                end
         | 
| 135 129 |  | 
| 136 | 
            -
             | 
| 137 | 
            -
             | 
| 138 | 
            -
             | 
| 130 | 
            +
                should "return nil from data_url" do
         | 
| 131 | 
            +
                  assert_equal "404", @alexa.data_url
         | 
| 132 | 
            +
                end
         | 
| 139 133 |  | 
| 140 | 
            -
             | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 134 | 
            +
                should "return nil from site_title" do
         | 
| 135 | 
            +
                  assert_equal "404", @alexa.site_title
         | 
| 136 | 
            +
                end
         | 
| 143 137 |  | 
| 144 | 
            -
             | 
| 145 | 
            -
             | 
| 146 | 
            -
             | 
| 138 | 
            +
                should "return nil from site_description" do
         | 
| 139 | 
            +
                  assert_nil @alexa.site_description
         | 
| 140 | 
            +
                end
         | 
| 147 141 |  | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 142 | 
            +
                should "return nil from language_locale" do
         | 
| 143 | 
            +
                  assert_nil @alexa.language_locale
         | 
| 144 | 
            +
                end
         | 
| 151 145 |  | 
| 152 | 
            -
             | 
| 153 | 
            -
             | 
| 154 | 
            -
             | 
| 146 | 
            +
                should "return nil from language_encoding" do
         | 
| 147 | 
            +
                  assert_nil @alexa.language_encoding
         | 
| 148 | 
            +
                end
         | 
| 155 149 |  | 
| 156 | 
            -
             | 
| 157 | 
            -
             | 
| 158 | 
            -
             | 
| 150 | 
            +
                should "return nil from links_in_count" do
         | 
| 151 | 
            +
                  assert_nil @alexa.links_in_count
         | 
| 152 | 
            +
                end
         | 
| 159 153 |  | 
| 160 | 
            -
             | 
| 161 | 
            -
             | 
| 162 | 
            -
             | 
| 154 | 
            +
                should "return nil from keywords" do
         | 
| 155 | 
            +
                  assert_nil @alexa.keywords
         | 
| 156 | 
            +
                end
         | 
| 163 157 |  | 
| 164 | 
            -
             | 
| 165 | 
            -
             | 
| 166 | 
            -
             | 
| 158 | 
            +
                should "return nil from related_links" do
         | 
| 159 | 
            +
                  assert_nil @alexa.related_links
         | 
| 160 | 
            +
                end
         | 
| 167 161 |  | 
| 168 | 
            -
             | 
| 169 | 
            -
             | 
| 170 | 
            -
             | 
| 162 | 
            +
                should "return nil from speed_median_load_time" do
         | 
| 163 | 
            +
                  assert_nil @alexa.speed_median_load_time
         | 
| 164 | 
            +
                end
         | 
| 171 165 |  | 
| 172 | 
            -
             | 
| 173 | 
            -
             | 
| 174 | 
            -
             | 
| 166 | 
            +
                should "return nil from speed_percentile" do
         | 
| 167 | 
            +
                  assert_nil @alexa.speed_percentile
         | 
| 168 | 
            +
                end
         | 
| 175 169 |  | 
| 176 | 
            -
             | 
| 177 | 
            -
             | 
| 178 | 
            -
             | 
| 170 | 
            +
                should "return nil from rank_by_country" do
         | 
| 171 | 
            +
                  assert_nil @alexa.rank_by_country
         | 
| 172 | 
            +
                end
         | 
| 179 173 |  | 
| 180 | 
            -
             | 
| 181 | 
            -
             | 
| 182 | 
            -
             | 
| 174 | 
            +
                should "return nil from rank_by_city" do
         | 
| 175 | 
            +
                  assert_nil @alexa.rank_by_city
         | 
| 176 | 
            +
                end
         | 
| 183 177 |  | 
| 184 | 
            -
             | 
| 185 | 
            -
             | 
| 186 | 
            -
                  end
         | 
| 178 | 
            +
                should "return nil from usage_statistics" do
         | 
| 179 | 
            +
                  assert_nil @alexa.usage_statistics
         | 
| 187 180 | 
             
                end
         | 
| 181 | 
            +
              end
         | 
| 188 182 |  | 
| 189 | 
            -
             | 
| 190 | 
            -
             | 
| 191 | 
            -
             | 
| 192 | 
            -
                  end
         | 
| 183 | 
            +
              should "not raise error when response is OK" do
         | 
| 184 | 
            +
                assert_nothing_raised do
         | 
| 185 | 
            +
                  @alexa.send :handle_response, Net::HTTPOK.new("1.1", "200", "OK")
         | 
| 193 186 | 
             
                end
         | 
| 194 187 | 
             
              end
         | 
| 195 188 | 
             
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,12 +1,8 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification 
         | 
| 2 2 | 
             
            name: alexa
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version 
         | 
| 4 | 
            -
              prerelease:  | 
| 5 | 
            -
               | 
| 6 | 
            -
              - 0
         | 
| 7 | 
            -
              - 1
         | 
| 8 | 
            -
              - 1
         | 
| 9 | 
            -
              version: 0.1.1
         | 
| 4 | 
            +
              prerelease: 
         | 
| 5 | 
            +
              version: 0.2.0
         | 
| 10 6 | 
             
            platform: ruby
         | 
| 11 7 | 
             
            authors: 
         | 
| 12 8 | 
             
            - "Wojciech Wn\xC4\x99trzak"
         | 
| @@ -14,8 +10,7 @@ autorequire: | |
| 14 10 | 
             
            bindir: bin
         | 
| 15 11 | 
             
            cert_chain: []
         | 
| 16 12 |  | 
| 17 | 
            -
            date:  | 
| 18 | 
            -
            default_executable: 
         | 
| 13 | 
            +
            date: 2011-05-04 00:00:00 Z
         | 
| 19 14 | 
             
            dependencies: 
         | 
| 20 15 | 
             
            - !ruby/object:Gem::Dependency 
         | 
| 21 16 | 
             
              name: xml-simple
         | 
| @@ -24,8 +19,6 @@ dependencies: | |
| 24 19 | 
             
                requirements: 
         | 
| 25 20 | 
             
                - - ">="
         | 
| 26 21 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 27 | 
            -
                    segments: 
         | 
| 28 | 
            -
                    - 0
         | 
| 29 22 | 
             
                    version: "0"
         | 
| 30 23 | 
             
              type: :runtime
         | 
| 31 24 | 
             
              prerelease: false
         | 
| @@ -37,8 +30,6 @@ dependencies: | |
| 37 30 | 
             
                requirements: 
         | 
| 38 31 | 
             
                - - ">="
         | 
| 39 32 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 40 | 
            -
                    segments: 
         | 
| 41 | 
            -
                    - 0
         | 
| 42 33 | 
             
                    version: "0"
         | 
| 43 34 | 
             
              type: :development
         | 
| 44 35 | 
             
              prerelease: false
         | 
| @@ -50,12 +41,21 @@ dependencies: | |
| 50 41 | 
             
                requirements: 
         | 
| 51 42 | 
             
                - - ">="
         | 
| 52 43 | 
             
                  - !ruby/object:Gem::Version 
         | 
| 53 | 
            -
                    segments: 
         | 
| 54 | 
            -
                    - 0
         | 
| 55 44 | 
             
                    version: "0"
         | 
| 56 45 | 
             
              type: :development
         | 
| 57 46 | 
             
              prerelease: false
         | 
| 58 47 | 
             
              version_requirements: *id003
         | 
| 48 | 
            +
            - !ruby/object:Gem::Dependency 
         | 
| 49 | 
            +
              name: mocha
         | 
| 50 | 
            +
              requirement: &id004 !ruby/object:Gem::Requirement 
         | 
| 51 | 
            +
                none: false
         | 
| 52 | 
            +
                requirements: 
         | 
| 53 | 
            +
                - - ">="
         | 
| 54 | 
            +
                  - !ruby/object:Gem::Version 
         | 
| 55 | 
            +
                    version: "0"
         | 
| 56 | 
            +
              type: :development
         | 
| 57 | 
            +
              prerelease: false
         | 
| 58 | 
            +
              version_requirements: *id004
         | 
| 59 59 | 
             
            description: Alexa Web Information Service library (AWIS)
         | 
| 60 60 | 
             
            email: 
         | 
| 61 61 | 
             
            - w.wnetrzak@gmail.com
         | 
| @@ -68,7 +68,6 @@ extra_rdoc_files: [] | |
| 68 68 | 
             
            files: 
         | 
| 69 69 | 
             
            - .gitignore
         | 
| 70 70 | 
             
            - Gemfile
         | 
| 71 | 
            -
            - Gemfile.lock
         | 
| 72 71 | 
             
            - LICENSE
         | 
| 73 72 | 
             
            - README.rdoc
         | 
| 74 73 | 
             
            - Rakefile
         | 
| @@ -83,7 +82,6 @@ files: | |
| 83 82 | 
             
            - test/fixtures/polsl_small.xml
         | 
| 84 83 | 
             
            - test/helper.rb
         | 
| 85 84 | 
             
            - test/url_info_test.rb
         | 
| 86 | 
            -
            has_rdoc: true
         | 
| 87 85 | 
             
            homepage: https://github.com/morgoth/alexa
         | 
| 88 86 | 
             
            licenses: []
         | 
| 89 87 |  | 
| @@ -97,7 +95,7 @@ required_ruby_version: !ruby/object:Gem::Requirement | |
| 97 95 | 
             
              requirements: 
         | 
| 98 96 | 
             
              - - ">="
         | 
| 99 97 | 
             
                - !ruby/object:Gem::Version 
         | 
| 100 | 
            -
                  hash:  | 
| 98 | 
            +
                  hash: -201747439707847299
         | 
| 101 99 | 
             
                  segments: 
         | 
| 102 100 | 
             
                  - 0
         | 
| 103 101 | 
             
                  version: "0"
         | 
| @@ -106,14 +104,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 106 104 | 
             
              requirements: 
         | 
| 107 105 | 
             
              - - ">="
         | 
| 108 106 | 
             
                - !ruby/object:Gem::Version 
         | 
| 109 | 
            -
                  hash:  | 
| 107 | 
            +
                  hash: -201747439707847299
         | 
| 110 108 | 
             
                  segments: 
         | 
| 111 109 | 
             
                  - 0
         | 
| 112 110 | 
             
                  version: "0"
         | 
| 113 111 | 
             
            requirements: []
         | 
| 114 112 |  | 
| 115 113 | 
             
            rubyforge_project: alexa
         | 
| 116 | 
            -
            rubygems_version: 1. | 
| 114 | 
            +
            rubygems_version: 1.7.2
         | 
| 117 115 | 
             
            signing_key: 
         | 
| 118 116 | 
             
            specification_version: 3
         | 
| 119 117 | 
             
            summary: Alexa Web Information Service library
         | 
    
        data/Gemfile.lock
    DELETED
    
    | @@ -1,23 +0,0 @@ | |
| 1 | 
            -
            PATH
         | 
| 2 | 
            -
              remote: .
         | 
| 3 | 
            -
              specs:
         | 
| 4 | 
            -
                alexa (0.1.1)
         | 
| 5 | 
            -
                  xml-simple
         | 
| 6 | 
            -
             | 
| 7 | 
            -
            GEM
         | 
| 8 | 
            -
              remote: http://rubygems.org/
         | 
| 9 | 
            -
              specs:
         | 
| 10 | 
            -
                rake (0.8.7)
         | 
| 11 | 
            -
                shoulda (2.11.3)
         | 
| 12 | 
            -
                test-unit (2.1.1)
         | 
| 13 | 
            -
                xml-simple (1.0.12)
         | 
| 14 | 
            -
             | 
| 15 | 
            -
            PLATFORMS
         | 
| 16 | 
            -
              ruby
         | 
| 17 | 
            -
             | 
| 18 | 
            -
            DEPENDENCIES
         | 
| 19 | 
            -
              alexa!
         | 
| 20 | 
            -
              rake
         | 
| 21 | 
            -
              shoulda
         | 
| 22 | 
            -
              test-unit
         | 
| 23 | 
            -
              xml-simple
         |