weather_gem_kg 0.31.0 → 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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 02a8cf12c9c8e11bd58b612f0a4cabfed6fcbaa89b0c4671b6bec3b45fa9fad7
4
- data.tar.gz: c0ff3ea5a27edf08750775ff1e596420d233774755731a993c3262bc8094e876
3
+ metadata.gz: f8433c3a942dcdc25b325c40624f7c2be90399e35e7d2c6b957bfb49ae121c04
4
+ data.tar.gz: ef5867ae1f04271203a5763cd12499f0ad7baef80d90f3c74def8ee30e0bfd35
5
5
  SHA512:
6
- metadata.gz: c654dd71e142f317e4404023567b70838180666c126463efca1303152a8c3ffe617aaa5e9f3817da1316e2a8f2d059cad27fc27da9c60fc1aba3b4642d943016
7
- data.tar.gz: 1d4815336c89bae37c21c4fc42c38790356a19a8d184ef67f3c98aabfce71f5650bdb4d2b206e5484921b812a68847f33373de8208a70ce744413a25cae6205a
6
+ metadata.gz: 593022b166c4032612c908615de4179c26f50f9b2f9b3638e3d815bdf403c7a346dfba45e47f190e93264fb344f4444b7bdb0d53db9a2b61efce71b4542eab59
7
+ data.tar.gz: 907b62f12190c808e4237b7dd65d2422ce40b7ec2f0f5a840c5d6bd401aa73bb915ad29ae89792c3b09149ae12b5ddac4bce8f36212c76f3d05896bb10bcbf2f
@@ -0,0 +1,22 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [master, main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+
12
+ steps:
13
+ - uses: actions/checkout@v4
14
+
15
+ - name: Set up Ruby
16
+ uses: ruby/setup-ruby@v1
17
+ with:
18
+ ruby-version: .ruby-version
19
+ bundler-cache: true
20
+
21
+ - name: Run specs
22
+ run: bundle exec rake
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ 4.0.6
data/Gemfile CHANGED
@@ -1,6 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
- # Specify your gem's dependencies in weather_gem_kg.gemspec
4
5
  gemspec
5
- gem "httparty"
6
- gem "geocoder"
data/Gemfile.lock CHANGED
@@ -1,45 +1,57 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- weather_gem_kg (0.30.0)
4
+ weather_gem_kg (1.0.0)
5
+ httparty (~> 0.24)
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
- diff-lcs (1.3)
10
- geocoder (1.5.1)
11
- httparty (0.17.0)
12
- mime-types (~> 3.0)
10
+ addressable (2.9.0)
11
+ public_suffix (>= 2.0.2, < 8.0)
12
+ bigdecimal (4.1.2)
13
+ crack (1.0.1)
14
+ bigdecimal
15
+ rexml
16
+ csv (3.3.5)
17
+ diff-lcs (1.6.2)
18
+ hashdiff (1.2.1)
19
+ httparty (0.24.2)
20
+ csv
21
+ mini_mime (>= 1.0.0)
13
22
  multi_xml (>= 0.5.2)
14
- mime-types (3.2.2)
15
- mime-types-data (~> 3.2015)
16
- mime-types-data (3.2019.0331)
17
- multi_xml (0.6.0)
18
- rake (10.5.0)
19
- rspec (3.8.0)
20
- rspec-core (~> 3.8.0)
21
- rspec-expectations (~> 3.8.0)
22
- rspec-mocks (~> 3.8.0)
23
- rspec-core (3.8.2)
24
- rspec-support (~> 3.8.0)
25
- rspec-expectations (3.8.4)
23
+ mini_mime (1.1.5)
24
+ multi_xml (0.9.1)
25
+ bigdecimal (>= 3.1, < 5)
26
+ public_suffix (7.0.5)
27
+ rake (13.4.2)
28
+ rexml (3.4.4)
29
+ rspec (3.13.2)
30
+ rspec-core (~> 3.13.0)
31
+ rspec-expectations (~> 3.13.0)
32
+ rspec-mocks (~> 3.13.0)
33
+ rspec-core (3.13.6)
34
+ rspec-support (~> 3.13.0)
35
+ rspec-expectations (3.13.5)
26
36
  diff-lcs (>= 1.2.0, < 2.0)
27
- rspec-support (~> 3.8.0)
28
- rspec-mocks (3.8.1)
37
+ rspec-support (~> 3.13.0)
38
+ rspec-mocks (3.13.8)
29
39
  diff-lcs (>= 1.2.0, < 2.0)
30
- rspec-support (~> 3.8.0)
31
- rspec-support (3.8.2)
40
+ rspec-support (~> 3.13.0)
41
+ rspec-support (3.13.7)
42
+ webmock (3.26.2)
43
+ addressable (>= 2.8.0)
44
+ crack (>= 0.3.2)
45
+ hashdiff (>= 0.4.0, < 2.0.0)
32
46
 
33
47
  PLATFORMS
34
48
  ruby
35
49
 
36
50
  DEPENDENCIES
37
- bundler (~> 2.0)
38
- geocoder
39
- httparty
40
- rake (~> 10.0)
51
+ rake (~> 13.0)
41
52
  rspec (~> 3.0)
42
53
  weather_gem_kg!
54
+ webmock (~> 3.0)
43
55
 
44
56
  BUNDLED WITH
45
- 2.0.2
57
+ 4.0.16
data/README.md CHANGED
@@ -1,43 +1,71 @@
1
1
  # WeatherGemKg
2
2
 
3
- 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/weather_gem_kg`. To experiment with that code, run `bin/console` for an interactive prompt.
4
-
5
- TODO: Delete this and the text above, and describe your gem
3
+ Ruby gem for daily city weather forecasts powered by [Open-Meteo](https://open-meteo.com/) (no API key required).
6
4
 
7
5
  ## Installation
8
6
 
9
7
  Add this line to your application's Gemfile:
10
8
 
11
9
  ```ruby
12
- gem 'weather_gem_kg'
10
+ gem "weather_gem_kg"
13
11
  ```
14
12
 
15
13
  And then execute:
16
14
 
17
- $ bundle
15
+ ```bash
16
+ bundle install
17
+ ```
18
+
19
+ Or install it yourself:
20
+
21
+ ```bash
22
+ gem install weather_gem_kg
23
+ ```
18
24
 
19
- Or install it yourself as:
25
+ ### Rails
20
26
 
21
- $ gem install weather_gem_kg
27
+ ```bash
28
+ rails generate weather_gem_kg:install
29
+ ```
22
30
 
23
31
  ## Usage
24
32
 
25
- TODO: Write usage instructions here
33
+ ```ruby
34
+ require "weather_gem_kg"
26
35
 
27
- ## Development
36
+ days = WeatherGemKg.forecast(city: "Bishkek", days: 3)
37
+
38
+ days.each do |day|
39
+ puts "#{day.date}: #{day.min_temp}–#{day.max_temp}°C, #{day.condition}"
40
+ end
41
+ ```
28
42
 
29
- After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
43
+ Each day is a `WeatherGemKg::ForecastDay` with `date`, `max_temp`, `min_temp`, and `condition`.
30
44
 
31
- 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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
45
+ ### Configuration
32
46
 
33
- ## Contributing
47
+ ```ruby
48
+ WeatherGemKg.configure do |config|
49
+ config.default_days = 3
50
+ # config.client = WeatherGemKg::Clients::OpenMeteo.new
51
+ end
52
+ ```
34
53
 
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/weather_gem_kg. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
54
+ ### Custom client
36
55
 
37
- ## License
56
+ Any object responding to `#forecast(city:, days:)` and returning an array of `ForecastDay` can be passed:
57
+
58
+ ```ruby
59
+ WeatherGemKg.forecast(city: "Bishkek", days: 1, client: MyClient.new)
60
+ ```
38
61
 
39
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
62
+ ## Development
40
63
 
41
- ## Code of Conduct
64
+ ```bash
65
+ bundle install
66
+ bundle exec rake
67
+ ```
68
+
69
+ ## License
42
70
 
43
- Everyone interacting in the WeatherGemKg project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/weather_gem_kg/blob/master/CODE_OF_CONDUCT.md).
71
+ MIT
@@ -0,0 +1,4 @@
1
+ WeatherGemKg.configure do |config|
2
+ # config.default_days = 3
3
+ # config.client = WeatherGemKg::Clients::OpenMeteo.new
4
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherGemKg
4
+ module Generators
5
+ class InstallGenerator < Rails::Generators::Base
6
+ source_root File.expand_path("../../templates", __FILE__)
7
+ desc "Creates WeatherGemKg initializer for your application"
8
+
9
+ def copy_initializer
10
+ template "weather_gem_kg_initializer.rb", "config/initializers/weather_gem_kg.rb"
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherGemKg
4
+ # Base contract for weather providers.
5
+ # Implementations must return an Array of ForecastDay.
6
+ class Client
7
+ def forecast(city:, days:)
8
+ raise NotImplementedError, "#{self.class}#forecast must be implemented"
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+ require "weather_gem_kg/client"
5
+ require "weather_gem_kg/errors"
6
+ require "weather_gem_kg/forecast_day"
7
+
8
+ module WeatherGemKg
9
+ module Clients
10
+ class OpenMeteo < Client
11
+ GEOCODING_URL = "https://geocoding-api.open-meteo.com/v1/search"
12
+ FORECAST_URL = "https://api.open-meteo.com/v1/forecast"
13
+
14
+ WEATHER_CODES = {
15
+ 0 => "Clear sky",
16
+ 1 => "Mainly clear",
17
+ 2 => "Partly cloudy",
18
+ 3 => "Overcast",
19
+ 45 => "Fog",
20
+ 48 => "Depositing rime fog",
21
+ 51 => "Light drizzle",
22
+ 53 => "Moderate drizzle",
23
+ 55 => "Dense drizzle",
24
+ 56 => "Light freezing drizzle",
25
+ 57 => "Dense freezing drizzle",
26
+ 61 => "Slight rain",
27
+ 63 => "Moderate rain",
28
+ 65 => "Heavy rain",
29
+ 66 => "Light freezing rain",
30
+ 67 => "Heavy freezing rain",
31
+ 71 => "Slight snow",
32
+ 73 => "Moderate snow",
33
+ 75 => "Heavy snow",
34
+ 77 => "Snow grains",
35
+ 80 => "Slight rain showers",
36
+ 81 => "Moderate rain showers",
37
+ 82 => "Violent rain showers",
38
+ 85 => "Slight snow showers",
39
+ 86 => "Heavy snow showers",
40
+ 95 => "Thunderstorm",
41
+ 96 => "Thunderstorm with slight hail",
42
+ 99 => "Thunderstorm with heavy hail"
43
+ }.freeze
44
+
45
+ def forecast(city:, days:)
46
+ days = Integer(days)
47
+ raise InvalidArgumentError, "days must be between 1 and 16" unless days.between?(1, 16)
48
+
49
+ location = geocode(city)
50
+ payload = fetch_forecast(location.fetch(:latitude), location.fetch(:longitude), days)
51
+ parse_forecast(payload)
52
+ end
53
+
54
+ private
55
+
56
+ def geocode(city)
57
+ response = HTTParty.get(GEOCODING_URL, query: { name: city, count: 1 })
58
+ raise RequestError, "Geocoding failed (HTTP #{response.code})" unless response.success?
59
+
60
+ result = response.parsed_response&.dig("results", 0)
61
+ raise LocationNotFoundError, "No location found for #{city.inspect}" unless result
62
+
63
+ {
64
+ latitude: result.fetch("latitude"),
65
+ longitude: result.fetch("longitude")
66
+ }
67
+ end
68
+
69
+ def fetch_forecast(latitude, longitude, days)
70
+ response = HTTParty.get(
71
+ FORECAST_URL,
72
+ query: {
73
+ latitude: latitude,
74
+ longitude: longitude,
75
+ daily: "weather_code,temperature_2m_max,temperature_2m_min",
76
+ forecast_days: days,
77
+ timezone: "auto"
78
+ }
79
+ )
80
+ raise RequestError, "Forecast request failed (HTTP #{response.code})" unless response.success?
81
+
82
+ response.parsed_response
83
+ end
84
+
85
+ def parse_forecast(payload)
86
+ daily = payload.fetch("daily")
87
+ times = daily.fetch("time")
88
+ max_temps = daily.fetch("temperature_2m_max")
89
+ min_temps = daily.fetch("temperature_2m_min")
90
+ codes = daily.fetch("weather_code")
91
+
92
+ times.each_index.map do |index|
93
+ ForecastDay.new(
94
+ date: times[index],
95
+ max_temp: max_temps[index],
96
+ min_temp: min_temps[index],
97
+ condition: WEATHER_CODES.fetch(codes[index], "Unknown")
98
+ )
99
+ end
100
+ end
101
+ end
102
+ end
103
+ end
@@ -1,17 +1,33 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WeatherGemKg
2
- module Configuration
3
- Config = Struct.new :api_key_apixu, :api_key_dark
4
+ class << self
5
+ attr_writer :configuration
6
+ end
4
7
 
