ArseniysWeatherApp 0.1.0 → 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 +4 -4
- data/.gitignore +4 -1
- data/README.md +13 -15
- data/lib/arseniys_weather_app.rb +132 -0
- data/lib/{ArseniysWeatherApp → arseniys_weather_app}/version.rb +1 -1
- metadata +21 -7
- data/lib/ArseniysWeatherApp.rb +0 -48
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d55c2880714ebc0d6758364d0468849046d37782f387a188da0970db68606234
|
4
|
+
data.tar.gz: 6a15f0f7d028d963bdefac066c523c8e8fc546b7b0cd90ee90e2c2b10ca17d67
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 67930c8bc15ff5d0bd6580e5c340f72bfba7cb8f0e39ca23114c939d187871da8d701a08fcab392b6a5668d04ffa3c91ffc4112145888f6fd979ed92484ecdeb
|
7
|
+
data.tar.gz: 8bd17749b1a8460ecd6e7bd2405fd3cb88b59ab886bb3e2467e36fd8a3a0a185deecd7183025d232f1cbd04d386137c16e412f1341f35a9e2e054f4b3b710c86
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -1,15 +1,15 @@
|
|
1
|
-
#
|
1
|
+
# Arseniys Weather App
|
2
2
|
|
3
|
-
Welcome
|
3
|
+
Welcome!
|
4
4
|
|
5
|
-
|
5
|
+
This gem will work until 11 sep 2021, after that date yandex api key expires.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
9
|
Add this line to your application's Gemfile:
|
10
10
|
|
11
11
|
```ruby
|
12
|
-
gem '
|
12
|
+
gem 'arseniys_weather_app'
|
13
13
|
```
|
14
14
|
|
15
15
|
And then execute:
|
@@ -22,17 +22,15 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
## Usage
|
24
24
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ArseniysWeatherApp.
|
25
|
+
Use
|
26
|
+
```ruby
|
27
|
+
ArseniysWeatherApp.attach_yandex_api
|
28
|
+
```
|
29
|
+
to attach yandex weather api key and then use
|
30
|
+
```ruby
|
31
|
+
ArseniysWeatherApp.spb_weather
|
32
|
+
```
|
33
|
+
to see weather forecasts for today.
|
36
34
|
|
37
35
|
## License
|
38
36
|
|
@@ -0,0 +1,132 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "arseniys_weather_app/version"
|
4
|
+
require "faraday"
|
5
|
+
require "geokit"
|
6
|
+
|
7
|
+
module ArseniysWeatherApp
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class Weather
|
11
|
+
def initialize
|
12
|
+
attach_yandex_api
|
13
|
+
attach_ip_stack_api
|
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?
|
26
|
+
url = "https://api.weather.yandex.ru/v2/forecast"
|
27
|
+
params = { "lat" => location[0], "lon" => location[1],
|
28
|
+
"lang" => lang, "limit" => forecasts,
|
29
|
+
"hours" => hours, "extra" => extra }
|
30
|
+
header = { "X-Yandex-API-Key" => @yandex_api }
|
31
|
+
response = Faraday.get(url, params, header)
|
32
|
+
JSON.parse(response.body)
|
33
|
+
end
|
34
|
+
|
35
|
+
def cleanup_forecast(parts)
|
36
|
+
parts["forecasts"][0]["parts"].delete_if { |key| %w[day_short night_short].include?(key) }
|
37
|
+
end
|
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"] }
|
43
|
+
end
|
44
|
+
|
45
|
+
def lat_lon_today_forecast(lat:, lon:)
|
46
|
+
cleanup_forecast(weather_json(location: [lat, lon], forecasts: 1, hours: true))
|
47
|
+
end
|
48
|
+
|
49
|
+
def lat_lon_today_avg_temperature(lat:, lon:)
|
50
|
+
cleanup_avg_temperature(lat_lon_today_forecast(lat: lat, lon: lon))
|
51
|
+
end
|
52
|
+
|
53
|
+
def lat_lon_fact(lat:, lon:)
|
54
|
+
weather_json(location: [lat, lon], forecasts: 1)["fact"]
|
55
|
+
end
|
56
|
+
|
57
|
+
def lat_lon_fact_temperature(lat:, lon:)
|
58
|
+
lat_lon_fact(lat: lat, lon: lon)["temp"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def spb_today_forecast
|
62
|
+
lat_lon_today_forecast(lat: @spb_location[:lat], lon: @spb_location[:lon])
|
63
|
+
end
|
64
|
+
|
65
|
+
def spb_today_avg_temperature
|
66
|
+
cleanup_avg_temperature(spb_today_forecast)
|
67
|
+
end
|
68
|
+
|
69
|
+
def spb_fact
|
70
|
+
lat_lon_fact(lat: @spb_location[:lat], lon: @spb_location[:lon])
|
71
|
+
end
|
72
|
+
|
73
|
+
def spb_fact_temperature
|
74
|
+
spb_fact["temp"]
|
75
|
+
end
|
76
|
+
|
77
|
+
def my_today_forecast
|
78
|
+
location = acquire_location
|
79
|
+
lat_lon_today_forecast(lat: location[0], lon: location[1])
|
80
|
+
end
|
81
|
+
|
82
|
+
def my_today_avg_temperature
|
83
|
+
cleanup_avg_temperature(my_today_forecast)
|
84
|
+
end
|
85
|
+
|
86
|
+
def my_fact
|
87
|
+
location = acquire_location
|
88
|
+
lat_lon_fact(lat: location[0], lon: location[1])
|
89
|
+
end
|
90
|
+
|
91
|
+
def my_fact_temperature
|
92
|
+
my_fact["temp"]
|
93
|
+
end
|
94
|
+
|
95
|
+
private
|
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"]
|
103
|
+
end
|
104
|
+
|
105
|
+
def configure_geokit
|
106
|
+
Geokit::Geocoders::IpstackGeocoder.api_key = @ip_stack_api
|
107
|
+
end
|
108
|
+
|
109
|
+
def acquire_location
|
110
|
+
geokit = Geokit::Geocoders::IpstackGeocoder.geocode(acquire_ip_addr)
|
111
|
+
[geokit.lat, geokit.longitude]
|
112
|
+
end
|
113
|
+
|
114
|
+
def attach_ip_stack_api
|
115
|
+
return unless @ip_stack_api.nil?
|
116
|
+
|
117
|
+
url = "https://obscure-temple-73986.herokuapp.com/"
|
118
|
+
response = Faraday.get(url, { "get_ip" => "yes" })
|
119
|
+
@ip_stack_api = JSON.parse(response.body)["ip_stack_api"]
|
120
|
+
end
|
121
|
+
|
122
|
+
def acquire_ip_addr
|
123
|
+
url = "https://obscure-temple-73986.herokuapp.com/"
|
124
|
+
response = Faraday.get(url, { "get_ip" => "yes" })
|
125
|
+
JSON.parse(response.body)["ip_addr"]
|
126
|
+
end
|
127
|
+
end
|
128
|
+
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.1
|
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
|
+
date: 2021-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -24,6 +24,20 @@ 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
|
@@ -36,14 +50,14 @@ files:
|
|
36
50
|
- ".gitignore"
|
37
51
|
- LICENSE.txt
|
38
52
|
- README.md
|
39
|
-
- lib/
|
40
|
-
- lib/
|
41
|
-
homepage: https://github.com/Supernich/
|
53
|
+
- lib/arseniys_weather_app.rb
|
54
|
+
- lib/arseniys_weather_app/version.rb
|
55
|
+
homepage: https://github.com/Supernich/arseniys_weather_app
|
42
56
|
licenses:
|
43
57
|
- MIT
|
44
58
|
metadata:
|
45
|
-
homepage_uri: https://github.com/Supernich/
|
46
|
-
source_code_uri: https://github.com/Supernich/
|
59
|
+
homepage_uri: https://github.com/Supernich/arseniys_weather_app
|
60
|
+
source_code_uri: https://github.com/Supernich/arseniys_weather_app
|
47
61
|
post_install_message:
|
48
62
|
rdoc_options: []
|
49
63
|
require_paths:
|
data/lib/ArseniysWeatherApp.rb
DELETED
@@ -1,48 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative "ArseniysWeatherApp/version"
|
4
|
-
require "faraday"
|
5
|
-
require "json"
|
6
|
-
|
7
|
-
module ArseniysWeatherApp
|
8
|
-
class Error < StandardError; end
|
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"]
|
14
|
-
end
|
15
|
-
|
16
|
-
|
17
|
-
|
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")
|
24
|
-
end
|
25
|
-
|
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)
|
41
|
-
end
|
42
|
-
|
43
|
-
# f = File.new("WeatherForecast.json", "w")
|
44
|
-
# f.write(parse.to_json)
|
45
|
-
# f.close
|
46
|
-
# str = JSON.parse(File.read("WeatherForecast.json"))
|
47
|
-
|
48
|
-
end
|