-
-
Save gr33n7007h/69ded10e271252346501f2ba42ec590f to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def aggregator(isos, meth) | |
countries_array = JSON.parse(Typhoeus.get(UriBuilder.new('/countries').url, cache_ttl: 900).response_body) | |
country_array = countries_array.select do |hash| | |
isos.include?(hash['countryInfo']['iso2']) | |
end | |
country_array.inject do |base, other| | |
base.merge(other) do |key, left, right| | |
left ||= 0 | |
right ||= 0 | |
left + right unless %w[country countryInfo].include?(key) | |
end | |
end.compact | |
meth === data | |
rescue JSON::ParserError | |
puts SERVER_DOWN | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment