Skip to content

Commit b599fff

Browse files
authored
Merge pull request #2 from mgm702/develop
V1.0.0 release
2 parents b85e9fa + 99003e5 commit b599fff

79 files changed

Lines changed: 69628 additions & 134 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/docs.yml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: Deploy Documentation
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
permissions:
8+
contents: read
9+
pages: write
10+
id-token: write
11+
12+
concurrency:
13+
group: "pages"
14+
cancel-in-progress: false
15+
16+
jobs:
17+
deploy:
18+
runs-on: ubuntu-latest
19+
environment:
20+
name: github-pages
21+
url: ${{ steps.deployment.outputs.page_url }}
22+
23+
steps:
24+
- uses: actions/checkout@v4
25+
26+
- name: Set up Ruby
27+
uses: ruby/setup-ruby@v1
28+
with:
29+
ruby-version: '3.2'
30+
bundler-cache: true
31+
32+
- name: Install dependencies
33+
run: bundle install
34+
35+
- name: Generate YARD documentation
36+
run: bundle exec yard doc
37+
38+
- name: Setup Pages
39+
uses: actions/configure-pages@v4
40+
41+
- name: Upload artifact
42+
uses: actions/upload-pages-artifact@v3
43+
with:
44+
path: './doc'
45+
46+
- name: Deploy to GitHub Pages
47+
id: deployment
48+
uses: actions/deploy-pages@v4

README.md

Lines changed: 236 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,256 @@
1-
# Usgs::Ruby
1+
# **usgs-ruby**
22

