ArseniysWeatherApp 0.1.0 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cbf1f318dd5763110dce0a345e139c73827192731bb3087a8648c16c640301f
4
- data.tar.gz: 90781055cf6d34a5231c83113df7436f7bdd9ae1fc68db2b395ca7d45f28a728
3
+ metadata.gz: 6c7b486feee9a4fc832cb2fa78b8a2647d16709bf0fb357d5ff535f45619628f
4
+ data.tar.gz: 034deb0b4180118f9d6248b69e5d6e264acc0005228924c4f66601fa5db40ca9
5
5
  SHA512:
6
- metadata.gz: 37d1d54eb12765488ab4116d3e07dc7843383e73939de3d62453da17280c9f7e04be8f42180a794b1187cdbae9d349718e7440e2ed8938a9febb2a8de5fcc945
7
- data.tar.gz: 1f55cd0187d370d47b8d3dd2e5ea581e1faf9395033e32dee1365728b4ede3168cc8599820798982359e946cfdb26b93112440a1f8ea478673db9333c61a6ad4
6
+ metadata.gz: 85090f66d32734b18e95f73c33e399b7e34ab7a7b01a0af0899a06fc266b483d7f0d713cfa7f94196f3da481b508211b66aed3c21705c1ecc9b1d1e7b7a693e1
7
+ data.tar.gz: 211c1bcf5232b4c4b9006f96f5aac89ddb6dbf515348250db215a7f1a9c5c7a67f2ce0ca7d82f5bcc456bab3d7be397c34474872245e7eaf3072601e471250cd
data/.gitignore CHANGED
@@ -7,15 +7,11 @@
7
7
  /spec/reports/
8
8
  /tmp/
9
9
  /spec/
10
- /bin/
11
10
  /.idea/
12
11
 
13
12
  # rspec failure tracking
14
13
  .rspec_status
15
14
  .rspec
