weather_gov_api 0.2.1 → 0.3.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +41 -30
- data/.rubocop_todo.yml +0 -31
- data/.ruby-version +1 -0
- data/.vscode/extensions.json +6 -0
- data/CHANGELOG.md +18 -1
- data/README.md +0 -3
- data/lib/weather_gov_api/api_errors.rb +41 -0
- data/lib/weather_gov_api/client.rb +42 -12
- data/lib/weather_gov_api/version.rb +1 -1
- data/lib/weather_gov_api.rb +1 -0
- metadata +6 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1774def1c5d0e09a3fb74a4d66b0f2c63c6c18fd97c02871690db6bfdac5c38c
|
4
|
+
data.tar.gz: 35336afbc96f2517d96b993de9e73501b427843cc649b0b1217d621c7b9be8dc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b54fd7e6fb5572e2ae2341f8a6e8049174c3961cda8f4a01e18541f6dfc63cca2e91c4e96fc1a98788f490fcc23ebac33208accdfb55f6f1faa57d07c05f0e4
|
7
|
+
data.tar.gz: 758cea3008922169f96395ba0540abad5154b224ffbf0b1a4435068db79a9b68031f3e733aa1e2c05189baf7950a4a90556345d9652b819b4b880bded8e84605
|
data/.rubocop.yml
CHANGED
@@ -1,30 +1,41 @@
|
|
1
|
-
inherit_from: .rubocop_todo.yml
|
2
|
-
|
3
|
-
require:
|
4
|
-
- rubocop-rspec
|
5
|
-
|
6
|
-
AllCops:
|
7
|
-
NewCops: enable
|
8
|
-
TargetRubyVersion: 3.1
|
9
|
-
|
10
|
-
Style/StringLiterals:
|
11
|
-
EnforcedStyle: double_quotes
|
12
|
-
|
13
|
-
Style/StringLiteralsInInterpolation:
|
14
|
-
EnforcedStyle: double_quotes
|
15
|
-
|
16
|
-
Layout/EndOfLine:
|
17
|
-
EnforcedStyle: lf
|
18
|
-
|
19
|
-
# Disable documentation requirements for specs
|
20
|
-
Style/Documentation:
|
21
|
-
Enabled: true
|
22
|
-
Exclude:
|
23
|
-
- "spec/**/*"
|
24
|
-
|
25
|
-
# Allow longer blocks in specs
|
26
|
-
Metrics/BlockLength:
|
27
|
-
Enabled: true
|
28
|
-
Exclude:
|
29
|
-
- "spec/**/*"
|
30
|
-
- "*.gemspec"
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
require:
|
4
|
+
- rubocop-rspec
|
5
|
+
|
6
|
+
AllCops:
|
7
|
+
NewCops: enable
|
8
|
+
TargetRubyVersion: 3.1
|
9
|
+
|
10
|
+
Style/StringLiterals:
|
11
|
+
EnforcedStyle: double_quotes
|
12
|
+
|
13
|
+
Style/StringLiteralsInInterpolation:
|
14
|
+
EnforcedStyle: double_quotes
|
15
|
+
|
16
|
+
Layout/EndOfLine:
|
17
|
+
EnforcedStyle: lf
|
18
|
+
|
19
|
+
# Disable documentation requirements for specs
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: true
|
22
|
+
Exclude:
|
23
|
+
- "spec/**/*"
|
24
|
+
|
25
|
+
# Allow longer blocks in specs
|
26
|
+
Metrics/BlockLength:
|
27
|
+
Enabled: true
|
28
|
+
Exclude:
|
29
|
+
- "spec/**/*"
|
30
|
+
- "*.gemspec"
|
31
|
+
|
32
|
+
Metrics/ParameterLists:
|
33
|
+
CountKeywordArgs:
|
34
|
+
Enabled: false
|
35
|
+
|
36
|
+
# Allow multiple exceptions
|
37
|
+
RSpec/MultipleExpectations:
|
38
|
+
Max: 4
|
39
|
+
|
40
|
+
RSpec/ExampleLength:
|
41
|
+
Max: 10 # Adjust this value as needed
|
data/.rubocop_todo.yml
CHANGED
@@ -6,34 +6,3 @@
|
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
|
-
# Offense count: 3
|
10
|
-
# Configuration parameters: EnforcedStyle, AllowedGems, Include.
|
11
|
-
# SupportedStyles: Gemfile, gems.rb, gemspec
|
12
|
-
# Include: **/*.gemspec, **/Gemfile, **/gems.rb
|
13
|
-
Gemspec/DevelopmentDependencies:
|
14
|
-
Exclude:
|
15
|
-
- 'weather_gov_api.gemspec'
|
16
|
-
|
17
|
-
# Offense count: 2
|
18
|
-
# Configuration parameters: EnforcedStyle.
|
19
|
-
# SupportedStyles: native, lf, crlf
|
20
|
-
Layout/EndOfLine:
|
21
|
-
Exclude:
|
22
|
-
- 'spec/weather_gov_api_spec.rb'
|
23
|
-
- 'weather_gov_api.gemspec'
|
24
|
-
|
25
|
-
# Offense count: 1
|
26
|
-
# Configuration parameters: Prefixes, AllowedPatterns.
|
27
|
-
# Prefixes: when, with, without
|
28
|
-
RSpec/ContextWording:
|
29
|
-
Exclude:
|
30
|
-
- 'spec/weather_gov_api/client_spec.rb'
|
31
|
-
|
32
|
-
# Offense count: 10
|
33
|
-
# Configuration parameters: CountAsOne.
|
34
|
-
RSpec/ExampleLength:
|
35
|
-
Max: 22
|
36
|
-
|
37
|
-
# Offense count: 5
|
38
|
-
RSpec/MultipleExpectations:
|
39
|
-
Max: 4
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.3.5
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## [0.3.0] - 2025-02-28
|
4
|
+
|
5
|
+
### Added
|
6
|
+
- Updated version handling adding WeatherGovApi::ApiError
|
7
|
+
- added .ruby-version
|
8
|
+
- added .vsc recommend plugins
|
9
|
+
|
10
|
+
### Fixed
|
11
|
+
- tackled rubocop_todo list
|
12
|
+
- fixed CodeQL rb/request-forgery error by ensuring same host
|
13
|
+
|
14
|
+
## [0.2.1] - 2025-02-21
|
15
|
+
|
16
|
+
### Added
|
17
|
+
- rubocop_todo
|
18
|
+
- simplecov and rubycritic
|
19
|
+
- updated CircleCI to require 90% overall and 80% on a file for test coverage
|
20
|
+
|
3
21
|
## [0.2.0] - 2025-02-19
|
4
22
|
|
5
23
|
### Added
|
@@ -9,7 +27,6 @@
|
|
9
27
|
## [0.1.0] - Initial Release
|
10
28
|
|
11
29
|
### Added
|
12
|
-
- Basic client implementation
|
13
30
|
- Basic client implementation for weather.gov API
|
14
31
|
- `points` method for fetching weather data by coordinates
|
15
32
|
- Error handling for:
|
data/README.md
CHANGED
@@ -76,9 +76,6 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/Jeffre
|
|
76
76
|
- [ ] Distributed rate limiting (Redis/DB-based)
|
77
77
|
- [ ] Add caching support for API responses
|
78
78
|
- [ ] Automate CHANGELOG.md updates during release process
|
79
|
-
- [ ] Configure Git repository settings:
|
80
|
-
- [ ] Disable direct commits to main branch
|
81
|
-
- [ ] Require passing CI builds for branch merges
|
82
79
|
|
83
80
|
## License
|
84
81
|
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module WeatherGovApi
|
4
|
+
# Custom error class to handle errors from the Weather.gov API
|
5
|
+
class ApiError < StandardError
|
6
|
+
attr_reader :type, :title, :status, :detail, :instance, :correlation_id, :parameter_errors
|
7
|
+
|
8
|
+
# rubocop:disable Metrics/ParameterLists
|
9
|
+
def initialize(type: nil, title: nil, status: nil, detail: nil, instance: nil, correlation_id: nil, message: nil,
|
10
|
+
parameter_errors: nil)
|
11
|
+
@type = type
|
12
|
+
@title = title
|
13
|
+
@status = status
|
14
|
+
@detail = detail
|
15
|
+
@instance = instance
|
16
|
+
@correlation_id = correlation_id
|
17
|
+
@parameter_errors = parameter_errors
|
18
|
+
@message = message
|
19
|
+
super(message || title || detail || "API request failed")
|
20
|
+
end
|
21
|
+
# rubocop:enable Metrics/ParameterLists
|
22
|
+
|
23
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
24
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
25
|
+
def to_s
|
26
|
+
return super unless super.empty?
|
27
|
+
|
28
|
+
parts = []
|
29
|
+
parts << "Type: #{@type}" if @type
|
30
|
+
parts << "Title: #{@title}" if @title
|
31
|
+
parts << "Status: #{@status}" if @status
|
32
|
+
parts << "Detail: #{@detail}" if @detail
|
33
|
+
parts << "Instance: #{@instance}" if @instance
|
34
|
+
parts << "CorrelationID: #{@correlation_id}" if @correlation_id
|
35
|
+
parts << "ParameterErros: #{@parameter_errors}" if @parameter_errors
|
36
|
+
parts.join(", ")
|
37
|
+
end
|
38
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
39
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
40
|
+
end
|
41
|
+
end
|
@@ -11,44 +11,53 @@ module WeatherGovApi
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def points(latitude:, longitude:)
|
14
|
-
validate_coordinates(latitude, longitude)
|
15
14
|
response = connection.get("/points/#{latitude},#{longitude}")
|
15
|
+
raise_api_error(response) unless response.success?
|
16
16
|
Response.new(response)
|
17
17
|
rescue Faraday::Error => e
|
18
|
-
raise
|
18
|
+
raise WeatherGovApi::ApiError.new(message: "API request failed: #{e.message}")
|
19
19
|
end
|
20
20
|
|
21
|
+
# rubocop:disable Metrics/MethodLength
|
21
22
|
def observation_stations(latitude:, longitude:)
|
22
23
|
points_response = points(latitude: latitude, longitude: longitude)
|
23
24
|
stations_url = points_response.data.dig("properties", "observationStations")
|
24
|
-
|
25
|
+
unless stations_url
|
26
|
+
raise WeatherGovApi::ApiError.new(message: "No observation stations URL found in points response")
|
27
|
+
end
|
28
|
+
|
29
|
+
stations_path = observation_stations_path(stations_url)
|
25
30
|
|
26
|
-
response = connection.get(
|
31
|
+
response = connection.get(stations_path)
|
32
|
+
raise_api_error(response) unless response.success?
|
27
33
|
Response.new(response)
|
28
34
|
rescue Faraday::Error => e
|
29
|
-
raise
|
35
|
+
raise WeatherGovApi::ApiError.new(message: "API request failed: #{e.message}")
|
30
36
|
end
|
37
|
+
# rubocop:enable Metrics/MethodLength
|
31
38
|
|
32
39
|
def current_weather(latitude:, longitude:)
|
33
40
|
stations_response = observation_stations(latitude: latitude, longitude: longitude)
|
34
41
|
station = stations_response.data.dig("features", 0)
|
35
|
-
raise
|
42
|
+
raise WeatherGovApi::ApiError.new(message: "No observation stations found") unless station
|
36
43
|
|
37
44
|
station_id = station.dig("properties", "stationIdentifier")
|
38
45
|
response = connection.get("/stations/#{station_id}/observations/latest")
|
46
|
+
raise_api_error(response) unless response.success?
|
39
47
|
Response.new(response)
|
40
48
|
rescue Faraday::Error => e
|
41
|
-
raise
|
49
|
+
raise WeatherGovApi::ApiError.new(message: "API request failed: #{e.message}")
|
42
50
|
end
|
43
51
|
|
44
52
|
private
|
45
53
|
|
46
|
-
def
|
47
|
-
|
48
|
-
|
49
|
-
|
54
|
+
def observation_stations_path(url)
|
55
|
+
uri = URI.parse(url)
|
56
|
+
unless uri.host == URI.parse(BASE_URL).host
|
57
|
+
raise WeatherGovApi::ApiError.new(message: "Invalid observation stations URL: #{url}")
|
58
|
+
end
|
50
59
|
|
51
|
-
|
60
|
+
uri.path
|
52
61
|
end
|
53
62
|
|
54
63
|
def connection
|
@@ -58,5 +67,26 @@ module WeatherGovApi
|
|
58
67
|
faraday.adapter Faraday.default_adapter
|
59
68
|
end
|
60
69
|
end
|
70
|
+
|
71
|
+
# rubocop:disable Metrics/MethodLength
|
72
|
+
def raise_api_error(response)
|
73
|
+
return if response.success?
|
74
|
+
|
75
|
+
begin
|
76
|
+
error_data = JSON.parse(response.body)
|
77
|
+
rescue JSON::ParserError
|
78
|
+
raise WeatherGovApi::ApiError.new(message: "API request failed with status #{response.status}\
|
79
|
+
but could not parse error response.")
|
80
|
+
end
|
81
|
+
|
82
|
+
raise WeatherGovApi::ApiError.new(
|
83
|
+
type: error_data["type"],
|
84
|
+
title: error_data["title"],
|
85
|
+
status: error_data["status"],
|
86
|
+
detail: error_data["detail"],
|
87
|
+
instance: error_data["instance"]
|
88
|
+
)
|
89
|
+
end
|
90
|
+
# rubocop:enable Metrics/MethodLength
|
61
91
|
end
|
62
92
|
end
|
data/lib/weather_gov_api.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: weather_gov_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JeffreyMPrice
|
8
|
-
autorequire:
|
9
8
|
bindir: exe
|
10
9
|
cert_chain: []
|
11
|
-
date: 2025-02-
|
10
|
+
date: 2025-02-28 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: faraday
|
@@ -24,48 +23,6 @@ dependencies:
|
|
24
23
|
- - "~>"
|
25
24
|
- !ruby/object:Gem::Version
|
26
25
|
version: '2.0'
|
27
|
-
- !ruby/object:Gem::Dependency
|
28
|
-
name: rspec
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
30
|
-
requirements:
|
31
|
-
- - "~>"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '3.0'
|
34
|
-
type: :development
|
35
|
-
prerelease: false
|
36
|
-
version_requirements: !ruby/object:Gem::Requirement
|
37
|
-
requirements:
|
38
|
-
- - "~>"
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '3.0'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: vcr
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '6.0'
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '6.0'
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: webmock
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '3.0'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '3.0'
|
69
26
|
description: |-
|
70
27
|
A Ruby gem for accessing weather data from the National Weather Service (weather.gov) API.
|
71
28
|
Provides a simple interface to fetch weather data for US locations.
|
@@ -78,12 +35,15 @@ files:
|
|
78
35
|
- ".rspec"
|
79
36
|
- ".rubocop.yml"
|
80
37
|
- ".rubocop_todo.yml"
|
38
|
+
- ".ruby-version"
|
39
|
+
- ".vscode/extensions.json"
|
81
40
|
- CHANGELOG.md
|
82
41
|
- CODE_OF_CONDUCT.md
|
83
42
|
- LICENSE.txt
|
84
43
|
- README.md
|
85
44
|
- Rakefile
|
86
45
|
- lib/weather_gov_api.rb
|
46
|
+
- lib/weather_gov_api/api_errors.rb
|
87
47
|
- lib/weather_gov_api/client.rb
|
88
48
|
- lib/weather_gov_api/response.rb
|
89
49
|
- lib/weather_gov_api/version.rb
|
@@ -97,7 +57,6 @@ metadata:
|
|
97
57
|
source_code_uri: https://github.com/JeffreyMPrice/weather_gov_api
|
98
58
|
changelog_uri: https://github.com/JeffreyMPrice/weather_gov_api/blob/main/CHANGELOG.md
|
99
59
|
rubygems_mfa_required: 'true'
|
100
|
-
post_install_message:
|
101
60
|
rdoc_options: []
|
102
61
|
require_paths:
|
103
62
|
- lib
|
@@ -112,8 +71,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
112
71
|
- !ruby/object:Gem::Version
|
113
72
|
version: '0'
|
114
73
|
requirements: []
|
115
|
-
rubygems_version: 3.5
|
116
|
-
signing_key:
|
74
|
+
rubygems_version: 3.6.5
|
117
75
|
specification_version: 4
|
118
76
|
summary: Ruby wrapper for the Weather.gov API
|
119
77
|
test_files: []
|