3-
TODO: Delete this and the text below, and describe your gem
3+
[![Build Status](https://github.com/YOUR_USERNAME/usgs-ruby/actions/workflows/ci.yml/badge.svg)](https://github.com/YOUR_USERNAME/usgs-ruby/actions)
4+
[![Gem Version](https://badge.fury.io/rb/usgs-ruby.svg)](https://badge.fury.io/rb/usgs-ruby)
5+
[![MIT license](https://img.shields.io/badge/license-MIT-brightgreen.svg)](https://opensource.org/licenses/MIT)
46

5-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/usgs/ruby`. To experiment with that code, run `bin/console` for an interactive prompt.
7+
[**« USGS »**](https://www.usgs.gov/)
68

7-
## Installation
9+
[**USGS Water Services**](https://waterservices.usgs.gov/)
810

9-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
11+
The goal of [**`usgs-ruby`**](https://rubygems.org/gems/usgs-ruby) is to provide functions that help Ruby users to navigate, explore, and make requests to the USGS Water Services API.
1012

11-
Install the gem and add to the application's Gemfile by executing:
13+
The United States Geological Survey (USGS) Water Services provides access to water resources data collected at approximately 1.9 million sites across the United States. This includes real-time and historical data for streamflow, groundwater levels, water quality, and more.
1214

13-
$ bundle add UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
15+
Thank you to the USGS for providing an accessible and well-documented API!
1416

15-
If bundler is not being used to manage dependencies, install the gem by executing:
17+
---
1618

17-
$ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
19+
## **Installation**
1820

19-
## Usage
21+
Add this line to your application's Gemfile:
2022

21-
TODO: Write usage instructions here
23+
```ruby
24+
gem 'usgs-ruby'
25+
```
2226

23-
## Development
27+
and then execute:
28+
29+
```bash
30+
bundle install
31+
```
32+
33+
or install it yourself as:
34+
35+
```bash
36+
gem install usgs-ruby
37+
```
38+
39+
## **Getting Started**
40+
41+
Using the gem is simple. Create a client and start making requests:
42+
43+
```ruby
44+
require 'usgs'
45+
46+
# Create a client
47+
client = Usgs.client
48+
49+
# Get site information
50+
sites = client.get_sites(state_cd: "CO", parameter_cd: :discharge)
51+
52+
# Get daily values (last 24 hours by default)
53+
readings = client.get_dv(sites: "06754000", parameter_cd: :discharge)
54+
55+
# Get instantaneous values
56+
iv_readings = client.get_iv(sites: "06754000", parameter_cd: :discharge)
57+
58+
# Get statistics
59+
stats = client.get_stats(sites: "06754000", report_type: :daily)
60+
```
61+
62+
## **Available Endpoints**
63+
64+
The `usgs-ruby` gem provides access to all major USGS Water Services endpoints through an intuitive interface. For detailed documentation on each endpoint and its methods, please visit our [documentation site](https://YOUR_USERNAME.github.io/usgs-ruby).
65+
66+
### Key Modules:
67+
68+
* **Daily Values (DV)** - Access daily streamflow, groundwater, and water quality data
69+
```ruby
70+
client.get_dv(sites: "06754000", parameter_cd: :discharge,
71+
start_date: "2023-01-01", end_date: "2023-12-31")
72+
```
73+
74+
* **Instantaneous Values (IV)** - Get real-time water data (15-minute intervals)
75+
```ruby
76+
client.get_iv(sites: "06754000", parameter_cd: :discharge)
77+
```
78+
79+
* **Site Information** - Search and retrieve monitoring location metadata
80+
```ruby
81+
client.get_sites(state_cd: "CO", site_type: "ST", parameter_cd: :discharge)
82+
```
83+
84+
* **Statistics** - Access statistical summaries (daily, monthly, annual)
85+
```ruby
86+
client.get_stats(sites: "06754000", report_type: :annual,
87+
stat_year_type: "water")
88+
```
89+
90+
### Supported Parameter Codes:
91+
92+
The gem includes convenient symbols for common parameters:
93+
94+
- `:discharge` - Streamflow (cubic feet per second)
95+
- `:gage_height` - Gage height (feet)
96+
- `:temperature` - Water temperature (°C)
97+
- `:precipitation` - Precipitation (inches)
98+
- `:do` - Dissolved oxygen (mg/L)
99+
- `:conductivity` - Specific conductance (µS/cm)
100+
- `:ph` - pH
101+
102+
You can also use USGS parameter codes directly (e.g., `"00060"` for discharge).
103+
104+
## **Examples**
105+
106+
### Finding Sites
107+
108+
```ruby
109+
# Search by state
110+
sites = client.get_sites(state_cd: "CO")
111+
112+
# Search by bounding box (west, south, east, north)
113+
sites = client.get_sites(bBox: "-105.5,39.5,-105.0,40.0")
114+
115+
# Search by site name
116+
sites = client.get_sites(site_name: "Boulder Creek")
117+
118+
# Filter by site type and parameter
119+
sites = client.get_sites(state_cd: "CO", site_type: "ST",
120+
parameter_cd: :discharge)
121+
```
122+
123+
### Retrieving Data
124+
125+
```ruby
126+
# Get recent daily values
127+
readings = client.get_dv(sites: "06754000", parameter_cd: :discharge)
128+
129+
# Get historical daily values
130+
readings = client.get_dv(
131+
sites: "06754000",
132+
parameter_cd: :discharge,
133+
start_date: Date.parse("2020-01-01"),
134+
end_date: Date.parse("2023-12-31")
135+
)
136+
137+
# Get multiple parameters
138+
readings = client.get_dv(
139+
sites: "06754000",
140+
parameter_cd: [:discharge, :gage_height]
141+
)
142+
143+
# Get data from multiple sites
144+
readings = client.get_dv(
145+
sites: ["06754000", "06752000"],
146+
parameter_cd: :discharge
147+
)
148+
```
149+
150+
### Working with Statistics
151+
152+
```ruby
153+
# Daily statistics
154+
stats = client.get_stats(sites: "06754000", report_type: :daily)
155+
156+
# Monthly statistics
157+
stats = client.get_stats(sites: "06754000", report_type: :monthly)
158+
159+
# Annual statistics (water year)
160+
stats = client.get_stats(
161+
sites: "06754000",
162+
report_type: :annual,
163+
stat_year_type: "water"
164+
)
165+
```
166+
167+
## **Configuration**
168+
169+
You can configure the client with custom options:
170+
171+
```ruby
172+
Usgs.configure do |config|
173+
config.user_agent = "MyApp/1.0 (contact@example.com)"
174+
end
175+
176+
client = Usgs.client
177+
```
178+
179+
## **Development**
24180

25181
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
26182

27-
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
183+
To install this gem onto your local machine, run `bundle exec rake install`.
184+
185+
### Running Tests
186+
187+
```bash
188+
bundle exec rake test
189+
```
190+
191+
### Generating Documentation
192+
193+
```bash
194+
bundle exec yard doc
195+
open doc/index.html
196+
```
197+
198+
### Running RuboCop
199+
200+
```bash
201+
bundle exec rubocop
202+
```
203+
204+
## **Testing**
205+
206+
This gem uses VCR for recording HTTP interactions during testing. When writing tests:
207+
208+
1. Tests will record real API responses on first run
209+
2. Subsequent runs use cached responses (cassettes)
210+
3. Cassettes are stored in `test/fixtures/vcr_cassettes/`
211+
212+
## **Contributing**
213+
214+
Contributions are welcome! Please follow these steps:
215+
216+
1. Fork the repository
217+
2. Create a feature branch (`git checkout -b feature/my-new-feature`)
218+
3. Write tests for your changes
219+
4. Make your changes and ensure tests pass (`rake test`)
220+
5. Run RuboCop and fix any violations (`rubocop`)
221+
6. Commit your changes with clear, descriptive messages
222+
7. Push to your branch (`git push origin feature/my-new-feature`)
223+
8. Create a Pull Request
224+
225+
Please make sure that your commit messages are clear and understandable.
226+
227+
## **Documentation**
228+
229+
Full API documentation is available at [https://YOUR_USERNAME.github.io/usgs-ruby](https://YOUR_USERNAME.github.io/usgs-ruby)
230+
231+
## **Resources**
232+
233+
- [USGS Water Services](https://waterservices.usgs.gov/)
234+
- [USGS Water Services REST API Documentation](https://waterservices.usgs.gov/rest/Site-Service.html)
235+
- [USGS Parameter Codes](https://help.waterdata.usgs.gov/parameter_cd?group_cd=%)
236+
237+
## **License**
238+
239+
The usgs-ruby gem is licensed under the MIT license. See [LICENSE](LICENSE) for details.
240+
241+
## **Acknowledgments**
28242

29-
## Contributing
243+
- Thanks to the USGS for maintaining an excellent public API
244+
- Inspired by similar projects in other languages
30245

31-
Bug reports and pull requests are welcome on GitHub at https://github.com/mgm702/usgs-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mgm702/usgs-ruby/blob/main/CODE_OF_CONDUCT.md).
246+
## **Support**
32247

33-
## License
248+
If you encounter any issues or have questions:
34249

35-
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
250+
1. Check the [documentation](https://YOUR_USERNAME.github.io/usgs-ruby)
251+
2. Search existing [GitHub Issues](https://github.com/YOUR_USERNAME/usgs-ruby/issues)
252+
3. Open a new issue with a clear description and example code
36253

37-
## Code of Conduct
254+
---
38255

39-
Everyone interacting in the Usgs::Ruby project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mgm702/usgs-ruby/blob/main/CODE_OF_CONDUCT.md).
256+
**Like the gem?** Star the repository on [GitHub](https://github.com/YOUR_USERNAME/usgs-ruby)!

Rakefile

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
require "bundler/gem_tasks"
44
require "rake/testtask"
5+
require "rubocop/rake_task"
6+
require "yard"
57

68
Rake::TestTask.new(:test) do |t|
79
t.libs << "test"
810
t.libs << "lib"
911
t.test_files = FileList["test/**/test_*.rb"]
1012
end
1113

12-
require "rubocop/rake_task"
13-
1414
RuboCop::RakeTask.new
1515

1616
task default: %i[test rubocop]
17+
18+
YARD::Rake::YardocTask.new do |t|
19+
t.options = ["--output-dir", "docs"]
20+
end
21+
22+
task :publish_docs do
23+
sh "git subtree push --prefix docs origin gh-pages"
24+
end

0 commit comments

Comments
 (0)