5
- class << self
6
- attr_accessor :api_key_apixu, :api_key_dark
7
- end
8
+ def self.configuration
9
+ @configuration ||= Configuration.new
10
+ end
11
+
12
+ def self.configure
13
+ yield(configuration) if block_given?
14
+ end
15
+
16
+ def self.reset_configuration!
17
+ @configuration = Configuration.new
18
+ end
19
+
20
+ class Configuration
21
+ attr_writer :client
22
+ attr_accessor :default_days
8
23
 
9
- def self.configure(&config_block)
10
- config_block.call config
24
+ def initialize
25
+ @default_days = 1
26
+ @client = nil
11
27
  end
12
28
 
13
- def self.config
14
- @config ||= Config.new
29
+ def client
30
+ @client ||= Clients::OpenMeteo.new
15
31
  end
16
32
  end
17
33
  end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherGemKg
4
+ class Error < StandardError; end
5
+ class LocationNotFoundError < Error; end
6
+ class RequestError < Error; end
7
+ class InvalidArgumentError < Error; end
8
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherGemKg
4
+ ForecastDay = Data.define(:date, :max_temp, :min_temp, :condition)
5
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module WeatherGemKg
2
- VERSION = "0.31.0"
4
+ VERSION = "1.0.0"
3
5
  end
