lex-openweathermap 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f7e44130bc8bdcff5b7cff2b9afe9c4330bb12dea501e09af997daa09f019e02
4
+ data.tar.gz: 4aff7f0484c01db30aed84d95c841eeb1d1f7f77cc984e6c3a090ed92de237c0
5
+ SHA512:
6
+ metadata.gz: 6017569cd33b3f2c2fedf9fa2e5b6f936fd4eecf2a533ff0338de33ca5a61faa5a9afdacbfdee8e093aa97350cd70a20d589628353a45f35b6f38312153c30dd
7
+ data.tar.gz: db47217bc77f5e8a83e141f0abc1706cd7adac8b7264ccb1c5d2592a5f88f54dbc5d21c57b5c270f98e3849a98eedb0640e78fe89d38949819b53390eee70f49
@@ -0,0 +1,16 @@
1
+ name: CI
2
+ on:
3
+ push:
4
+ branches: [origin]
5
+ pull_request:
6
+
7
+ jobs:
8
+ ci:
9
+ uses: LegionIO/.github/.github/workflows/ci.yml@main
10
+
11
+ release:
12
+ needs: ci
13
+ if: github.event_name == 'push' && github.ref == 'refs/heads/origin'
14
+ uses: LegionIO/.github/.github/workflows/release.yml@main
15
+ secrets:
16
+ rubygems-api-key: ${{ secrets.RUBYGEMS_API_KEY }}
data/.gitignore ADDED
@@ -0,0 +1,12 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,53 @@
1
+ AllCops:
2
+ TargetRubyVersion: 3.4
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+
6
+ Layout/LineLength:
7
+ Max: 160
8
+
9
+ Layout/SpaceAroundEqualsInParameterDefault:
10
+ EnforcedStyle: space
11
+
12
+ Layout/HashAlignment:
13
+ EnforcedHashRocketStyle: table
14
+ EnforcedColonStyle: table
15
+
16
+ Metrics/MethodLength:
17
+ Max: 50
18
+
19
+ Metrics/ClassLength:
20
+ Max: 1500
21
+
22
+ Metrics/ModuleLength:
23
+ Max: 1500
24
+
25
+ Metrics/BlockLength:
26
+ Max: 40
27
+ Exclude:
28
+ - 'spec/**/*'
29
+
30
+ Metrics/ParameterLists:
31
+ Max: 10
32
+
33
+ Metrics/AbcSize:
34
+ Max: 60
35
+
36
+ Metrics/CyclomaticComplexity:
37
+ Max: 15
38
+
39
+ Metrics/PerceivedComplexity:
40
+ Max: 17
41
+
42
+ Style/Documentation:
43
+ Enabled: false
44
+
45
+ Style/SymbolArray:
46
+ Enabled: true
47
+
48
+ Style/FrozenStringLiteralComment:
49
+ Enabled: true
50
+ EnforcedStyle: always
51
+
52
+ Naming/FileName:
53
+ Enabled: false
data/CHANGELOG.md ADDED
@@ -0,0 +1,10 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2026-03-21
4
+
5
+ ### Added
6
+ - Initial release
7
+ - `Helpers::Client` — Faraday connection builder targeting OpenWeatherMap API v2.5 with `appid` query param auth and configurable `units`
8
+ - `Runners::Weather` — current_weather (by city or lat/lon), current_weather_by_id
9
+ - `Runners::Forecast` — five_day_forecast, hourly_forecast
10
+ - Standalone `Client` class for use outside the Legion framework
data/Gemfile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ source 'https://rubygems.org'
4
+
5
+ gemspec
6
+
7
+ gem 'rake', '~> 12.0'
8
+ gem 'rspec', '~> 3.0'
9
+ gem 'rspec_junit_formatter'
10
+ gem 'rubocop'
11
+ gem 'rubocop-rspec'
12
+ gem 'webmock'
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ # lex-openweathermap
2
+
3
+ LegionIO extension for OpenWeatherMap integration via the OpenWeatherMap REST API v2.5.
4
+
5
+ ## Installation
6
+
7
+ Add to your Gemfile:
8
+
9
+ ```ruby
10
+ gem 'lex-openweathermap'
11
+ ```
12
+
13
+ ## Standalone Usage
14
+
15
+ ```ruby
16
+ require 'legion/extensions/openweathermap'
17
+
18
+ client = Legion::Extensions::Openweathermap::Client.new(api_key: 'your-api-key')
19
+
20
+ # Current weather by city
21
+ client.current_weather(city: 'London')
22
+
23
+ # Current weather by coordinates
24
+ client.current_weather(lat: 44.98, lon: -93.27)
25
+
26
+ # Current weather by city ID
27
+ client.current_weather_by_id(city_id: 2_643_743)
28
+
29
+ # 5-day forecast
30
+ client.five_day_forecast(city: 'Berlin')
31
+
32
+ # Hourly forecast (cnt controls number of timestamps, default 8)
33
+ client.hourly_forecast(city: 'New York', cnt: 4)
34
+ ```
35
+
36
+ ## Authentication
37
+
38
+ OpenWeatherMap uses an API key passed as the `appid` query parameter. Obtain a free key at: https://openweathermap.org/api
39
+
40
+ ## Units
41
+
42
+ Supported `units` values: `metric` (default), `imperial`, `standard`.
43
+
44
+ ## License
45
+
46
+ MIT
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'lib/legion/extensions/openweathermap/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = 'lex-openweathermap'
7
+ spec.version = Legion::Extensions::Openweathermap::VERSION
8
+ spec.authors = ['Esity']
9
+ spec.email = ['matthewdiverson@gmail.com']
10
+
11
+ spec.summary = 'LEX::Openweathermap'
12
+ spec.description = 'Used to connect Legion to OpenWeatherMap'
13
+ spec.homepage = 'https://github.com/LegionIO/lex-openweathermap'
14
+ spec.license = 'MIT'
15
+ spec.required_ruby_version = '>= 3.4'
16
+
17
+ spec.metadata['homepage_uri'] = spec.homepage
18
+ spec.metadata['source_code_uri'] = 'https://github.com/LegionIO/lex-openweathermap'
19
+ spec.metadata['changelog_uri'] = 'https://github.com/LegionIO/lex-openweathermap/blob/main/CHANGELOG.md'
20
+ spec.metadata['rubygems_mfa_required'] = 'true'
21
+
22
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
23
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
24
+ end
25
+ spec.bindir = 'exe'
26
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
+ spec.require_paths = ['lib']
28
+
29
+ spec.add_dependency 'faraday', '~> 2.0'
30
+ end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'helpers/client'
4
+ require_relative 'runners/weather'
5
+ require_relative 'runners/forecast'
6
+
7
+ module Legion
8
+ module Extensions
9
+ module Openweathermap
10
+ class Client
11
+ include Helpers::Client
12
+ include Runners::Weather
13
+ include Runners::Forecast
14
+
15
+ attr_reader :opts
16
+
17
+ def initialize(api_key:, units: 'metric', **extra)
18
+ @opts = { api_key: api_key, units: units, **extra }
19
+ end
20
+
21
+ def settings
22
+ { options: @opts }
23
+ end
24
+
25
+ def connection(**override)
26
+ super(**@opts, **override)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'faraday'
4
+
5
+ module Legion
6
+ module Extensions
7
+ module Openweathermap
8
+ module Helpers
9
+ module Client
10
+ BASE_URL = 'https://api.openweathermap.org/data/2.5'
11
+
12
+ def connection(api_key: nil, units: 'metric', **_opts)
13
+ Faraday.new(url: BASE_URL) do |conn|
14
+ conn.request :json
15
+ conn.response :json, content_type: /\bjson$/
16
+ conn.params['appid'] = api_key if api_key
17
+ conn.params['units'] = units
18
+ conn.adapter Faraday.default_adapter
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Openweathermap
6
+ module Runners
7
+ module Forecast
8
+ def five_day_forecast(city:, **)
9
+ resp = connection(**).get('/forecast', { q: city })
10
+ { forecast: resp.body }
11
+ end
12
+
13
+ def hourly_forecast(city:, cnt: 8, **)
14
+ resp = connection(**).get('/forecast', { q: city, cnt: cnt })
15
+ { forecast: resp.body }
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Openweathermap
6
+ module Runners
7
+ module Weather
8
+ def current_weather(city: nil, lat: nil, lon: nil, **)
9
+ params = {}
10
+ if city
11
+ params[:q] = city
12
+ elsif lat && lon
13
+ params[:lat] = lat
14
+ params[:lon] = lon
15
+ end
16
+ resp = connection(**).get('/weather', params)
17
+ { weather: resp.body }
18
+ end
19
+
20
+ def current_weather_by_id(city_id:, **)
21
+ resp = connection(**).get('/weather', { id: city_id })
22
+ { weather: resp.body }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Legion
4
+ module Extensions
5
+ module Openweathermap
6
+ VERSION = '0.1.1'
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'legion/extensions/openweathermap/version'
4
+ require 'legion/extensions/openweathermap/helpers/client'
5
+ require 'legion/extensions/openweathermap/runners/weather'
6
+ require 'legion/extensions/openweathermap/runners/forecast'
7
+ require 'legion/extensions/openweathermap/client'
8
+
9
+ module Legion
10
+ module Extensions
11
+ module Openweathermap
12
+ extend Legion::Extensions::Core if Legion::Extensions.const_defined? :Core
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lex-openweathermap
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Esity
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.0'
26
+ description: Used to connect Legion to OpenWeatherMap
27
+ email:
28
+ - matthewdiverson@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - ".github/workflows/ci.yml"
34
+ - ".gitignore"
35
+ - ".rspec"
36
+ - ".rubocop.yml"
37
+ - CHANGELOG.md
38
+ - Gemfile
39
+ - README.md
40
+ - lex-openweathermap.gemspec
41
+ - lib/legion/extensions/openweathermap.rb
42
+ - lib/legion/extensions/openweathermap/client.rb
43
+ - lib/legion/extensions/openweathermap/helpers/client.rb
44
+ - lib/legion/extensions/openweathermap/runners/forecast.rb
45
+ - lib/legion/extensions/openweathermap/runners/weather.rb
46
+ - lib/legion/extensions/openweathermap/version.rb
47
+ homepage: https://github.com/LegionIO/lex-openweathermap
48
+ licenses:
49
+ - MIT
50
+ metadata:
51
+ homepage_uri: https://github.com/LegionIO/lex-openweathermap
52
+ source_code_uri: https://github.com/LegionIO/lex-openweathermap
53
+ changelog_uri: https://github.com/LegionIO/lex-openweathermap/blob/main/CHANGELOG.md
54
+ rubygems_mfa_required: 'true'
55
+ rdoc_options: []
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: '3.4'
63
+ required_rubygems_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ requirements: []
69
+ rubygems_version: 3.6.9
70
+ specification_version: 4
71
+ summary: LEX::Openweathermap
72
+ test_files: []