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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3cbf1f318dd5763110dce0a345e139c73827192731bb3087a8648c16c640301f
4
- data.tar.gz: 90781055cf6d34a5231c83113df7436f7bdd9ae1fc68db2b395ca7d45f28a728
3
+ metadata.gz: d55c2880714ebc0d6758364d0468849046d37782f387a188da0970db68606234
4
+ data.tar.gz: 6a15f0f7d028d963bdefac066c523c8e8fc546b7b0cd90ee90e2c2b10ca17d67
5
5
  SHA512:
6
- metadata.gz: 37d1d54eb12765488ab4116d3e07dc7843383e73939de3d62453da17280c9f7e04be8f42180a794b1187cdbae9d349718e7440e2ed8938a9febb2a8de5fcc945
7
- data.tar.gz: 1f55cd0187d370d47b8d3dd2e5ea581e1faf9395033e32dee1365728b4ede3168cc8599820798982359e946cfdb26b93112440a1f8ea478673db9333c61a6ad4
6
+ metadata.gz: 67930c8bc15ff5d0bd6580e5c340f72bfba7cb8f0e39ca23114c939d187871da8d701a08fcab392b6a5668d04ffa3c91ffc4112145888f6fd979ed92484ecdeb
7
+ data.tar.gz: 8bd17749b1a8460ecd6e7bd2405fd3cb88b59ab886bb3e2467e36fd8a3a0a185deecd7183025d232f1cbd04d386137c16e412f1341f35a9e2e054f4b3b710c86
data/.gitignore CHANGED
@@ -15,7 +15,10 @@
15
15
  .rspec
16
16
  .rubocop.yml
17
17
  .ruby-version
18
- ArseniysWeatherApp.gemspec
18
+ arseniys_weather_app.gemspec
19
19
  Gemfile
20
20
  Gemfile.lock
21
21
  Rakefile
22
+ *.gem
23
+ test.rb
24
+ *.json
data/README.md CHANGED
@@ -1,15 +1,15 @@
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
 
9
9
  Add this line to your application's Gemfile:
10
10
 
11
11
  ```ruby
12
- gem 'ArseniysWeatherApp'
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
- 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.
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
@@ -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.1"
5
5
  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.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 00:00:00.000000000 Z
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/ArseniysWeatherApp.rb
40
- - lib/ArseniysWeatherApp/version.rb
41
- homepage: https://github.com/Supernich/ArseniysWeatherApp
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/ArseniysWeatherApp
46
- source_code_uri: https://github.com/Supernich/ArseniysWeatherApp
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:
@@ -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