@@ -1,14 +1,17 @@
1
- require "httparty"
1
+ # frozen_string_literal: true
2
+
2
3
  require "weather_gem_kg/version"
3
- require "weather_gem_kg/generator"
4
+ require "weather_gem_kg/errors"
5
+ require "weather_gem_kg/forecast_day"
6
+ require "weather_gem_kg/client"
4
7
  require "weather_gem_kg/config"
8
+ require "weather_gem_kg/clients/open_meteo"
5
9
 
6
10
  module WeatherGemKg
7
- extend Configuration
8
- end
11
+ def self.forecast(city:, days: nil, client: nil)
12
+ raise InvalidArgumentError, "city is required" if city.nil? || city.to_s.strip.empty?
9
13
 
10
- # weather1 = WeatherGemKg::Generator.new('Bishkek', 1, WeatherGemKg::Clients::Apixu.new)
11
- # weather1.generate_me
12
- #
13
- # weather2 = WeatherGemKg::Generator.new('Bishkek', 1, WeatherGemKg::Clients::DarkSky.new)
14
- # puts weather2.generate_me
14
+ days ||= configuration.default_days
15
+ (client || configuration.client).forecast(city: city, days: days)
16
+ end
17
+ end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  lib = File.expand_path("lib", __dir__)
2
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
5
  require "weather_gem_kg/version"
