Class: Falcore::Fetcher
- Inherits:
-
Object
- Object
- Falcore::Fetcher
- Defined in:
- lib/falcore/fetcher.rb
Class Method Summary collapse
-
.get(url) ⇒ Hash
Get the JSON at the given URL and parse it as such.
Class Method Details
.get(url) ⇒ Hash
Get the JSON at the given URL and parse it as such. This method is just a very thin wrapper around Ruby’s native OpenURI with some error- handling magic.
40 41 42 43 44 45 46 47 |
# File 'lib/falcore/fetcher.rb', line 40 def get(url) response = open(url) JSON.parse(response.read) rescue Errno::ENOENT, OpenURI::HTTPError, SocketError => e raise "Failed to GET '#{url}': #{e.class} - #{e.}" rescue JSON::ParserError raise 'Invalid JSON!' end |