ArseniysWeatherApp 0.1.3 → 0.1.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -7
- data/exe/arseniys_weather_app +10 -0
- data/exe/location_avg_temp_threedays +7 -0
- data/exe/location_avg_temp_today +7 -0
- data/exe/my_weather_threedays +7 -0
- data/exe/my_weather_today +7 -0
- data/lib/ArseniysWeatherApp/version.rb +1 -1
- data/lib/ArseniysWeatherApp.rb +69 -77
- metadata +13 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6c7b486feee9a4fc832cb2fa78b8a2647d16709bf0fb357d5ff535f45619628f
|
4
|
+
data.tar.gz: 034deb0b4180118f9d6248b69e5d6e264acc0005228924c4f66601fa5db40ca9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 85090f66d32734b18e95f73c33e399b7e34ab7a7b01a0af0899a06fc266b483d7f0d713cfa7f94196f3da481b508211b66aed3c21705c1ecc9b1d1e7b7a693e1
|
7
|
+
data.tar.gz: 211c1bcf5232b4c4b9006f96f5aac89ddb6dbf515348250db215a7f1a9c5c7a67f2ce0ca7d82f5bcc456bab3d7be397c34474872245e7eaf3072601e471250cd
|
data/.gitignore
CHANGED
@@ -7,18 +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
|
-
arseniys_weather_app.gemspec
|
19
|
-
Gemfile
|
20
|
-
Gemfile.lock
|
21
|
-
Rakefile
|
22
15
|
*.gem
|
23
16
|
test.rb
|
24
17
|
*.json
|
@@ -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
|
data/lib/ArseniysWeatherApp.rb
CHANGED
@@ -7,126 +7,118 @@ require "geokit"
|
|
7
7
|
module ArseniysWeatherApp
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
|
-
class
|
11
|
-
def
|
12
|
-
|
13
|
-
|
14
|
-
configure_geokit
|
15
|
-
@spb_location = { lat: 59.9573887, lon: 30.3430287 }
|
16
|
-
end
|
17
|
-
|
18
|
-
def weather_from_json
|
19
|
-
JSON.parse(File.read("WeatherForecasts.json"))
|
20
|
-
end
|
21
|
-
|
22
|
-
def weather_json(location: [59.9573887, 30.3430287],
|
23
|
-
lang: "ru_RU", forecasts: 7,
|
24
|
-
hours: false, extra: false)
|
25
|
-
attach_yandex_api if @yandex_api.nil?
|
10
|
+
class Requests
|
11
|
+
def self.weather_json(location: [59.9573887, 30.3430287],
|
12
|
+
lang: "ru_RU", forecasts: 7,
|
13
|
+
hours: false, extra: false)
|
26
14
|
url = "https://api.weather.yandex.ru/v2/forecast"
|
27
15
|
params = { "lat" => location[0], "lon" => location[1],
|
28
16
|
"lang" => lang, "limit" => forecasts,
|
29
17
|
"hours" => hours, "extra" => extra }
|
30
|
-
header = { "X-Yandex-API-Key" =>
|
18
|
+
header = { "X-Yandex-API-Key" => "01cafac0-8fd8-48ca-956a-f442580428a0" }
|
31
19
|
response = Faraday.get(url, params, header)
|
32
20
|
JSON.parse(response.body)
|
33
21
|
end
|
34
22
|
|
35
|
-
def
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
def cleanup_avg_temperature(parts)
|
40
|
-
parts.delete_if { |key| %w[day_short night_short].include?(key) }
|
41
|
-
{ morning: parts["morning"]["temp_avg"], day: parts["day"]["temp_avg"],
|
42
|
-
evening: parts["evening"]["temp_avg"], night: parts["night"]["temp_avg"] }
|
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"]
|
43
27
|
end
|
28
|
+
end
|
44
29
|
|
45
|
-
|
46
|
-
|
30
|
+
class GeoInfo
|
31
|
+
def self.spb_location
|
32
|
+
{ lat: 59.9573887, lon: 30.3430287 }
|
47
33
|
end
|
48
34
|
|
49
|
-
def
|
50
|
-
|
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 }
|
51
39
|
end
|
40
|
+
end
|
52
41
|
|
53
|
-
|
54
|
-
|
42
|
+
class Forecast
|
43
|
+
def initialize(lat:, lon:)
|
44
|
+
@location = [lat, lon]
|
55
45
|
end
|
56
46
|
|
57
|
-
def
|
58
|
-
|
47
|
+
def today
|
48
|
+
Requests.weather_json(location: @location, forecasts: 1, hours: true)
|
59
49
|
end
|
60
50
|
|
61
|
-
def
|
62
|
-
|
51
|
+
def three_days
|
52
|
+
Requests.weather_json(location: @location, forecasts: 3, hours: true)
|
63
53
|
end
|
54
|
+
end
|
64
55
|
|
65
|
-
|
66
|
-
|
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
|
67
68
|
end
|
68
69
|
|
69
|
-
def
|
70
|
-
|
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
|
71
75
|
end
|
72
76
|
|
73
|
-
def
|
74
|
-
|
77
|
+
def self.fact(parts)
|
78
|
+
parts["fact"]["temp"]
|
75
79
|
end
|
80
|
+
end
|
76
81
|
|
77
|
-
|
78
|
-
|
79
|
-
|
82
|
+
class LocationWeatherForecast
|
83
|
+
def initialize(lat:, lon:)
|
84
|
+
@forecast = Forecast.new(lat: lat, lon: lon)
|
80
85
|
end
|
81
86
|
|
82
|
-
def
|
83
|
-
|
87
|
+
def fact
|
88
|
+
Cleaners.fact(@forecast.today)
|
84
89
|
end
|
85
90
|
|
86
|
-
def
|
87
|
-
|
88
|
-
lat_lon_fact(lat: location[0], lon: location[1])
|
91
|
+
def today_avg_temperature
|
92
|
+
Cleaners.avg_temperature(@forecast.today)
|
89
93
|
end
|
90
94
|
|
91
|
-
def
|
92
|
-
|
95
|
+
def three_days_avg_temperature
|
96
|
+
Cleaners.avg_temperature(@forecast.three_days)
|
93
97
|
end
|
94
98
|
|
95
|
-
|
96
|
-
|
97
|
-
def attach_yandex_api
|
98
|
-
return unless @yandex_api.nil?
|
99
|
-
|
100
|
-
url = "https://obscure-temple-73986.herokuapp.com/"
|
101
|
-
response = Faraday.get(url, { "weather" => "yes" })
|
102
|
-
@yandex_api = JSON.parse(response.body)["message"]
|
99
|
+
def today_forecast_json
|
100
|
+
Cleaners.forecast_json(@forecast.today)
|
103
101
|
end
|
104
102
|
|
105
|
-
def
|
106
|
-
|
103
|
+
def three_days_forecast_json
|
104
|
+
Cleaners.forecast_json(@forecast.three_days)
|
107
105
|
end
|
106
|
+
end
|
108
107
|
|
109
|
-
|
110
|
-
|
111
|
-
|
108
|
+
class MyWeatherForecast
|
109
|
+
def initialize
|
110
|
+
location = GeoInfo.location_by_ip
|
111
|
+
@location_weather = LocationWeatherForecast.new(lat: location[:lat], lon: location[:lon])
|
112
112
|
end
|
113
113
|
|
114
|
-
def
|
115
|
-
|
114
|
+
def method_missing(method_name)
|
115
|
+
raise NoMethodError unless @location_weather.methods.include?(method_name)
|
116
116
|
|
117
|
-
|
118
|
-
response = Faraday.get(url, { "get_ip" => "yes" })
|
119
|
-
@ip_stack_api = JSON.parse(response.body)["ip_stack_api"]
|
117
|
+
@location_weather.method(method_name).call
|
120
118
|
end
|
121
119
|
|
122
|
-
def
|
123
|
-
|
124
|
-
response = Faraday.get(url, { "get_ip" => "yes" })
|
125
|
-
JSON.parse(response.body)["ip_addr"]
|
120
|
+
def respond_to_missing?(method_name, include_private = false)
|
121
|
+
@location_weather.methods.include?(method_name)
|
126
122
|
end
|
127
123
|
end
|
128
124
|
end
|
129
|
-
|
130
|
-
# f = File.new("WeatherForecasts.json", "w")
|
131
|
-
# f.write(Application.new.weather_json(forecasts: 1).to_json)
|
132
|
-
# f.close
|
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.
|
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-
|
11
|
+
date: 2021-09-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -43,13 +43,23 @@ description: |-
|
|
43
43
|
tells you what weather is right now
|
44
44
|
email:
|
45
45
|
- supernich19@gmail.com
|
46
|
-
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
|
47
52
|
extensions: []
|
48
53
|
extra_rdoc_files: []
|
49
54
|
files:
|
50
55
|
- ".gitignore"
|
51
56
|
- LICENSE.txt
|
52
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
|
53
63
|
- lib/ArseniysWeatherApp.rb
|
54
64
|
- lib/ArseniysWeatherApp/version.rb
|
55
65
|
homepage: https://github.com/Supernich/ArseniysWeatherApp
|