@@ -8,27 +10,21 @@ Gem::Specification.new do |spec|
8
10
  spec.authors = ["Edilbek"]
9
11
  spec.email = ["edil.talantbekov@gmail.com"]
10
12
 
11
- spec.summary = %q{Write a short summary, because RubyGems requires one.}
12
- spec.description = %q{Write a longer description or delete this line.}
13
- # spec.homepage = "Put your gem's website or public repo URL here."
13
+ spec.summary = "Daily weather forecasts via Open-Meteo"
14
+ spec.description = "A small Ruby gem that fetches daily city forecasts using the free Open-Meteo API."
14
15
  spec.license = "MIT"
16
+ spec.required_ruby_version = ">= 3.2"
15
17
 
16
- # spec.metadata["allowed_push_host"] = "Set to 'http://mygemserver.com'"
17
-
18
- # spec.metadata["homepage_uri"] = spec.homepage
19
- # spec.metadata["source_code_uri"] = "Put your gem's public repo URL here."
20
- # spec.metadata["changelog_uri"] = "Put your gem's CHANGELOG.md URL here."
21
-
22
- # Specify which files should be added to the gem when it is released.
23
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
18
+ spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
25
19
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
20
  end
27
21
  spec.bindir = "exe"
28
22
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
29
23
  spec.require_paths = ["lib"]
