From b089f563347d9a54be26063d68bb526af97258ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wojciech=20Wn=C4=99trzak?= Date: Sun, 1 Sep 2013 10:08:04 +0200 Subject: [PATCH] make time assertion less restrictive to avoid failures --- lib/alexa/api/category_listings.rb | 10 ++++------ lib/alexa/api/traffic_history.rb | 5 ++--- lib/alexa/api/url_info.rb | 22 +++++++++------------- test/api/traffic_history_test.rb | 4 ++-- 4 files changed, 17 insertions(+), 24 deletions(-) diff --git a/lib/alexa/api/category_listings.rb b/lib/alexa/api/category_listings.rb index bdc53eb..01a9b39 100644 --- a/lib/alexa/api/category_listings.rb +++ b/lib/alexa/api/category_listings.rb @@ -21,16 +21,14 @@ def fetch(arguments = {}) def count return @count if defined?(@count) - if count = safe_retrieve(parsed_body, "CategoryListingsResponse", "Response", "CategoryListingsResult", "Alexa", "CategoryListings", "Count") - @count = count.to_i - end + count = safe_retrieve(parsed_body, "CategoryListingsResponse", "Response", "CategoryListingsResult", "Alexa", "CategoryListings", "Count") + @count = count ? count.to_i : nil end def recursive_count return @recursive_count if defined?(@recursive_count) - if recursive_count = safe_retrieve(parsed_body, "CategoryListingsResponse", "Response", "CategoryListingsResult", "Alexa", "CategoryListings", "RecursiveCount") - @recursive_count = recursive_count.to_i - end + recursive_count = safe_retrieve(parsed_body, "CategoryListingsResponse", "Response", "CategoryListingsResult", "Alexa", "CategoryListings", "RecursiveCount") + @recursive_count = recursive_count ? recursive_count.to_i : nil end def listings diff --git a/lib/alexa/api/traffic_history.rb b/lib/alexa/api/traffic_history.rb index 5e23f26..0c8b982 100644 --- a/lib/alexa/api/traffic_history.rb +++ b/lib/alexa/api/traffic_history.rb @@ -26,9 +26,8 @@ def start def range return @range if defined?(@range) - if range = safe_retrieve(parsed_body, "TrafficHistoryResponse", "Response", "TrafficHistoryResult", "Alexa", "TrafficHistory", "Range") - @range = range.to_i - end + range = safe_retrieve(parsed_body, "TrafficHistoryResponse", "Response", "TrafficHistoryResult", "Alexa", "TrafficHistory", "Range") + @range = range ? range.to_i : nil end def data diff --git a/lib/alexa/api/url_info.rb b/lib/alexa/api/url_info.rb index 591b889..9ea3509 100644 --- a/lib/alexa/api/url_info.rb +++ b/lib/alexa/api/url_info.rb @@ -19,9 +19,8 @@ def fetch(arguments = {}) def rank return @rank if defined?(@rank) - if rank = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "TrafficData", "Rank") - @rank = rank.to_i - end + rank = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "TrafficData", "Rank") + @rank = rank ? rank.to_i : nil end def rank_by_country @@ -58,9 +57,8 @@ def language_encoding def links_in_count return @links_in_count if defined?(@links_in_count) - if links_in_count = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "LinksInCount") - @links_in_count = links_in_count.to_i - end + links_in_count = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "LinksInCount") + @links_in_count = links_in_count ? links_in_count.to_i : nil end def keywords @@ -69,22 +67,20 @@ def keywords def speed_median_load_time return @speed_median_load_time if defined?(@speed_median_load_time) - if speed_median_load_time = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "Speed", "MedianLoadTime") - @speed_median_load_time = speed_median_load_time.to_i - end + speed_median_load_time = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "Speed", "MedianLoadTime") + @speed_median_load_time = speed_median_load_time ? speed_median_load_time.to_i : nil end def speed_percentile return @speed_percentile if defined?(@speed_percentile) - if speed_percentile = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "Speed", "Percentile") - @speed_percentile = speed_percentile.to_i - end + speed_percentile = safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "ContentData", "Speed", "Percentile") + @speed_percentile = speed_percentile ? speed_percentile.to_i : nil end def related_links @related_links ||= safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "Related", "RelatedLinks", "RelatedLink") end - + def categories @categories ||= safe_retrieve(parsed_body, "UrlInfoResponse", "Response", "UrlInfoResult", "Alexa", "Related", "Categories", "CategoryData") end diff --git a/test/api/traffic_history_test.rb b/test/api/traffic_history_test.rb index beb8278..4b4419c 100644 --- a/test/api/traffic_history_test.rb +++ b/test/api/traffic_history_test.rb @@ -12,8 +12,8 @@ @traffic_history = Alexa::API::TrafficHistory.new(:access_key_id => "fake", :secret_access_key => "fake") @traffic_history.fetch(:url => "github.com", :range => 14) - # 14 days from now - assert_in_delta (Time.now - 3600 * 24 * 14).to_i, @traffic_history.arguments[:start].to_i, 0.001 + # 14 days ago + assert_in_delta (Time.now - 3600 * 24 * 14).to_i, @traffic_history.arguments[:start].to_i, 1 end describe "parsing xml" do