Skip to content

Commit

Permalink
make time assertion less restrictive to avoid failures
Browse files Browse the repository at this point in the history
  • Loading branch information
morgoth committed Sep 1, 2013
1 parent 7882194 commit b089f56
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 24 deletions.
10 changes: 4 additions & 6 deletions lib/alexa/api/category_listings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/alexa/api/traffic_history.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
22 changes: 9 additions & 13 deletions lib/alexa/api/url_info.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions test/api/traffic_history_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit b089f56

Please sign in to comment.