30
24
 
31
- spec.add_development_dependency "bundler", "~> 2.0"
32
- spec.add_development_dependency "rake", "~> 10.0"
25
+ spec.add_dependency "httparty", "~> 0.24"
26
+
27
+ spec.add_development_dependency "rake", "~> 13.0"
33
28
  spec.add_development_dependency "rspec", "~> 3.0"
29
+ spec.add_development_dependency "webmock", "~> 3.0"
34
30
  end
metadata CHANGED
@@ -1,43 +1,42 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather_gem_kg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.31.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edilbek
8
- autorequire:
9
8
  bindir: exe
10
9
  cert_chain: []
11
- date: 2019-07-15 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
- name: bundler
13
+ name: httparty
15
14
  requirement: !ruby/object:Gem::Requirement
16
15
  requirements:
17
16
  - - "~>"
18
17
  - !ruby/object:Gem::Version
19
- version: '2.0'
20
- type: :development
18
+ version: '0.24'
19
+ type: :runtime
21
20
  prerelease: false
22
21
  version_requirements: !ruby/object:Gem::Requirement
23
22
  requirements:
24
23
  - - "~>"
25
24
  - !ruby/object:Gem::Version
26
- version: '2.0'
25
+ version: '0.24'
27
26
  - !ruby/object:Gem::Dependency
28
27
  name: rake
29
28
  requirement: !ruby/object:Gem::Requirement
30
29
  requirements:
31
30
  - - "~>"
32
31
  - !ruby/object:Gem::Version
33
- version: '10.0'
32
+ version: '13.0'
34
33
  type: :development
35
34
  prerelease: false
36
35
  version_requirements: !ruby/object:Gem::Requirement
37
36
  requirements:
38
37
  - - "~>"
39
38
  - !ruby/object:Gem::Version
40
- version: '10.0'
39
+ version: '13.0'
41
40
  - !ruby/object:Gem::Dependency
42
41
  name: rspec
43
42
  requirement: !ruby/object:Gem::Requirement
@@ -52,16 +51,32 @@ dependencies:
52
51
  - - "~>"
53
52
  - !ruby/object:Gem::Version
54
53
  version: '3.0'
55
- description: Write a longer description or delete this line.
54
+ - !ruby/object:Gem::Dependency
55
+ name: webmock
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '3.0'
61
+ type: :development
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '3.0'
68
+ description: A small Ruby gem that fetches daily city forecasts using the free Open-Meteo
69
+ API.
56
70
  email:
57
71
  - edil.talantbekov@gmail.com
58
72
  executables: []
59
73
  extensions: []
60
74
  extra_rdoc_files: []
61
75
  files:
76
+ - ".github/workflows/ci.yml"
62
77
  - ".gitignore"
63
78
  - ".rspec"
64
- - ".travis.yml"
79
+ - ".ruby-version"
65
80
  - CODE_OF_CONDUCT.md
66
81
  - Gemfile
67
82
  - Gemfile.lock
@@ -70,18 +85,19 @@ files:
70
85
  - Rakefile
71
86
  - bin/console
72
87
  - bin/setup
88
+ - lib/generators/templates/weather_gem_kg_initializer.rb
89
+ - lib/generators/weather_gem_kg/install_generator.rb
73
90
  - lib/weather_gem_kg.rb
74
- - lib/weather_gem_kg/clients/apixu.rb
75
- - lib/weather_gem_kg/clients/dark_sky.rb
91
+ - lib/weather_gem_kg/client.rb
92
+ - lib/weather_gem_kg/clients/open_meteo.rb
76
93
  - lib/weather_gem_kg/config.rb
