|
1 | | -# Usgs::Ruby |
| 1 | +# **usgs-ruby** |
2 | 2 |
|
3 | | -TODO: Delete this and the text below, and describe your gem |
| 3 | +[](https://github.com/YOUR_USERNAME/usgs-ruby/actions) |
| 4 | +[](https://badge.fury.io/rb/usgs-ruby) |
| 5 | +[](https://opensource.org/licenses/MIT) |
4 | 6 |
|
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/) |
6 | 8 |
|
7 | | -## Installation |
| 9 | +[**USGS Water Services**](https://waterservices.usgs.gov/) |
8 | 10 |
|
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. |
10 | 12 |
|
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. |
12 | 14 |
|
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! |
14 | 16 |
|
15 | | -If bundler is not being used to manage dependencies, install the gem by executing: |
| 17 | +--- |
16 | 18 |
|
17 | | - $ gem install UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG |
| 19 | +## **Installation** |
18 | 20 |
|
19 | | -## Usage |
| 21 | +Add this line to your application's Gemfile: |
20 | 22 |
|
21 | | -TODO: Write usage instructions here |
| 23 | +```ruby |
| 24 | +gem 'usgs-ruby' |
| 25 | +``` |
22 | 26 |
|
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** |
24 | 180 |
|
25 | 181 | 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. |
26 | 182 |
|
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** |
28 | 242 |
|
29 | | -## Contributing |
| 243 | +- Thanks to the USGS for maintaining an excellent public API |
| 244 | +- Inspired by similar projects in other languages |
30 | 245 |
|
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** |
32 | 247 |
|
33 | | -## License |
| 248 | +If you encounter any issues or have questions: |
34 | 249 |
|
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 |
36 | 253 |
|
37 | | -## Code of Conduct |
| 254 | +--- |
38 | 255 |
|
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)! |
0 commit comments