Sha256: f0309591c46318612130d6d1c90df9b3b7b8ffe05677c392ff992b4ef658af91

Contents?: true

Size: 688 Bytes

Versions: 4

Compression:

Stored size: 688 Bytes

Contents

require "alert"
require "httparty"

module Noaa
  class Client
    attr_reader :alerts

    def initialize(state)
      @alerts = []
      get_alerts(state)
    end

    private

    def get_alerts(state)
      catalog = HTTParty.get("http://alerts.weather.gov/cap/#{state}.php?x=0",
                             format: :xml)
      handle_catalog(catalog)
    end

    def handle_catalog(catalog)
      entries = catalog['feed']['entry']
      entries = [entries] unless entries.kind_of?(Array)
      entries.each do |entry| 
        item = HTTParty.get(entry['id'],
                            format: :xml)['alert']
        @alerts << Noaa::Alert.new(item)
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
noaa-alerts-0.1.1 lib/client.rb
noaa-alerts-0.1.0 lib/client.rb
noaa-alerts-0.0.2 lib/client.rb
noaa-alerts-0.0.1 lib/client.rb