77
- - lib/weather_gem_kg/generator.rb
94
+ - lib/weather_gem_kg/errors.rb
95
+ - lib/weather_gem_kg/forecast_day.rb
78
96
  - lib/weather_gem_kg/version.rb
79
97
  - weather_gem_kg.gemspec
80
- homepage:
81
98
  licenses:
82
99
  - MIT
83
100
  metadata: {}
84
- post_install_message:
85
101
  rdoc_options: []
86
102
  require_paths:
87
103
  - lib
@@ -89,15 +105,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
105
  requirements:
90
106
  - - ">="
91
107
  - !ruby/object:Gem::Version
92
- version: '0'
108
+ version: '3.2'
93
109
  required_rubygems_version: !ruby/object:Gem::Requirement
94
110
  requirements:
95
111
  - - ">="
96
112
  - !ruby/object:Gem::Version
97
113
  version: '0'
98
114
  requirements: []
99
- rubygems_version: 3.0.4
100
- signing_key:
115
+ rubygems_version: 4.0.16
101
116
  specification_version: 4
102
- summary: Write a short summary, because RubyGems requires one.
117
+ summary: Daily weather forecasts via Open-Meteo
103
118
  test_files: []
data/.travis.yml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- sudo: false
3
- language: ruby
4
- cache: bundler
5
- rvm:
6
- - 2.4.1
7
- before_install: gem install bundler -v 2.0.2
@@ -1,30 +0,0 @@
1
- require_relative '../config'
2
-
3
- module WeatherGemKg
4
- module Clients
5
- class Apixu
6
- API_KEY = WeatherGemKg::Configuration.config.api_key_apixu
7
-
8
- def initialize
9
- @base_url = "http://api.apixu.com/v1/forecast.json?key=#{API_KEY}"
10
- end
11
-
12
- def get_weather(city, days)
13
- @data = get_weather_info(city, days)
14
- @data.dig('forecast', 'forecastday').map do |f|
15
- day = f.dig('day')
16
- {
17
- date: Time.at(f['date_epoch']).ctime.slice(0, 10),
18
- max_temp: day['maxtemp_c'],
19
- min_temp: day['mintemp_c'],
20
- condition: day.dig('condition', 'text')
21
- }
22
- end
23
- end
24
-
25
- def get_weather_info(city, days)
26
- HTTParty.get("#{@base_url}&q=#{city}&days=#{days}")
27
- end
28
- end
29
- end
30
- end
@@ -1,37 +0,0 @@
1
- require "geocoder"
2
- require_relative '../config'
3
-
4
- module WeatherGemKg
5
- module Clients
6
- class DarkSky
7
- API_KEY = WeatherGemKg::Configuration.config.api_key_dark
8
-
9
- def initialize
10
- @base_url = "https://api.darksky.net/forecast/#{API_KEY}"
11
- end
12
-
13
- def get_weather(city, days)
14
- @data = get_weather_info(city, days)
15
-
16
- @data.dig("daily", "data")[0...days].map do |f|
17
- {
18
- date: Time.at(f['time']).ctime.slice(0, 10),
19
- max_temp: ((f["temperatureHigh"] - 32) * 5 / 9).round(1),
20
- min_temp: ((f["temperatureLow"] - 32) * 5 / 9).round(1),
21
- condition: f["summary"]
22
- }
23
- end
24
- end
25
-
26
- def get_weather_info(city, days)
27
- coordinates = get_city_coordinates(city)
28
-
29
- HTTParty.get("#{@base_url}/#{coordinates}")
30
- end
31
-
32
- def get_city_coordinates(city)
33
- Geocoder.search("#{city}").first.coordinates.map(&:inspect).join(',')
34
- end
35
- end
36
- end
37
- end
@@ -1,18 +0,0 @@
1
- require "weather_gem_kg/clients/apixu"
2
- require "weather_gem_kg/clients/dark_sky"
3
-
4
- module WeatherGemKg
5
- class Generator
6
- attr_reader :city, :day, :generator
7
-
8
- def initialize(city, day, generator)
9
- @city = city
10
- @day = day
11
- @generator = generator
12
- end
13
-
14
- def generate_me
15
- generator.get_weather(city, day)
16
- end
17
- end
18
- end