Skip to content

Instantly share code, notes, and snippets.

@gr33n7007h
Last active March 29, 2020 21:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gr33n7007h/69ded10e271252346501f2ba42ec590f to your computer and use it in GitHub Desktop.
Save gr33n7007h/69ded10e271252346501f2ba42ec590f to your computer and use it in GitHub Desktop.
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