usgs-ruby 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (57) hide show
  1. checksums.yaml +7 -0
  2. data/.rubocop.yml +87 -0
  3. data/CHANGELOG.md +5 -0
  4. data/CODE_OF_CONDUCT.md +84 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +256 -0
  7. data/Rakefile +24 -0
  8. data/docs/Usgs/Client.html +563 -0
  9. data/docs/Usgs/DailyValues.html +338 -0
  10. data/docs/Usgs/InstantaneousValues.html +329 -0
  11. data/docs/Usgs/Models/Reading.html +1124 -0
  12. data/docs/Usgs/Models/Site.html +2030 -0
  13. data/docs/Usgs/Models/Statistic.html +3981 -0
  14. data/docs/Usgs/Models.html +117 -0
  15. data/docs/Usgs/Parser.html +346 -0
  16. data/docs/Usgs/Parsers/RdbParser.html +354 -0
  17. data/docs/Usgs/Parsers/SiteParser.html +174 -0
  18. data/docs/Usgs/Parsers/StatisticsParser.html +228 -0
  19. data/docs/Usgs/Parsers/TimeSeriesParser.html +189 -0
  20. data/docs/Usgs/Parsers.html +117 -0
  21. data/docs/Usgs/Site.html +445 -0
  22. data/docs/Usgs/Statistics.html +335 -0
  23. data/docs/Usgs/Utils.html +357 -0
  24. data/docs/Usgs.html +303 -0
  25. data/docs/_index.html +286 -0
  26. data/docs/class_list.html +54 -0
  27. data/docs/css/common.css +1 -0
  28. data/docs/css/full_list.css +58 -0
  29. data/docs/css/style.css +503 -0
  30. data/docs/file.README.html +111 -0
  31. data/docs/file_list.html +59 -0
  32. data/docs/frames.html +22 -0
  33. data/docs/index.html +111 -0
  34. data/docs/js/app.js +344 -0
  35. data/docs/js/full_list.js +242 -0
  36. data/docs/js/jquery.js +4 -0
  37. data/docs/method_list.html +598 -0
  38. data/docs/top-level-namespace.html +110 -0
  39. data/lib/usgs/client.rb +62 -0
  40. data/lib/usgs/daily_values.rb +38 -0
  41. data/lib/usgs/instantaneous_values.rb +35 -0
  42. data/lib/usgs/models/reading.rb +43 -0
  43. data/lib/usgs/models/site.rb +61 -0
  44. data/lib/usgs/models/statistic.rb +95 -0
  45. data/lib/usgs/parser.rb +23 -0
  46. data/lib/usgs/parsers/rdb_parser.rb +55 -0
  47. data/lib/usgs/parsers/site_parser.rb +13 -0
  48. data/lib/usgs/parsers/statistics_parser.rb +40 -0
  49. data/lib/usgs/parsers/time_series_parser.rb +54 -0
  50. data/lib/usgs/site.rb +50 -0
  51. data/lib/usgs/statistics.rb +42 -0
  52. data/lib/usgs/utils.rb +50 -0
  53. data/lib/usgs/version.rb +5 -0
  54. data/lib/usgs.rb +28 -0
  55. data/sig/usgs/ruby.rbs +6 -0
  56. data/usgs-ruby.gemspec +48 -0
  57. metadata +231 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 90c31d4e2da0bfbeda5ed5e6b5ae37b358df9432740c7b55bb730e445600c07f