16
- .rubocop.yml
17
- .ruby-version
18
- ArseniysWeatherApp.gemspec
19
- Gemfile
20
- Gemfile.lock
21
- Rakefile
15
+ *.gem
16
+ test.rb
17
+ *.json
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # ArseniysWeatherApp
1
+ # Arseniys Weather App
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/ArseniysWeatherApp`. To experiment with that code, run `bin/console` for an interactive prompt.
3
+ Welcome!
4
4
 
5
- TODO: Delete this and the text above, and describe your gem
5
+ This gem will work until 11 sep 2021, after that date yandex api key expires.
6
6
 
7
7
  ## Installation
8
8
 
@@ -20,19 +20,18 @@ Or install it yourself as:
20
20
 
21
21
  $ gem install ArseniysWeatherApp
22
22
 
23
- ## Usage
24
-
25
- TODO: Write usage instructions here
26
-
27
- ## Development
28
-
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.
30
-
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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
-
33
- ## Contributing
34
-
35
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ArseniysWeatherApp.
23
+ ## QUICKSTART
24
+ ```ruby
25
+ $ gem install ArseniysWeatherApp
26
+
27
+ irb:001:0> require "ArseniysWeatherApp"
28
+ => true
29
+ irb:002:0> weather = ArseniysWeatherApp::Weather.new
30
+ irb:003:0> weather.my_fact_temperature
31
+ => 16
32
+ irb:004:0> weather.spb_today_avg_temperature
33
+ => {:morning=>19, :day=>23, :evening=>20, :night=>16}
34
+ ```
36
35
 
37
36
  ## License
38
37
 
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ArseniysWeatherApp"
5
+
6
+ my_weather = ["Run my_weather_today to see your weather forecast for today",
7
+ "Run my_weather_threedays to see your weather forecast for 3 days",
8
+ "Run location_avg_temp_today desired_latitude desired_longitude to see this location weather forecast for today",
9
+ "Run location_avg_temp_threedays desired_latitude desired_longitude to see this location weather forecast for 3 days"]
10
+ puts my_weather
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ArseniysWeatherApp"
5
+
6
+ forecast = ArseniysWeatherApp::LocationWeatherForecast.new(lat: ARGV[0], lon: ARGV[1])
7
+ puts forecast.today_avg_temperature
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ArseniysWeatherApp"
5
+
6
+ forecast = ArseniysWeatherApp::LocationWeatherForecast.new(lat: ARGV[0], lon: ARGV[1])
7
+ puts forecast.three_days_avg_temperature
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ArseniysWeatherApp"
5
+
6
+ forecast = ArseniysWeatherApp::MyWeatherForecast.new
7
+ puts forecast.three_days_avg_temperature
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "ArseniysWeatherApp"
5
+
6
+ forecast = ArseniysWeatherApp::MyWeatherForecast.new
7
+ puts forecast.today_avg_temperature
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ArseniysWeatherApp
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.4"
5
5
  end
@@ -2,47 +2,123 @@
2
2
 
3
3
  require_relative "ArseniysWeatherApp/version"
4
4
  require "faraday"
5
- require "json"
5
+ require "geokit"
6
6
 
7
7
  module ArseniysWeatherApp
8
8
  class Error < StandardError; end
9
9
 
10
- def self.attach_yandex_api
11
- url = "https://obscure-temple-73986.herokuapp.com/"
12
- response = Faraday.get(url, { "weather" => "yes" })
13
- @yandex_api = JSON.parse(response.body)["message"]
10
+ class Requests
11
+ def self.weather_json(location: [59.9573887, 30.3430287],
12
+ lang: "ru_RU", forecasts: 7,
13
+ hours: false, extra: false)
14
+ url = "https://api.weather.yandex.ru/v2/forecast"
15
+ params = { "lat" => location[0], "lon" => location[1],
16
+ "lang" => lang, "limit" => forecasts,
17
+ "hours" => hours, "extra" => extra }
18
+ header = { "X-Yandex-API-Key" => "01cafac0-8fd8-48ca-956a-f442580428a0" }
19
+ response = Faraday.get(url, params, header)
20
+ JSON.parse(response.body)
21
+ end
22
+
23
+ def self.ip_addr
24
+ url = "https://obscure-temple-73986.herokuapp.com/"
25
+ response = Faraday.get(url, { "get_ip" => "yes" })
26
+ JSON.parse(response.body)["ip_addr"]
27
+ end
28
+ end
29
+
30
+ class GeoInfo
31
+ def self.spb_location
32
+ { lat: 59.9573887, lon: 30.3430287 }
33
+ end
34
+
35
+ def self.location_by_ip
36
+ Geokit::Geocoders::IpstackGeocoder.api_key = "a1b3e41fa2284fb6fd4db50b8629e884"
37
+ geokit = Geokit::Geocoders::IpstackGeocoder.geocode(Requests.ip_addr)
38
+ { lat: geokit.lat, lon: geokit.longitude }
39
+ end
40
+ end
41
+
42
+ class Forecast
43
+ def initialize(lat:, lon:)
44
+ @location = [lat, lon]
45
+ end
46
+
47
+ def today
48
+ Requests.weather_json(location: @location, forecasts: 1, hours: true)
49
+ end
50
+
51
+ def three_days
52
+ Requests.weather_json(location: @location, forecasts: 3, hours: true)
53
+ end
14
54
  end
15
55
 
56
+ class Cleaners
57
+ def self.avg_temperature(forecast)
58
+ forecast = forecast_json(forecast)
59
+ avg_temperature = {}
60
+ day_name = ["today", "tomorrow", "day after tomorrow"]
61
+ forecast["forecasts"].each_with_index do |day, i|
62
+ avg_temperature[day_name[i]] = { morning: day["parts"]["morning"]["temp_avg"],
63
+ day: day["parts"]["day"]["temp_avg"],
64
+ evening: day["parts"]["evening"]["temp_avg"],
65
+ night: day["parts"]["night"]["temp_avg"] }
66
+ end
67
+ avg_temperature
68
+ end
16
69
 
70
+ def self.forecast_json(parts)
71
+ parts["forecasts"].each do |day|
72
+ day["parts"].delete_if { |key| %w[day_short night_short].include?(key) }
73
+ end
74
+ parts
75
+ end
17
76
 
18
- def self.spb_weather
19
- str = weather_json(location: [60, 30])
20
- puts("Today's night average temperature: #{str["forecasts"][0]["parts"]["night"]["temp_avg"]}C")
21
- puts("Today's morning average temperature: #{str["forecasts"][0]["parts"]["morning"]["temp_avg"]}C")
22
- puts("Today's day average temperature: #{str["forecasts"][0]["parts"]["day"]["temp_avg"]}C")
23
- puts("Today's evening average temperature: #{str["forecasts"][0]["parts"]["evening"]["temp_avg"]}C")
77
+ def self.fact(parts)
78
+ parts["fact"]["temp"]
79
+ end
24
80
  end
25
81
 
26
- def self.weather_json(location: [59.9573887, 30.3430287],
27
- lang: "ru_RU",
28
- forecasts: 7,
29
- hours: false,
30
- extra: false)
31
- url = "https://api.weather.yandex.ru/v2/forecast"
32
- params = { "lat" => location[0],
33
- "lon" => location[1],
34
- "lang" => lang,
35
- "limit" => forecasts,
36
- "hours" => hours,
37
- "extra" => extra }
38
- header = { "X-Yandex-API-Key" => @yandex_api }
39
- response = Faraday.get(url, params, header)
40
- JSON.parse(response.body)
82
+ class LocationWeatherForecast
83
+ def initialize(lat:, lon:)
84
+ @forecast = Forecast.new(lat: lat, lon: lon)
85
+ end
86
+
87
+ def fact
88
+ Cleaners.fact(@forecast.today)
89
+ end
90
+
91
+ def today_avg_temperature
92
+ Cleaners.avg_temperature(@forecast.today)
93
+ end
94
+
95
+ def three_days_avg_temperature
96
+ Cleaners.avg_temperature(@forecast.three_days)
97
+ end
98
+
99
+ def today_forecast_json
100
+ Cleaners.forecast_json(@forecast.today)
101
+ end
102
+
103
+ def three_days_forecast_json
104
+ Cleaners.forecast_json(@forecast.three_days)
105
+ end
41
106
  end
42
107
 
43
- # f = File.new("WeatherForecast.json", "w")
44
- # f.write(parse.to_json)
45
- # f.close
46
- # str = JSON.parse(File.read("WeatherForecast.json"))
108
+ class MyWeatherForecast
109
+ def initialize
110
+ location = GeoInfo.location_by_ip
111
+ @location_weather = LocationWeatherForecast.new(lat: location[:lat], lon: location[:lon])
112
+ end
113
+
114
+ def method_missing(method_name)
115
+ raise NoMethodError unless @location_weather.methods.include?(method_name)
47
116
 
117
+ @location_weather.method(method_name).call
118
+ end
119
+
120
+ def respond_to_missing?(method_name, include_private = false)
121
+ @location_weather.methods.include?(method_name)
122
+ end
123
+ end
48
124
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ArseniysWeatherApp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arseniy Chirkov
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-08-11 00:00:00.000000000 Z
11
+ date: 2021-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday
@@ -24,18 +24,42 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: geokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.13.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.13.1
27
41
  description: |-
28
42
  This gem is searches your location and based on your location
29
43
  tells you what weather is right now
30
44
  email:
31
45
  - supernich19@gmail.com
32
- executables: []
46
+ executables:
47
+ - arseniys_weather_app
48
+ - location_avg_temp_threedays
49
+ - location_avg_temp_today
50
+ - my_weather_threedays
51
+ - my_weather_today
33
52
  extensions: []
34
53
  extra_rdoc_files: []
35
54
  files:
36
55
  - ".gitignore"
37
56
  - LICENSE.txt
38
57
  - README.md
58
+ - exe/arseniys_weather_app
59
+ - exe/location_avg_temp_threedays
60
+ - exe/location_avg_temp_today
61
+ - exe/my_weather_threedays
62
+ - exe/my_weather_today
39
63
  - lib/ArseniysWeatherApp.rb
40
64
  - lib/ArseniysWeatherApp/version.rb
41
65
  homepage: https://github.com/Supernich/ArseniysWeatherApp