Sha256: b1e1a01eb201f1c4c2230efae4f7cbea59536803ee1f5d826d90ab6fc7de0322

Contents?: true

Size: 749 Bytes

Versions: 2

Compression:

Stored size: 749 Bytes

Contents

require 'net/http'
require 'uri'
require 'json'

# Europe Gem
module Europe
  # Eurostat
  module Eurostat
    STAT_URL = 'http://ec.europa.eu/eurostat/wdds' \
               '/rest/data/v1.1/json/en/'

    def self.retrieve(dataset, filters)
      fetch_stats(dataset, filters)
    end

    private

    def self.generate_url(dataset, _filters)
      uri = URI.parse(STAT_URL + dataset)
      params = {
        precision: 1, geo: 'EU28',
        unit: 'EUR_HAB', time: '2010',
        indic_na: 'B1GM', unitLabel: 'code' }
      uri.query = URI.encode_www_form(params)
      uri
    end

    def self.fetch_stats(dataset, filters)
      uri = generate_url(dataset, filters)
      resp = Net::HTTP.get(uri)
      JSON.parse(resp)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
europe-0.0.4 lib/europe/eurostat/eurostat.rb
europe-0.0.3 lib/europe/eurostat/eurostat.rb