4
+ data.tar.gz: 9f8ec80140d27872755ae841a8022d4590590dcd8b8ca0520b19bb8ad2ec48ae
5
+ SHA512:
6
+ metadata.gz: f14971c5157e372bcf0fdbae4272aa3477a49a44c417a7ae8951fd04447ef7457bed798e32024921893ca545d952e1bf6492cf47cab7c444c04de19e4052617d
7
+ data.tar.gz: 9941d12c94c95e9e2a0e009ea026c93de0b2dc288241c07d421febfce5e2090657f7288c875a83287e750d9cdb4dbf3ca09131350c06b0dae9c3461283e85247
data/.rubocop.yml ADDED
@@ -0,0 +1,87 @@
1
+ # .rubocop.yml
2
+ require:
3
+ - rubocop-minitest
4
+
5
+ AllCops:
6
+ TargetRubyVersion: 3.0
7
+ NewCops: enable
8
+
9
+ # Allow development dependencies in gemspec
10
+ Gemspec/DevelopmentDependencies:
11
+ Enabled: false
12
+
13
+ # Make documentation optional for most files
14
+ Style/Documentation:
15
+ Enabled: false
16
+
17
+ # Allow unused arguments (often needed for API compatibility)
18
+ Lint/UnusedMethodArgument:
19
+ Enabled: false
20
+
21
+ # Allow missing super in inherited callbacks
22
+ Lint/MissingSuper:
23
+ Enabled: false
24
+
25
+ # Allow private class methods to be defined normally
26
+ Lint/IneffectiveAccessModifier:
27
+ Enabled: false
28
+
29
+ # Allow longer classes and modules for better organization
30
+ Metrics/ClassLength:
31
+ Max: 200
32
+ Exclude:
33
+ - 'test/**/*'
34
+
35
+ Metrics/ModuleLength:
36
+ Max: 200
37
+
38
+ # Allow more reasonable method lengths
39
+ Metrics/MethodLength:
40
+ Max: 40
41
+ Exclude:
42
+ - 'test/**/*'
43
+
44
+ Metrics/AbcSize:
45
+ Max: 50
46
+ Exclude:
47
+ - 'test/**/*'
48
+
49
+ Metrics/CyclomaticComplexity:
50
+ Max: 12
51
+
52
+ Metrics/PerceivedComplexity:
53
+ Max: 12
54
+
55
+ # Allow longer parameter lists for API methods
56
+ Metrics/ParameterLists:
57
+ Max: 10
58
+ CountKeywordArgs: false
59
+
60
+ # Allow longer lines, especially for documentation
61
+ Layout/LineLength:
62
+ Max: 150
63
+ Exclude:
64
+ - 'test/**/*'
65
+
66
+ # Allow larger blocks in tests
67
+ Metrics/BlockLength:
68
+ Exclude:
69
+ - 'test/**/*'
70
+ - '*.gemspec'
71
+
72
+ # Other style preferences
73
+ Style/StringLiterals:
74
+ EnforcedStyle: double_quotes
75
+
76
+ Lint/DuplicateMethods:
77
+ Exclude:
78
+ - 'test/**/*'
79
+
80
+ Style/FrozenStringLiteralComment:
81
+ Enabled: false
82
+
83
+ Lint/Void:
84
+ Exclude:
85
+ - test/cdss/test_analysis.rb
86
+ - test/cdss/test_structures.rb
87
+
data/CHANGELOG.md ADDED
@@ -0,0 +1,5 @@
1
+ ## [Unreleased]
2
+
3
+ ## [0.1.0] - 2025-11-21
4
+
5
+ - Initial release
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at mattm3646@gmail.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025 Matt Michnal
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,256 @@
1
+ # **usgs-ruby**
2
+
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)
6
+
7
+ [**« USGS »**](https://www.usgs.gov/)
8
+
9
+ [**USGS Water Services**](https://waterservices.usgs.gov/)
10
+
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.
12
+
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.
14
+
15
+ Thank you to the USGS for providing an accessible and well-documented API!
16
+
17
+ ---
18
+
19
+ ## **Installation**
20
+
21
+ Add this line to your application's Gemfile:
22
+
23
+ ```ruby
24
+ gem 'usgs-ruby'
25
+ ```
26
+
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**
180
+
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.
182
+
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**
242
+
243
+ - Thanks to the USGS for maintaining an excellent public API
244
+ - Inspired by similar projects in other languages
245
+
246
+ ## **Support**
247
+
248
+ If you encounter any issues or have questions:
249
+
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
253
+
254
+ ---
255
+
256
+ **Like the gem?** Star the repository on [GitHub](https://github.com/YOUR_USERNAME/usgs-ruby)!
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/testtask"
5
+ require "rubocop/rake_task"
6
+ require "yard"
7
+
8
+ Rake::TestTask.new(:test) do |t|
9
+ t.libs << "test"
10
+ t.libs << "lib"
11
+ t.test_files = FileList["test/**/test_*.rb"]
12
+ end
13
+
14
+ RuboCop::RakeTask.new
15
+
16
+ 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