weather_by_dcq 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: d08f10a58793762e49be0189e9156a437dd65b2bb76ef39c8a95154a22a6aec1
4
+ data.tar.gz: 55d1ea3f0e923f1c772bc83a7984d9938e6a01b69605d1039a3ee913ac472487
5
+ SHA512:
6
+ metadata.gz: 73361a224c4ee57bd293a53902def76b60a4923a9261473470c3b5a5060af1cc0d666423d471a3a4baeb8e039e42265b59141ceb0566fd6773dc09b0c8226c75
7
+ data.tar.gz: 63cf14675d329c3b2211742db3d85e0c7e39ad56e17598c30fd8c77f7f8a56e40dc0fc26a868ac27bdad106f69c07d7c9401ab3ea55c0e4325c60bc7d4ea4d5a
data/.gitignore ADDED
@@ -0,0 +1,279 @@
1
+ # Created by https://www.gitignore.io/api/windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
2
+ # Edit at https://www.gitignore.io/?templates=windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
3
+
4
+ ### JetBrains+all ###
5
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
6
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
7
+
8
+ # User-specific stuff
9
+ .idea/**/workspace.xml
10
+ .idea/**/tasks.xml
11
+ .idea/**/usage.statistics.xml
12
+ .idea/**/dictionaries
13
+ .idea/**/shelf
14
+
15
+ # Generated files
16
+ .idea/**/contentModel.xml
17
+
18
+ # Sensitive or high-churn files
19
+ .idea/**/dataSources/
20
+ .idea/**/dataSources.ids
21
+ .idea/**/dataSources.local.xml
22
+ .idea/**/sqlDataSources.xml
23
+ .idea/**/dynamic.xml
24
+ .idea/**/uiDesigner.xml
25
+ .idea/**/dbnavigator.xml
26
+
27
+ # Gradle
28
+ .idea/**/gradle.xml
29
+ .idea/**/libraries
30
+
31
+ # Gradle and Maven with auto-import
32
+ # When using Gradle or Maven with auto-import, you should exclude module files,
33
+ # since they will be recreated, and may cause churn. Uncomment if using
34
+ # auto-import.
35
+ # .idea/modules.xml
36
+ # .idea/*.iml
37
+ # .idea/modules
38
+ # *.iml
39
+ # *.ipr
40
+
41
+ # CMake
42
+ cmake-build-*/
43
+
44
+ # Mongo Explorer plugin
45
+ .idea/**/mongoSettings.xml
46
+
47
+ # File-based project format
48
+ *.iws
49
+
50
+ # IntelliJ
51
+ out/
52
+
53
+ # mpeltonen/sbt-idea plugin
54
+ .idea_modules/
55
+
56
+ # JIRA plugin
57
+ atlassian-ide-plugin.xml
58
+
59
+ # Cursive Clojure plugin
60
+ .idea/replstate.xml
61
+
62
+ # Crashlytics plugin (for Android Studio and IntelliJ)
63
+ com_crashlytics_export_strings.xml
64
+ crashlytics.properties
65
+ crashlytics-build.properties
66
+ fabric.properties
67
+
68
+ # Editor-based Rest Client
69
+ .idea/httpRequests
70
+
71
+ # Android studio 3.1+ serialized cache file
72
+ .idea/caches/build_file_checksums.ser
73
+
74
+ ### JetBrains+all Patch ###
75
+ # Ignores the whole .idea folder and all .iml files
76
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
77
+
78
+ .idea/
79
+
80
+ # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
81
+
82
+ *.iml
83
+ modules.xml
84
+ .idea/misc.xml
85
+ *.ipr
86
+
87
+ # Sonarlint plugin
88
+ .idea/sonarlint
89
+
90
+ ### Linux ###
91
+ *~
92
+
93
+ # temporary files which can be created if a process still has a handle open of a deleted file
94
+ .fuse_hidden*
95
+
96
+ # KDE directory preferences
97
+ .directory
98
+
99
+ # Linux trash folder which might appear on any partition or disk
100
+ .Trash-*
101
+
102
+ # .nfs files are created when an open file is removed but is still being accessed
103
+ .nfs*
104
+
105
+ ### macOS ###
106
+ # General
107
+ .DS_Store
108
+ .AppleDouble
109
+ .LSOverride
110
+
111
+ # Icon must end with two \r
112
+ Icon
113
+
114
+ # Thumbnails
115
+ ._*
116
+
117
+ # Files that might appear in the root of a volume
118
+ .DocumentRevisions-V100
119
+ .fseventsd
120
+ .Spotlight-V100
121
+ .TemporaryItems
122
+ .Trashes
123
+ .VolumeIcon.icns
124
+ .com.apple.timemachine.donotpresent
125
+
126
+ # Directories potentially created on remote AFP share
127
+ .AppleDB
128
+ .AppleDesktop
129
+ Network Trash Folder
130
+ Temporary Items
131
+ .apdisk
132
+
133
+ ### Ruby ###
134
+ *.gem
135
+ *.rbc
136
+ .rspec_status
137
+ /.config
138
+ /coverage/
139
+ /InstalledFiles
140
+ /pkg/
141
+ /spec/reports/
142
+ /spec/examples.txt
143
+ /test/tmp/
144
+ /test/version_tmp/
145
+ /tmp/
146
+
147
+ # Used by dotenv library to load environment variables.
148
+ # .env
149
+
150
+ # Ignore Byebug command history file.
151
+ .byebug_history
152
+
153
+ ## Specific to RubyMotion:
154
+ .dat*
155
+ .repl_history
156
+ build/
157
+ *.bridgesupport
158
+ build-iPhoneOS/
159
+ build-iPhoneSimulator/
160
+
161
+ ## Specific to RubyMotion (use of CocoaPods):
162
+ #
163
+ # We recommend against adding the Pods directory to your .gitignore. However
164
+ # you should judge for yourself, the pros and cons are mentioned at:
165
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
166
+ # vendor/Pods/
167
+
168
+ ## Documentation cache and generated files:
169
+ /.yardoc/
170
+ /_yardoc/
171
+ /doc/
172
+ /rdoc/
173
+
174
+ ## Environment normalization:
175
+ /.bundle/
176
+ /vendor/bundle
177
+ /lib/bundler/man/
178
+
179
+ # for a library or gem, you might want to ignore these files since the code is
180
+ # intended to run in multiple environments; otherwise, check them in:
181
+ # Gemfile.lock
182
+ # .ruby-version
183
+ # .ruby-gemset
184
+
185
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
186
+ .rvmrc
187
+
188
+ ### RubyMine+all ###
189
+ # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
190
+ # Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
191
+
192
+ # User-specific stuff
193
+
194
+ # Generated files
195
+
196
+ # Sensitive or high-churn files
197
+
198
+ # Gradle
199
+
200
+ # Gradle and Maven with auto-import
201
+ # When using Gradle or Maven with auto-import, you should exclude module files,
202
+ # since they will be recreated, and may cause churn. Uncomment if using
203
+ # auto-import.
204
+ # .idea/modules.xml
205
+ # .idea/*.iml
206
+ # .idea/modules
207
+ # *.iml
208
+ # *.ipr
209
+
210
+ # CMake
211
+
212
+ # Mongo Explorer plugin
213
+
214
+ # File-based project format
215
+
216
+ # IntelliJ
217
+
218
+ # mpeltonen/sbt-idea plugin
219
+
220
+ # JIRA plugin
221
+
222
+ # Cursive Clojure plugin
223
+
224
+ # Crashlytics plugin (for Android Studio and IntelliJ)
225
+
226
+ # Editor-based Rest Client
227
+
228
+ # Android studio 3.1+ serialized cache file
229
+
230
+ ### RubyMine+all Patch ###
231
+ # Ignores the whole .idea folder and all .iml files
232
+ # See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
233
+
234
+
235
+ # Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
236
+
237
+
238
+ # Sonarlint plugin
239
+
240
+ ### VisualStudioCode ###
241
+ .vscode/*
242
+ !.vscode/settings.json
243
+ !.vscode/tasks.json
244
+ !.vscode/launch.json
245
+ !.vscode/extensions.json
246
+
247
+ ### VisualStudioCode Patch ###
248
+ # Ignore all local history of files
249
+ .history
250
+
251
+ ### Windows ###
252
+ # Windows thumbnail cache files
253
+ Thumbs.db
254
+ Thumbs.db:encryptable
255
+ ehthumbs.db
256
+ ehthumbs_vista.db
257
+
258
+ # Dump file
259
+ *.stackdump
260
+
261
+ # Folder config file
262
+ [Dd]esktop.ini
263
+
264
+ # Recycle Bin used on file shares
265
+ $RECYCLE.BIN/
266
+
267
+ # Windows Installer files
268
+ *.cab
269
+ *.msi
270
+ *.msix
271
+ *.msm
272
+ *.msp
273
+
274
+ # Windows shortcuts
275
+ *.lnk
276
+
277
+ # End of https://www.gitignore.io/api/windows,macos,linux,visualstudiocode,jetbrains+all,ruby,rubymine+all
278
+
279
+ .env
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at YOUR@EMAIL.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [https://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: https://contributor-covenant.org
74
+ [version]: https://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in weather_by_dcq.gemspec
4
+ gemspec
5
+
6
+ gem "rake", "~> 12.0"
7
+ gem 'httparty'
8
+ gem 'json'
9
+ gem 'pry'
10
+ gem 'tty-spinner'
11
+ gem 'tty-table'
12
+ gem 'forecast_io'
13
+ gem 'geocoder'
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 YOUR NAME
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,44 @@
1
+ # WeatherByDcq
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_by_dcq`. 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
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'weather_by_dcq'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle install
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install weather_by_dcq
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. 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 tags, 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]/weather_by_dcq. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/weather_by_dcq/blob/master/CODE_OF_CONDUCT.md).
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
41
+
42
+ ## Code of Conduct
43
+
44
+ Everyone interacting in the WeatherByDcq project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/weather_by_dcq/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "weather_by_dcq"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,5 @@
1
+
2
+ require 'bundler/setup'
3
+ require 'weather_ferret'
4
+
5
+ WeatherFerret::CLI.new.call
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative '../lib/weather_by_dcq/version'
4
+ require_relative '../lib/weather_by_dcq/request'
5
+ require_relative '../lib/weather_by_dcq/forecast'
6
+ require_relative '../lib/weather_by_dcq/view'
7
+
8
+ weatherbydcq = WeatherByDcq::View.new
9
+
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'tty-spinner'
4
+ require 'tty-table'
5
+ require 'pry'
6
+
7
+ class WeatherByDcq::Forecast
8
+ def self.fetch_curr_data(key_data)
9
+ @forecast['currently'][key_data]
10
+ end
11
+
12
+ def self.fetch_data(num, key_data)
13
+ @forecast['daily']['data'][num][key_data]
14
+ end
15
+
16
+ def self.fetch_sun_data(num, key_data)
17
+ time = Time.at(@forecast['daily']['data'][num][key_data])
18
+ time.strftime('%I:%M ')
19
+ end
20
+
21
+ def self.display_curr_table(location)
22
+ ## Add TTY Spinner
23
+ spinner = TTY::Spinner.new('[:spinner] Fetch from API', format: :bouncing_ball, clear: true)
24
+ 30.times do
25
+ spinner.spin
26
+ sleep(0.1)
27
+ end
28
+ spinner.success
29
+
30
+ @forecast = WeatherByDcq::Request.fetch(location)
31
+ puts ""
32
+ puts "🌐 "+@forecast['timezone']
33
+
34
+ temperature = fetch_curr_data('temperature').to_i
35
+ @temperature = ((temperature - 32) / 1.8).round(2)
36
+ apparentTemperature = fetch_curr_data('apparentTemperature').to_i
37
+ @apparentTemperature = ((apparentTemperature - 32) / 1.8).round(2)
38
+
39
+
40
+ curr_table = TTY::Table.new ["\u{1F321} Temp.: #{@temperature}°C",
41
+ "\u{1F321} Heat Index: #{@apparentTemperature}°C"],
42
+ [["\u{1F4A6} Humidity: #{fetch_curr_data('humidity')}\u{0025}",
43
+ "\u{1F343} Wind Speed: #{fetch_curr_data('windSpeed')}mph"]]
44
+ puts curr_table.render(:ascii, padding: [0, 2])
45
+ puts ''
46
+ end
47
+
48
+ def self.display_forecast_list
49
+ @forecast['daily'].each do |key, value|
50
+ next unless key == 'data'
51
+
52
+ value.each.with_index do |n, index|
53
+ date = Time.at(n['time'])
54
+ puts "#{index + 1})".colorize(:blue) + " #{date.strftime('%a')} - #{date.month}/#{date.day}"
55
+ end
56
+ end
57
+ end
58
+
59
+ def self.display_details(num)
60
+ puts ''
61
+ display_forecast_list
62
+ puts ''
63
+
64
+ num -= 1
65
+ date = Time.at(@forecast['daily']['data'][num]['time'])
66
+ puts ''
67
+ puts " Detailed forecast on #{date.strftime('%a')} - #{date.month}/#{date.day}".colorize(:blue)
68
+ puts ' ========================================================================='.colorize(:blue)
69
+
70
+ hi = fetch_data(num, 'temperatureHigh').to_i
71
+ @hi = ((hi - 32) / 1.8).round(2)
72
+ lo = fetch_data(num, 'temperatureLow').to_i
73
+ @lo = ((lo - 32) / 1.8).round(2)
74
+ hea = fetch_data(num, 'apparentTemperatureHigh').to_i
75
+ @hea = ((hea - 32) / 1.8).round(2)
76
+
77
+ # Build table
78
+ detail_table = TTY::Table.new do |t|
79
+ t << ["\u{1F321} High: #{@hi}°C",
80
+ "\u{1F321} Low: #{@lo}°C",
81
+ "\u{1F321} Heat Index: #{@hea}°C"]
82
+ t << ["🌀 Wind: #{fetch_data(num, 'windSpeed').to_i}mph",
83
+ "🌦 Precip Prob.: #{(fetch_data(num, 'precipProbability') * 100).to_i}\u{0025}",
84
+ "🌧 Precip.: #{fetch_data(num, 'precipType').to_s.capitalize}"]
85
+ t << ["💧 Humidity: #{(fetch_data(num, 'humidity')*100).to_i}\u{0025}",
86
+ "🌇 Sunrise: #{fetch_sun_data(num, 'sunriseTime')}AM", "🌆 Sunset: #{fetch_sun_data(num, 'sunsetTime')}PM"]
87
+ end
88
+
89
+ puts " #{fetch_data(num, 'summary')}".colorize(:red)
90
+ puts ""
91
+ @icon = fetch_data(num, 'icon')
92
+ if @icon.eql?'rain'
93
+ puts " \u{2614}" + " #{@icon}".colorize(:yellow)
94
+ elsif @icon.eql?'clear-day'
95
+ puts " \u{1F324}" + " #{@icon}".colorize(:yellow)
96
+ elsif @icon.eql?'fog'
97
+ puts " \u{1F32B}" + " #{@icon}".colorize(:yellow)
98
+ else
99
+ puts " \u{1F325}" + " #{@icon}".colorize(:yellow)
100
+ end
101
+
102
+ puts detail_table.render(:ascii, padding: [0, 2]) { |renderer|
103
+ renderer.border.separator = :each_row
104
+ renderer.border.style = :cyan
105
+ }
106
+
107
+
108
+
109
+ end
110
+ end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'forecast_io'
4
+ require 'geocoder'
5
+ require 'pry'
6
+
7
+
8
+ # export
9
+
10
+ class WeatherByDcq::Request
11
+ attr_accessor :location
12
+
13
+ def initialize(location)
14
+ @location = location
15
+ end
16
+
17
+ # Convert user entered location to geodetic coordinates
18
+ def self.coordinate_pts(location)
19
+ city = Geocoder.search(location)
20
+ @lat = city[0].latitude
21
+ @lon = city[0].longitude
22
+ end
23
+
24
+ # fetch forecast hash from Dark Sky API
25
+ def self.fetch(location)
26
+ coordinate_pts(location)
27
+ ForecastIO.configure do |c|
28
+ c.api_key = '4aac124157c348289553a5e7fdc1899d'
29
+ c.default_params = { time: 600, exclude: 'minutely, hourly' }
30
+ end
31
+ @forecast = ForecastIO.forecast(@lat, @lon)
32
+ end
33
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module WeatherByDcq
4
+ VERSION = '0.1.0'.freeze
5
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'colorize'
4
+ require 'pry'
5
+
6
+ class WeatherByDcq::View
7
+ attr_accessor :location, :forecast
8
+
9
+ def menu
10
+ puts ''
11
+ puts 'Please enter a city to retrieve a forecast (Format: City State):'
12
+ location = gets.strip
13
+
14
+ puts "You entered: #{location}".colorize(:blue) + ' Is this correct (Y/N)?'
15
+ input_confirm = gets.strip.downcase
16
+ if input_confirm == 'n'
17
+ puts 'I am sorry, let us try again.'
18
+ menu
19
+ elsif input_confirm == 'y'
20
+ system('cls') || system('clear')
21
+ puts ''
22
+ puts "Current Conditions for #{location}:".colorize(:blue)
23
+ puts '====================================='
24
+ WeatherByDcq::Forecast.display_curr_table(location)
25
+
26
+ # Extended forecast List
27
+ puts 'Extended forecast:'.colorize(:blue)
28
+ puts '--------------------'
29
+ WeatherByDcq::Forecast.display_forecast_list
30
+ puts ''
31
+ options_menu
32
+ else
33
+ begin
34
+ raise WeatherError
35
+ rescue WeatherError => e
36
+ puts e.message
37
+ end
38
+ menu
39
+ end
40
+ end
41
+
42
+ def options_menu
43
+ puts ''
44
+ puts 'Would you like additional details about any of the days listed?'.colorize(:blue)
45
+ puts 'Please enter the corresponding number for your request, or any letter to EXIT: '.colorize(:blue)
46
+ detail_input = gets.strip.to_i
47
+ if detail_input.positive? && detail_input < 9
48
+ system('cls') || system('clear')
49
+ WeatherByDcq::Forecast.display_details(detail_input)
50
+ options_menu
51
+
52
+ elsif detail_input.negative? || detail_input > 8
53
+ begin
54
+ raise WeatherError
55
+ rescue WeatherError => e
56
+ puts e.message
57
+ end
58
+ options_menu
59
+ else
60
+ exit
61
+ end
62
+ end
63
+
64
+ class WeatherError < StandardError
65
+ def message
66
+ puts ''
67
+ puts ' <== ERROR ==>'.colorize(:white).on_red
68
+ puts ''
69
+ puts ' I do not understand your response, please try again.'.colorize(:yellow)
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,42 @@
1
+ lib = File.expand_path('lib', __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require_relative 'lib/weather_by_dcq/version'
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "weather_by_dcq"
7
+ spec.version = WeatherByDcq::VERSION
8
+ spec.authors = ["Doan Trung Quan"]
9
+ spec.email = ["doantrungquan97@gmail.com"]
10
+
11
+ spec.summary = "DarkSky API"
12
+ spec.description = "Write a longer description or delete this line."
13
+ spec.homepage = "https://github.com/TOMOSIA-VIETNAM/weather_by_dcq"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
16
+
17
+
18
+
19
+ spec.metadata["homepage_uri"] = spec.homepage
20
+ spec.metadata["source_code_uri"] = "https://github.com/TOMOSIA-VIETNAM/weather_by_dcq."
21
+ spec.metadata["changelog_uri"] = "https://github.com/TOMOSIA-VIETNAM/weather_by_dcq."
22
+
23
+ # Specify which files should be added to the gem when it is released.
24
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
27
+ end
28
+ spec.bindir = "exe"
29
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
30
+ spec.require_paths = ["lib"]
31
+
32
+ spec.add_development_dependency 'bundler', '~> 2.1.0'
33
+ spec.add_development_dependency 'colorize', '~>0.8.1'
34
+ spec.add_development_dependency 'forecast_io', '~>2.0.2'
35
+ spec.add_development_dependency 'geocoder', '~>1.5.2'
36
+ spec.add_development_dependency 'json', '~>2.3.0'
37
+ spec.add_development_dependency 'pry', '~>0.12.2'
38
+ spec.add_development_dependency 'rake', '~> 13.0.1'
39
+ spec.add_development_dependency 'rspec', '~> 3.9.0'
40
+ spec.add_development_dependency 'tty-spinner', '~>0.9.2'
41
+ spec.add_development_dependency 'tty-table', '~>0.11.0'
42
+ end
metadata ADDED
@@ -0,0 +1,201 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: weather_by_dcq
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Doan Trung Quan
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-12-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 2.1.0
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 2.1.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: colorize
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.8.1
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.8.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: forecast_io
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: geocoder
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.5.2
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.5.2
69
+ - !ruby/object:Gem::Dependency
70
+ name: json
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 2.3.0
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 2.3.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.12.2
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.12.2
97
+ - !ruby/object:Gem::Dependency
98
+ name: rake
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 13.0.1
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 13.0.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 3.9.0
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 3.9.0
125
+ - !ruby/object:Gem::Dependency
126
+ name: tty-spinner
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.9.2
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.9.2
139
+ - !ruby/object:Gem::Dependency
140
+ name: tty-table
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: 0.11.0
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: 0.11.0
153
+ description: Write a longer description or delete this line.
154
+ email:
155
+ - doantrungquan97@gmail.com
156
+ executables: []
157
+ extensions: []
158
+ extra_rdoc_files: []
159
+ files:
160
+ - ".gitignore"
161
+ - CODE_OF_CONDUCT.md
162
+ - Gemfile
163
+ - LICENSE.txt
164
+ - README.md
165
+ - Rakefile
166
+ - bin/console
167
+ - bin/setup
168
+ - bin/weather-by-dcq.rb
169
+ - lib/weather_by_dcq.rb
170
+ - lib/weather_by_dcq/forecast.rb
171
+ - lib/weather_by_dcq/request.rb
172
+ - lib/weather_by_dcq/version.rb
173
+ - lib/weather_by_dcq/view.rb
174
+ - weather_by_dcq.gemspec
175
+ homepage: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq
176
+ licenses:
177
+ - MIT
178
+ metadata:
179
+ homepage_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq
180
+ source_code_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.
181
+ changelog_uri: https://github.com/TOMOSIA-VIETNAM/weather_by_dcq.
182
+ post_install_message:
183
+ rdoc_options: []
184
+ require_paths:
185
+ - lib
186
+ required_ruby_version: !ruby/object:Gem::Requirement
187
+ requirements:
188
+ - - ">="
189
+ - !ruby/object:Gem::Version
190
+ version: 2.3.0
191
+ required_rubygems_version: !ruby/object:Gem::Requirement
192
+ requirements:
193
+ - - ">="
194
+ - !ruby/object:Gem::Version
195
+ version: '0'
196
+ requirements: []
197
+ rubygems_version: 3.0.1
198
+ signing_key:
199
+ specification_version: 4
200
+ summary: DarkSky API
201
+ test_files: []