nws-client
Version, currently master branch1 version
- master branchlatestAug 17, 2020
github.com/dscottboggs/crystal-nws-client
Crystal client library for the US National Weather Service API
Installation
# Add this to your shard.yml
dependencies:
nws-client:
github: dscottboggs/crystal-nws-client
branch: mastermaster is a branch, not a release, so this tracks it rather than pinning a version.
Then run:
shards installshard.yml
- Crystal
0.35.1- License
- MIT
- Author
- D. Scott Boggs
Dependencies
This version declares no dependencies.
README
NWS Client
A Crystal library for querying the United States' National Weather Service API.
Installation
-
Add the dependency to your
shard.yml:dependencies: nws-client: github: dscottboggs/nws-client -
Run
shards install
Usage
require "nws-client/gridpoints/forecast"
NWSClient.gridpoints("PBZ", 74, 68)
.forecast
.properties
.periods
.each do |forecast|
puts "it will be #{forecast.temperature} #{forecast.name}"
end
Output:
it will be 81 Today
it will be 62 Tonight
it will be 82 Tuesday
it will be 58 Tuesday Night
it will be 82 Wednesday
it will be 58 Wednesday Night
it will be 86 Thursday
it will be 62 Thursday Night
it will be 89 Friday
it will be 65 Friday Night
it will be 88 Saturday
it will be 65 Saturday Night
it will be 85 Sunday
it will be 64 Sunday Night
Development
Not all API endpoints are currently implemented. If you need to query an endpoint which hasn't been implemented yet, the procedure for implementing it is:
- Download a sample(s) from the endpoint you want to be able to query from Crystal
curl -L api.weather.gov/gridpoints/PBZ/74,68/forecast > src/types/gridpoints_forecast.json
- Run
jeneratoron the downloaded sample(s).
cd samples
jenerator .
-
Write a spec for the new type, based on the existing examples in the
specdir, which tests that your generated types successfully parse the sample you downloaded. -
Edit the generated file(s) until the specs pass. This involves removing redundant ArrayMember types, and changing any
Niltypes to the optional of what they're expected to be (i.e.String?orFloat64?). This may include pulling class definitions from nested structures other redundant ArrayMember types. This is definitely the hardest part of the process, but it should only take a few minutes. -
Add a
fetchclass method to your type:- If your query can be constant, assign it to
FETCH_PATHin your type, and include APIHelper. Seesrc/types/alerts.crfor an example. - If your query needs some parameters, define a custom
fetchmethod like insrc/types/gridpoints_forecast.cr
- If your query can be constant, assign it to
-
Add a convenience class method to the NWSClient in
src/nws-client/. This method and any support types should be defined in a single file in that folder. For example:- alerts queries should be requirable with
require "nws-client/alerts" - all queries related to gridpoints should be requirable with
require "nws-client/gridpoints", while the forecasts for a gridpoint should be able to be required withrequire "nws-client/gridpoints/forecast".
These client files should only require the types under
src/types/which are needed to make a given request. - alerts queries should be requirable with
Contributing
- Fork it (https://github.com/dscottboggs/nws-client/fork)
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request
Contributors
- D. Scott Boggs - creator and maintainer
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This branch
- Branch
master- Seen
- Aug 17, 2020
- Crystal
0.35.1- Indexed
- yes
Dependents
No indexed shard depends on this one yet.
Repository
github.com/dscottboggs/crystal-nws-client
Metadata
- Created
- Aug 12, 2026
- Updated
- Aug 16, 2026
- Synced
- Aug 16, 2026
- Versions
- 1