From 1f13d5fdd438b970cd861c520f273cf1b8c79dee Mon Sep 17 00:00:00 2001 From: Reid Thompson Date: Tue, 9 Dec 2014 15:31:10 -0500 Subject: [PATCH 1/2] make work my current system --- lib/noaa/http_service.rb | 6 ++-- lib/noaa/station.rb | 12 ++++---- lib/noaa/version.rb | 2 +- noaa.gemspec | 63 ++++++++++++++++++++++++---------------- test/test_helper.rb | 1 + test/test_station.rb | 4 +-- 6 files changed, 51 insertions(+), 37 deletions(-) diff --git a/lib/noaa/http_service.rb b/lib/noaa/http_service.rb index 2595b61..8332e01 100644 --- a/lib/noaa/http_service.rb +++ b/lib/noaa/http_service.rb @@ -5,15 +5,15 @@ def initialize(http = Net::HTTP) end def get_current_conditions(station_id) - LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/#{station_id}.xml"))) + LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/xml/current_obs/#{station_id}.xml"))) end def get_forecast(num_days, lat, lng) - LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}"))) + LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/forecasts/xml/sample_products/browser_interface/ndfdBrowserClientByDay.php?lat=#{lat}&lon=#{lng}&format=24+hourly&numDays=#{num_days}"))) end def get_station_list - LibXML::XML::Document.string(@HTTP.get(URI.parse("http://www.weather.gov/xml/current_obs/index.xml"))) + LibXML::XML::Document.string(@HTTP.get(URI.parse("http://w1.weather.gov/xml/current_obs/index.xml"))) end end end diff --git a/lib/noaa/station.rb b/lib/noaa/station.rb index 1a23df9..fcdd79b 100644 --- a/lib/noaa/station.rb +++ b/lib/noaa/station.rb @@ -31,7 +31,7 @@ def find(id) # # NOAA::Station.closest_to(37.989, -77.507) # NOAA::Station.closest_to([37.989, -77.507]) - # NOAA::Station.closest_to(GeoKit::LatLng.new(37.989, -77.507)) + # NOAA::Station.closest_to(Geokit::LatLng.new(37.989, -77.507)) def closest_to(*args) if args.length == 1 if args.first.respond_to?(:distance_to) @@ -39,19 +39,19 @@ def closest_to(*args) elsif %w(first last).all? { |m| args.first.respond_to?(m) } closest_to_lat_lng(args.first) else - raise ArgumentError, "expected two-element Array or GeoKit::LatLng" + raise ArgumentError, "expected two-element Array or Geokit::LatLng" end elsif args.length == 2 closest_to_lat_lng(args) else - raise ArgumentError, "closest_to() will accept one Array argument, one GeoKit::LatLng argument, or two FixNum arguments" + raise ArgumentError, "closest_to() will accept one Array argument, one Geokit::LatLng argument, or two FixNum arguments" end end private def closest_to_lat_lng(pair) - closest_to_coordinates(GeoKit::LatLng.new(pair.first, pair.last)) + closest_to_coordinates(Geokit::LatLng.new(pair.first, pair.last)) end def closest_to_coordinates(coordinates) @@ -74,7 +74,7 @@ def stations_file end end - # GeoKit::LatLng containing the station's coordinates + # Geokit::LatLng containing the station's coordinates attr_reader :coordinates # Station ID (e.g., "KNYC") @@ -92,7 +92,7 @@ def initialize(properties) @id, @name, @state, @xml_url = %w(id name state xml_url).map do |p| properties[p] end - @coordinates = GeoKit::LatLng.new(properties['latitude'], properties['longitude']) + @coordinates = Geokit::LatLng.new(properties['latitude'], properties['longitude']) end # Latitude of station diff --git a/lib/noaa/version.rb b/lib/noaa/version.rb index 9aa1c86..6e57f2a 100644 --- a/lib/noaa/version.rb +++ b/lib/noaa/version.rb @@ -1,3 +1,3 @@ module NOAA - VERSION = '0.2.3' + VERSION = '0.2.4' end diff --git a/noaa.gemspec b/noaa.gemspec index c5f6148..54a29ec 100644 --- a/noaa.gemspec +++ b/noaa.gemspec @@ -1,35 +1,48 @@ # -*- encoding: utf-8 -*- - -$: << File.expand_path(File.join(File.dirname(__FILE__), 'lib')) -require 'noaa/version' +# stub: noaa 0.2.4 ruby lib Gem::Specification.new do |s| - s.name = %q{noaa} - s.version = NOAA::VERSION + s.name = "noaa" + s.version = "0.2.4" s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version= + s.require_paths = ["lib"] s.authors = ["Mat Brown"] - s.date = Date.today - s.default_executable = %q{noaa-update-stations} - s.description = %q{Ruby API for National Oceanic and Atmospheric Administration weather data} - s.email = %q{mat@patch.com} + s.date = "2014-12-09" + s.description = "Ruby API for National Oceanic and Atmospheric Administration weather data" + s.email = "mat@patch.com" s.executables = ["noaa-update-stations"] - s.files = Dir.glob('{bin,lib,test,data}/**/*') + %w(CHANGELOG README) - s.has_rdoc = true - s.homepage = %q{http://github.com/outoftime/noaa} - s.post_install_message = %q{Be sure to update the weather station list: + s.extra_rdoc_files = ["CHANGELOG", "README", "bin/noaa-update-stations", "lib/noaa.rb", "lib/noaa/current_conditions.rb", "lib/noaa/forecast.rb", "lib/noaa/forecast_day.rb", "lib/noaa/http_service.rb", "lib/noaa/station.rb", "lib/noaa/station_writer.rb", "lib/noaa/version.rb"] + s.files = ["CHANGELOG", "Manifest", "README", "Rakefile", "bin/noaa-update-stations", "data/stations.yml", "lib/noaa.rb", "lib/noaa/current_conditions.rb", "lib/noaa/forecast.rb", "lib/noaa/forecast_day.rb", "lib/noaa/http_service.rb", "lib/noaa/station.rb", "lib/noaa/station_writer.rb", "lib/noaa/version.rb", "noaa.gemspec", "test/data/4-day.xml", "test/data/KVAY.xml", "test/data/stations-abridged.xml", "test/data/stations.xml", "test/data/stations.yml", "test/test_current_conditions.rb", "test/test_forecast.rb", "test/test_helper.rb", "test/test_http_service.rb", "test/test_station.rb", "test/test_station_writer.rb"] + s.homepage = "http://github.com/outoftime/noaa" + s.post_install_message = "Be sure to update the weather station list:\n\n\tsudo noaa-update-stations\n\nThis can be run at any time to update the stations, but you must run it once to initially populate the station list." + s.rdoc_options = ["--line-numbers", "--title", "Noaa", "--main", "README"] + s.rubyforge_project = "noaa" + s.rubygems_version = "2.4.5" + s.summary = "Ruby API for National Oceanic and Atmospheric Administration weather data" + s.test_files = ["test/test_helper.rb", "test/test_station_writer.rb", "test/test_http_service.rb", "test/test_current_conditions.rb", "test/test_forecast.rb", "test/test_station.rb"] - sudo noaa-update-stations + if s.respond_to? :specification_version then + s.specification_version = 4 -This can be run at any time to update the stations, but you must run it once to initially populate the station list.} - s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Noaa", "--main", "README"] - s.require_paths = ["lib"] - s.rubyforge_project = %q{noaa} - s.rubygems_version = %q{1.3.1} - s.summary = %q{Ruby API for National Oceanic and Atmospheric Administration weather data} - s.test_files = ["test/test_station_writer.rb", "test/test_forecast.rb", "test/test_helper.rb", "test/test_station.rb", "test/test_http_service.rb", "test/test_current_conditions.rb"] - s.add_runtime_dependency('nokogiri', '>= 0.9.7') - s.add_runtime_dependency('geokit', '>= 1.5.0') - s.add_development_dependency('mcmire-context', ">= 0.0.16") - s.add_development_dependency('jnunemaker-matchy', ">= 0.4.0") + if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then + s.add_runtime_dependency(%q= 0.9.7)>, [">= 0"]) + s.add_runtime_dependency(%q= 1.5.0)>, [">= 0"]) + s.add_development_dependency(%q= 0.0.6)>, [">= 0"]) + s.add_development_dependency(%q= 0.0.1)>, [">= 0"]) + s.add_development_dependency(%q 0.10)>, [">= 0"]) + else + s.add_dependency(%q= 0.9.7)>, [">= 0"]) + s.add_dependency(%q= 1.5.0)>, [">= 0"]) + s.add_dependency(%q= 0.0.6)>, [">= 0"]) + s.add_dependency(%q= 0.0.1)>, [">= 0"]) + s.add_dependency(%q 0.10)>, [">= 0"]) + end + else + s.add_dependency(%q= 0.9.7)>, [">= 0"]) + s.add_dependency(%q= 1.5.0)>, [">= 0"]) + s.add_dependency(%q= 0.0.6)>, [">= 0"]) + s.add_dependency(%q= 0.0.1)>, [">= 0"]) + s.add_dependency(%q 0.10)>, [">= 0"]) + end end diff --git a/test/test_helper.rb b/test/test_helper.rb index 44a32af..fcb7aa6 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,6 +1,7 @@ begin require 'context' require 'matchy' + require 'openssl' rescue LoadError => e if require 'rubygems' then retry else raise(e) diff --git a/test/test_station.rb b/test/test_station.rb index 2aaefd8..f3cf33f 100644 --- a/test/test_station.rb +++ b/test/test_station.rb @@ -14,7 +14,7 @@ class TestStation < NOAA::TestCase end test 'should find closest to coordinates' do - NOAA::Station.closest_to(GeoKit::LatLng.new(40.8, -73.96)).id.should == 'KNYC' + NOAA::Station.closest_to(Geokit::LatLng.new(40.8, -73.96)).id.should == 'KNYC' end test 'should find closest to lat/lng' do @@ -54,7 +54,7 @@ class TestStation < NOAA::TestCase end test 'should return coordinates' do - station.coordinates.should == GeoKit::LatLng.new(40.783, -73.967) + station.coordinates.should == Geokit::LatLng.new(40.783, -73.967) end private From 8ba9de16378ce1222ef27b75aed5003ddf95167f Mon Sep 17 00:00:00 2001 From: Reid Thompson <1116827+jreidthompson@users.noreply.github.com> Date: Fri, 4 May 2018 12:41:12 -0400 Subject: [PATCH 2/2] add libxml to requires --- lib/noaa.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/noaa.rb b/lib/noaa.rb index 90801a4..7eeb93c 100644 --- a/lib/noaa.rb +++ b/lib/noaa.rb @@ -2,6 +2,7 @@ require 'time' require 'nokogiri' require 'geokit' + require 'libxml' rescue LoadError => e if require 'rubygems' then retry else raise(e)