darksky-api 0.1.3
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 +7 -0
- data/.gitignore +9 -0
- data/.rubocop.yml +24 -0
- data/.yardopts +2 -0
- data/Gemfile +10 -0
- data/Gemfile.lock +42 -0
- data/LICENSE.txt +21 -0
- data/README.md +106 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/darksky-api.gemspec +28 -0
- data/lib/darksky-api.rb +10 -0
- data/lib/darksky-api/config.rb +30 -0
- data/lib/darksky-api/current.rb +295 -0
- data/lib/darksky-api/day.rb +494 -0
- data/lib/darksky-api/location.rb +94 -0
- data/lib/darksky-api/version.rb +4 -0
- metadata +131 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 7a0d324adb3f3ca70e81b924293c2ddfe13074c2f9678d4ca02dbfcc9fa505f2
|
4
|
+
data.tar.gz: 9a6a530b42eb6b4f5a296f18e921911803399d494d796e2a01a0c47b79670d59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e83781a530fd0aec046da02ea3ba14a7161c9048861d9a9729a1e3c74f9a8520f1aa7a6a8b7997e79f1e10fc1954b4a66ce75725da814a75f4599f3e98a50e2c
|
7
|
+
data.tar.gz: 1fb64f1a6fa35ce39c5f51fc9fbd0effeb6272e9270d9faed379922ab8d3aa788e0afc49a079503c7d63c6404e9f62a9cf597a0652cc03c6234b31104a03e80c
|
data/.gitignore
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
Style/ClassVars:
|
2
|
+
Enabled: false
|
3
|
+
|
4
|
+
Style/Documentation:
|
5
|
+
Enabled: false
|
6
|
+
|
7
|
+
Style/AsciiComments:
|
8
|
+
Enabled: false
|
9
|
+
|
10
|
+
Naming/FileName:
|
11
|
+
Enabled: false
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Max: 20
|
15
|
+
|
16
|
+
Metrics/LineLength:
|
17
|
+
# disable for comment-only lines and lines with URLs
|
18
|
+
IgnoredPatterns: [
|
19
|
+
'^(\A|\s)*#',
|
20
|
+
'https?://'
|
21
|
+
]
|
22
|
+
|
23
|
+
Metrics/ClassLength:
|
24
|
+
Max: 200
|
data/.yardopts
ADDED
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
darksky-api (0.1.1)
|
5
|
+
json (~> 2.1)
|
6
|
+
rest-client (~> 2.0)
|
7
|
+
|
8
|
+
GEM
|
9
|
+
remote: https://rubygems.org/
|
10
|
+
specs:
|
11
|
+
domain_name (0.5.20170404)
|
12
|
+
unf (>= 0.0.5, < 1.0.0)
|
13
|
+
http-cookie (1.0.3)
|
14
|
+
domain_name (~> 0.5)
|
15
|
+
json (2.1.0)
|
16
|
+
mime-types (3.1)
|
17
|
+
mime-types-data (~> 3.2015)
|
18
|
+
mime-types-data (3.2016.0521)
|
19
|
+
minitest (5.10.3)
|
20
|
+
netrc (0.11.0)
|
21
|
+
rake (10.5.0)
|
22
|
+
rest-client (2.0.2)
|
23
|
+
http-cookie (>= 1.0.2, < 2.0)
|
24
|
+
mime-types (>= 1.16, < 4.0)
|
25
|
+
netrc (~> 0.8)
|
26
|
+
unf (0.1.4)
|
27
|
+
unf_ext
|
28
|
+
unf_ext (0.0.7.4)
|
29
|
+
|
30
|
+
PLATFORMS
|
31
|
+
ruby
|
32
|
+
|
33
|
+
DEPENDENCIES
|
34
|
+
bundler (~> 1.16)
|
35
|
+
darksky-api!
|
36
|
+
json (~> 2.1)
|
37
|
+
minitest (~> 5.0)
|
38
|
+
rake (~> 10.0)
|
39
|
+
rest-client (~> 2.0)
|
40
|
+
|
41
|
+
BUNDLED WITH
|
42
|
+
1.16.0
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Jacob Pratt
|
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,106 @@
|
|
1
|
+
# DarkSky
|
2
|
+
|
3
|
+
Disclaimer: This gem has no affiliation with DarkSky. It is an independent way to interact with its API.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'darksky-api'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install darksky-api
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### DarkSky
|
24
|
+
|
25
|
+
After importing DarkSky (`require 'darksky-api'`), you will need to configure it with some settings. All arguments are keyword arguments.
|
26
|
+
|
27
|
+
To configure DarkSky, you'll need to call `DarkSky.confg` with the kwargs below.
|
28
|
+
|
29
|
+
**Current kwargs**
|
30
|
+
|
31
|
+
| kwarg | purpose | default |
|
32
|
+
|-------|-------------------------|------------|
|
33
|
+
| key | secret key from DarkSky | *required* |
|
34
|
+
|
35
|
+
### DarkSky::Location
|
36
|
+
|
37
|
+
This library stores data *by location*. As such, you'll need to instantiate the `Location` class for each place you want data from. The required parameter is an array of the latitude and longitude.
|
38
|
+
|
39
|
+
To instantiate a Location: `loc = DarkSky::Location.new [lat, long]`
|
40
|
+
|
41
|
+
Optional kwargs:
|
42
|
+
|
43
|
+
| kwarg | options | default |
|
44
|
+
|------------------|-------------------------------------------------|---------|
|
45
|
+
| `cache_duration` | any positive number (in seconds) | 300 |
|
46
|
+
| `units` | `:auto`<br>`:si`<br>`:us`<br>`:uk`<br>`:canada` | `:auto` |
|
47
|
+
| `language` | any supported by DarkSky | `en` |
|
48
|
+
|
49
|
+
After you've configured `DarkSky` and created a `Location`, you're all set to start using the data! By default, the cache duration is 5 minutes, so anything you do within that timeframe only results in a single request.
|
50
|
+
|
51
|
+
To get data about the current time, use the `current` namespace. Here's all the operations defined in that namespace:
|
52
|
+
|
53
|
+
apparent_temperature (aliased as wind_chill, heat_index, feels_like)
|
54
|
+
clear?
|
55
|
+
cloud_cover
|
56
|
+
cloudy?
|
57
|
+
dew_point
|
58
|
+
foggy?
|
59
|
+
humidity
|
60
|
+
icon
|
61
|
+
nearest_storm_bearing
|
62
|
+
nearest_storm_bearing_text
|
63
|
+
nearest_storm_distance
|
64
|
+
ozone
|
65
|
+
precip_intensity
|
66
|
+
precip_intensity_text
|
67
|
+
precip_probability
|
68
|
+
precip_type
|
69
|
+
pressure
|
70
|
+
rainy?
|
71
|
+
sleet?
|
72
|
+
snowy?
|
73
|
+
summary
|
74
|
+
temperature
|
75
|
+
uv_index
|
76
|
+
visibility
|
77
|
+
wind_bearing
|
78
|
+
wind_bearing_text
|
79
|
+
wind_gust
|
80
|
+
wind_speed
|
81
|
+
windy?
|
82
|
+
|
83
|
+
Example: How do you get the current temperature (actual and apparent) in New York City?
|
84
|
+
|
85
|
+
```ruby
|
86
|
+
require 'darksky-api'
|
87
|
+
DarkSky.config 'KEY-VALUE'
|
88
|
+
|
89
|
+
nyc = DarkSky::Location.new [40.7828687, -73.9675438]
|
90
|
+
puts "temperature: #{nyc.current.temperature}" # actual air temperature
|
91
|
+
puts "feels like: #{nyc.current.feels_like}" # apparent temperature
|
92
|
+
```
|
93
|
+
|
94
|
+
## Development
|
95
|
+
|
96
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
97
|
+
|
98
|
+
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).
|
99
|
+
|
100
|
+
## Contributing
|
101
|
+
|
102
|
+
Bug reports and pull requests are welcome on GitHub at [jhpratt/darksky-api](https://github.com/jhpratt/darksky-api). Creating a pull request implies you are releasing you code under the license stated below.
|
103
|
+
|
104
|
+
## License
|
105
|
+
|
106
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'darksky-api'
|
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
data/darksky-api.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
lib = File.expand_path('../lib', __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'darksky-api/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = 'darksky-api'
|
7
|
+
spec.version = DarkSky::VERSION
|
8
|
+
spec.authors = ['Jacob Pratt']
|
9
|
+
spec.email = ['the.z.cuber@gmail.com']
|
10
|
+
|
11
|
+
spec.summary = 'Library for the public API on DarkSky.net'
|
12
|
+
spec.homepage = 'https://github.com/jhpratt/darksky-api'
|
13
|
+
spec.license = 'MIT'
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
16
|
+
f.match(%r{^(test|spec|features)/})
|
17
|
+
end
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_dependency 'json', '~> 2.1'
|
23
|
+
spec.add_dependency 'rest-client', '~> 2.0'
|
24
|
+
|
25
|
+
spec.add_development_dependency 'bundler', '~> 1.16'
|
26
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
27
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
28
|
+
end
|
data/lib/darksky-api.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
module DarkSky
|
2
|
+
# set required and optional class variables
|
3
|
+
#
|
4
|
+
# keyword arguments:
|
5
|
+
# - **`key`** [required] ─ API key from [DarkSky](https://darksky.net/dev/account)
|
6
|
+
# - **`warnings`** [optional] ─ whether or not warnings are printed (default `true`)
|
7
|
+
#
|
8
|
+
# @since 0.1.0
|
9
|
+
# @return [void]
|
10
|
+
def self.config(opts)
|
11
|
+
defaults = {
|
12
|
+
units: :si
|
13
|
+
}
|
14
|
+
opts = defaults.merge opts
|
15
|
+
|
16
|
+
# required parameters
|
17
|
+
@@key = opts.fetch(:key)
|
18
|
+
|
19
|
+
# optional parameters
|
20
|
+
@@units = opts[:units]
|
21
|
+
end
|
22
|
+
|
23
|
+
# @example
|
24
|
+
# DarkSky.key #=> '0f1e2d3c4b5a6978'
|
25
|
+
# @since 0.1.0
|
26
|
+
# @return [String] API key that was set by `.config()`
|
27
|
+
def self.key
|
28
|
+
@@key
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,295 @@
|
|
1
|
+
module DarkSky
|
2
|
+
class Location
|
3
|
+
class Current
|
4
|
+
# automatically called by `Location`
|
5
|
+
# @since 0.1.0
|
6
|
+
# @param [Location] location where to get data from
|
7
|
+
def initialize(location)
|
8
|
+
@location = location
|
9
|
+
end
|
10
|
+
|
11
|
+
# @example
|
12
|
+
# location = DarkSky::Location.new [45, -90]
|
13
|
+
# location.current.apparent_temperature #=> apparent temperature at location
|
14
|
+
# @since 0.1.0
|
15
|
+
# @return [Numeric] current apparent temperature at location
|
16
|
+
def apparent_temperature
|
17
|
+
data[:apparentTemperature]
|
18
|
+
end
|
19
|
+
alias wind_chill apparent_temperature
|
20
|
+
alias heat_index apparent_temperature
|
21
|
+
alias feels_like apparent_temperature
|
22
|
+
|
23
|
+
# @example
|
24
|
+
# location = DarkSky::Location.new [45, -90]
|
25
|
+
# location.current.cloud_cover #=> cloud cover at location
|
26
|
+
# @since 0.1.0
|
27
|
+
# @return [Numeric] current cloud cover at location
|
28
|
+
def cloud_cover
|
29
|
+
data[:cloudCover]
|
30
|
+
end
|
31
|
+
|
32
|
+
# @example
|
33
|
+
# location = DarkSky::Location.new [45, -90]
|
34
|
+
# location.current.dew_point #=> dew point at location
|
35
|
+
# @since 0.1.0
|
36
|
+
# @return [Numeric] current dew point at location
|
37
|
+
def dew_point
|
38
|
+
data[:dewPoint]
|
39
|
+
end
|
40
|
+
|
41
|
+
# @example
|
42
|
+
# location = DarkSky::Location.new [45, -90]
|
43
|
+
# location.current.humidity #=> humidity at location
|
44
|
+
# @since 0.1.0
|
45
|
+
# @return [Numeric] current humidity at location
|
46
|
+
def humidity
|
47
|
+
data[:humidity]
|
48
|
+
end
|
49
|
+
|
50
|
+
# @example
|
51
|
+
# location = DarkSky::Location.new [45, -90]
|
52
|
+
# location.current.icon #=> icon representation
|
53
|
+
# @since 0.1.0
|
54
|
+
# @return [String] icon representation of current weather at location
|
55
|
+
def icon
|
56
|
+
data[:icon]
|
57
|
+
end
|
58
|
+
|
59
|
+
# @example
|
60
|
+
# location = DarkSky::Location.new [45, -90]
|
61
|
+
# location.current.clear?
|
62
|
+
# @since 0.1.0
|
63
|
+
# @return [Boolean] if icon is 'clear' variant
|
64
|
+
def clear?
|
65
|
+
%w[clear-day clear-night].include? icon
|
66
|
+
end
|
67
|
+
|
68
|
+
# @example
|
69
|
+
# location = DarkSky::Location.new [45, -90]
|
70
|
+
# location.current.rainy?
|
71
|
+
# @since 0.1.0
|
72
|
+
# @return [Boolean] if icon is 'rain'
|
73
|
+
def rainy?
|
74
|
+
icon == 'rain'
|
75
|
+
end
|
76
|
+
|
77
|
+
# @example
|
78
|
+
# location = DarkSky::Location.new [45, -90]
|
79
|
+
# location.current.snowy?
|
80
|
+
# @since 0.1.0
|
81
|
+
# @return [Boolean] if icon is 'snow'
|
82
|
+
def snowy?
|
83
|
+
icon == 'snow'
|
84
|
+
end
|
85
|
+
|
86
|
+
# @example
|
87
|
+
# location = DarkSky::Location.new [45, -90]
|
88
|
+
# location.current.sleet?
|
89
|
+
# @since 0.1.0
|
90
|
+
# @return [Boolean] if icon is 'sleet'
|
91
|
+
def sleet?
|
92
|
+
icon == 'sleet'
|
93
|
+
end
|
94
|
+
|
95
|
+
# @example
|
96
|
+
# location = DarkSky::Location.new [45, -90]
|
97
|
+
# location.current.windy?
|
98
|
+
# @since 0.1.0
|
99
|
+
# @return [Boolean] if icon is 'wind'
|
100
|
+
def windy?
|
101
|
+
icon == 'wind'
|
102
|
+
end
|
103
|
+
|
104
|
+
# @example
|
105
|
+
# location = DarkSky::Location.new [45, -90]
|
106
|
+
# location.current.foggy?
|
107
|
+
# @since 0.1.0
|
108
|
+
# @return [Boolean] if icon is 'fog'
|
109
|
+
def foggy?
|
110
|
+
icon == 'fog'
|
111
|
+
end
|
112
|
+
|
113
|
+
# @example
|
114
|
+
# location = DarkSky::Location.new [45, -90]
|
115
|
+
# location.current.cloudy?
|
116
|
+
# @since 0.1.0
|
117
|
+
# @return [Boolean] if icon is 'cloudy' or variant
|
118
|
+
def cloudy?
|
119
|
+
%w[cloudy partly-cloudy-day partly-cloudy-night].include? icon
|
120
|
+
end
|
121
|
+
|
122
|
+
# @example
|
123
|
+
# location = DarkSky::Location.new [45, -90]
|
124
|
+
# location.current.nearest_storm_bearing #=> nearest storm bearing at location
|
125
|
+
# @since 0.1.0
|
126
|
+
# @return [Numeric] nearest storm bearing at location
|
127
|
+
def nearest_storm_bearing
|
128
|
+
data[:nearestStormBearing]
|
129
|
+
end
|
130
|
+
|
131
|
+
# @example
|
132
|
+
# location = DarkSky::Location.new [45, -90]
|
133
|
+
# location.current.nearest_storm_bearing_text #=> text representation of bearing (N, NW, etc.)
|
134
|
+
# @since 0.1.0
|
135
|
+
# @return [String] text representation of bearing
|
136
|
+
def nearest_storm_bearing_text
|
137
|
+
directions = %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW]
|
138
|
+
directions[nearest_storm_bearing / 22.5 + 0.5]
|
139
|
+
end
|
140
|
+
|
141
|
+
# @example
|
142
|
+
# location = DarkSky::Location.new [45, -90]
|
143
|
+
# location.current.nearest_storm_distance #=> nearest storm distance from location
|
144
|
+
# @since 0.1.0
|
145
|
+
# @return [Numeric] nearest storm distance from location
|
146
|
+
def nearest_storm_distance
|
147
|
+
data[:nearestStormDistance]
|
148
|
+
end
|
149
|
+
|
150
|
+
# @example
|
151
|
+
# location = DarkSky::Location.new [45, -90]
|
152
|
+
# location.current.ozone #=> ozone level at location
|
153
|
+
# @since 0.1.0
|
154
|
+
# @return [Numeric] current ozone level at location
|
155
|
+
def ozone
|
156
|
+
data[:ozone]
|
157
|
+
end
|
158
|
+
|
159
|
+
# @example
|
160
|
+
# location = DarkSky::Location.new [45, -90]
|
161
|
+
# location.current.precip_intensity #=> precipitation intensity at location
|
162
|
+
# @since 0.1.0
|
163
|
+
# @return [Numeric] current precipitation intensity at location
|
164
|
+
def precip_intensity
|
165
|
+
data[:precipIntensity]
|
166
|
+
end
|
167
|
+
|
168
|
+
# @example
|
169
|
+
# location = DarkSky::Locaiton.new [45, -90]
|
170
|
+
# location.current.precip_intensity_text #=> text representation of precipitation intensity at location
|
171
|
+
# @since 0.1.0
|
172
|
+
# @return [String] text representation of precipitation intensity at location
|
173
|
+
def precip_intensity_text
|
174
|
+
if precip_intensity >= 0.400
|
175
|
+
'heavy'
|
176
|
+
elsif precip_intensity >= 0.100
|
177
|
+
'moderate'
|
178
|
+
elsif precip_intensity >= 0.017
|
179
|
+
'light'
|
180
|
+
elsif precip_intensity >= 0.002
|
181
|
+
'very light'
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
# @example
|
186
|
+
# location = DarkSky::Location.new [45, -90]
|
187
|
+
# location.current.precip_probability #=> precipitation probability at location
|
188
|
+
# @since 0.1.0
|
189
|
+
# @return [Numeric] current precipitation probability at location
|
190
|
+
def precip_probability
|
191
|
+
data[:precipProbability]
|
192
|
+
end
|
193
|
+
|
194
|
+
# @example
|
195
|
+
# location = DarkSky::Location.new [45, -90]
|
196
|
+
# location.current.precip_type #=> precipitation type at location
|
197
|
+
# @since 0.1.0
|
198
|
+
# @return [String | nil] current precipitation type at location
|
199
|
+
def precip_type
|
200
|
+
data[:precipType]
|
201
|
+
end
|
202
|
+
|
203
|
+
# @example
|
204
|
+
# location = DarkSky::Location.new [45, -90]
|
205
|
+
# location.current.pressure #=> barometric pressure at location
|
206
|
+
# @since 0.1.0
|
207
|
+
# @return [Numeric] current barometric pressure at location
|
208
|
+
def pressure
|
209
|
+
data[:pressure]
|
210
|
+
end
|
211
|
+
|
212
|
+
# @example
|
213
|
+
# location = DarkSky::Location.new [45, -90]
|
214
|
+
# location.current.summary #=> summary of weather at location
|
215
|
+
# @since 0.1.0
|
216
|
+
# @return [String] summary of weather at location
|
217
|
+
def summary
|
218
|
+
data[:summary]
|
219
|
+
end
|
220
|
+
|
221
|
+
# @example
|
222
|
+
# location = DarkSky::Location.new [45, -90]
|
223
|
+
# location.current.temperature #=> temperature at location
|
224
|
+
# @since 0.1.0
|
225
|
+
# @return [Numeric] current temperature at location
|
226
|
+
def temperature
|
227
|
+
data[:temperature]
|
228
|
+
end
|
229
|
+
|
230
|
+
# @example
|
231
|
+
# location = DarkSky::Location.new [45, -90]
|
232
|
+
# location.current.uv_index #=> UV index at location
|
233
|
+
# @since 0.1.0
|
234
|
+
# @return [Numeric] current UV index at location
|
235
|
+
def uv_index
|
236
|
+
data[:uvIndex]
|
237
|
+
end
|
238
|
+
|
239
|
+
# @example
|
240
|
+
# location = DarkSky::Location.new [45, -90]
|
241
|
+
# location.current.visibility #=> visibility at location
|
242
|
+
# @since 0.1.0
|
243
|
+
# @return [Numeric] current visibility at location
|
244
|
+
def visibility
|
245
|
+
data[:visibility]
|
246
|
+
end
|
247
|
+
|
248
|
+
# @example
|
249
|
+
# location = DarkSky::Location.new [45, -90]
|
250
|
+
# location.current.wind_bearing #=> wind bearing at location
|
251
|
+
# @since 0.1.0
|
252
|
+
# @return [Numeric] current wind bearing at location
|
253
|
+
def wind_bearing
|
254
|
+
data[:windBearing]
|
255
|
+
end
|
256
|
+
|
257
|
+
# @example
|
258
|
+
# location = DarkSky::Location.new [45, -90]
|
259
|
+
# location.current.wind_bearing_text #=> text representation of bearing (N, NW, etc.)
|
260
|
+
# @since 0.1.0
|
261
|
+
# @return [String] text representation of bearing
|
262
|
+
def wind_bearing_text
|
263
|
+
directions = %w[N NNE NE ENE E ESE SE SSE S SSW SW WSW W WNW NW NNW]
|
264
|
+
directions[wind_bearing / 22.5 + 0.5]
|
265
|
+
end
|
266
|
+
|
267
|
+
# @example
|
268
|
+
# location = DarkSky::Location.new [45, -90]
|
269
|
+
# location.current.wind_gust #=> wind gust at location
|
270
|
+
# @since 0.1.0
|
271
|
+
# @return [Numeric] current wind gust at location
|
272
|
+
def wind_gust
|
273
|
+
data[:windGust]
|
274
|
+
end
|
275
|
+
|
276
|
+
# @example
|
277
|
+
# location = DarkSky::Location.new [45, -90]
|
278
|
+
# location.current.wind_speed #=> wind speed at location
|
279
|
+
# @since 0.1.0
|
280
|
+
# @return [Numeric] current wind speed at location
|
281
|
+
def wind_speed
|
282
|
+
data[:windSpeed]
|
283
|
+
end
|
284
|
+
|
285
|
+
private
|
286
|
+
|
287
|
+
# helper to avoid typing this many times over
|
288
|
+
# @since 0.1.3
|
289
|
+
# @return [Hash] full data for current time
|
290
|
+
def data
|
291
|
+
@location.full_data[:currently]
|
292
|
+
end
|
293
|
+
end
|
294
|
+
end
|
295
|
+
end
|
@@ -0,0 +1,494 @@
|
|
1
|
+
module DarkSky
|
2
|
+
class Location
|
3
|
+
class Day
|
4
|
+
# automatically called by `Location`
|
5
|
+
# @since 0.1.3
|
6
|
+
# @param [Location] location where to get data from
|
7
|
+
def initialize(location, days_from_current)
|
8
|
+
@location = location
|
9
|
+
@days_from_current = days_from_current
|
10
|
+
end
|
11
|
+
|
12
|
+
# @example
|
13
|
+
# location = DarkSky::Location.new [45, -90]
|
14
|
+
# location.today.date #=> object for the date
|
15
|
+
# @since 0.1.3
|
16
|
+
# @return [Date] object for the day
|
17
|
+
def date
|
18
|
+
# we only want the date, so don't use `Time.at()`
|
19
|
+
Date.strptime data[:time].to_s, '%s'
|
20
|
+
end
|
21
|
+
|
22
|
+
# @example
|
23
|
+
# location = DarkSky::Location.new [45, -90]
|
24
|
+
# location.today.temperature_high #=> high temperature for the day
|
25
|
+
# @since 0.1.3
|
26
|
+
# @return [Numeric] high temperature for the day
|
27
|
+
def temperature_high
|
28
|
+
data[:temperatureHigh]
|
29
|
+
end
|
30
|
+
alias high_temperature temperature_high
|
31
|
+
|
32
|
+
# @example
|
33
|
+
# location = DarkSky::Location.new [45, -90]
|
34
|
+
# location.today.temperature_high_time #=> time of high temperature
|
35
|
+
# @since 0.1.3
|
36
|
+
# @return [Time] time of high temperature
|
37
|
+
def temperature_high_time
|
38
|
+
Time.at data[:temperatureHighTime]
|
39
|
+
end
|
40
|
+
alias high_temperature_time temperature_high_time
|
41
|
+
|
42
|
+
# @example
|
43
|
+
# location = DarkSky::Location.new [45, -90]
|
44
|
+
# location.today.temperature_low #=> low temperature for the day
|
45
|
+
# @since 0.1.3
|
46
|
+
# @return [Numeric] low temperature for the day
|
47
|
+
def temperature_low
|
48
|
+
data[:temperatureLow]
|
49
|
+
end
|
50
|
+
alias low_temperature temperature_low
|
51
|
+
|
52
|
+
# @example
|
53
|
+
# location = DarkSky::Location.new [45, -90]
|
54
|
+
# location.today.temperature_low_time #=> time of low temperature
|
55
|
+
# @since 0.1.3
|
56
|
+
# @return [Time] time of low temperature
|
57
|
+
def temperature_low_time
|
58
|
+
Time.at data[:temperatureLowTime]
|
59
|
+
end
|
60
|
+
alias low_temperature_time temperature_low_time
|
61
|
+
|
62
|
+
# @example
|
63
|
+
# location = DarkSky::Location.new [45, -90]
|
64
|
+
# location.today.icon #=> icon representation
|
65
|
+
# @since 0.1.3
|
66
|
+
# @return [String] icon representation of weather on day
|
67
|
+
def icon
|
68
|
+
data[:icon]
|
69
|
+
end
|
70
|
+
|
71
|
+
# @example
|
72
|
+
# location = DarkSky::Location.new [45, -90]
|
73
|
+
# location.today.summary #=> summary of weather
|
74
|
+
# @since 0.1.3
|
75
|
+
# @return [String] summary of weather on day
|
76
|
+
def summary
|
77
|
+
data[:summary]
|
78
|
+
end
|
79
|
+
|
80
|
+
# @example
|
81
|
+
# location = DarkSky::Location.new [45, -90]
|
82
|
+
# location.today.sunrise_time #=> sunrise time on day
|
83
|
+
# @since 0.1.3
|
84
|
+
# @return [Time] object with sunrise timestamp
|
85
|
+
def sunrise_time
|
86
|
+
Time.at data[:sunriseTime]
|
87
|
+
end
|
88
|
+
alias sunrise sunrise_time
|
89
|
+
|
90
|
+
# @example
|
91
|
+
# location = DarkSky::Location.new [45, -90]
|
92
|
+
# location.today.sunset_time #=> sunset time on day
|
93
|
+
# @since 0.1.3
|
94
|
+
# @return [Time] object with sunset timestamp
|
95
|
+
def sunset_time
|
96
|
+
Time.at data[:sunsetTime]
|
97
|
+
end
|
98
|
+
alias sunset sunset_time
|
99
|
+
|
100
|
+
# @example
|
101
|
+
# location = DarkSky::Location.new [45, -90]
|
102
|
+
# location.today.moon_phase #=> moon phase on day
|
103
|
+
# @since 0.1.3
|
104
|
+
# @return [Numeric] phase of the moon (0 to 1)
|
105
|
+
def moon_phase
|
106
|
+
data[:moonPhase]
|
107
|
+
end
|
108
|
+
|
109
|
+
# @example
|
110
|
+
# location = DarkSky::Location.new [45, -90]
|
111
|
+
# location.today.moon_phase_text #=> textual representation of moon phase
|
112
|
+
# @since 0.1.3
|
113
|
+
# @return [String] textual representation of moon phase
|
114
|
+
def moon_phase_text
|
115
|
+
# separate method for easy unit testing
|
116
|
+
_moon_phase_text moon_phase
|
117
|
+
end
|
118
|
+
|
119
|
+
# @example
|
120
|
+
# location = DarkSky::Location.new [45, -90]
|
121
|
+
# location.today.precip_intensity #=> precipitation intensity on day
|
122
|
+
# @since 0.1.3
|
123
|
+
# @return [Numeric] precipitation intensity on day
|
124
|
+
def precip_intensity
|
125
|
+
data[:precipIntensity]
|
126
|
+
end
|
127
|
+
|
128
|
+
# @example
|
129
|
+
# location = DarkSky::Locaiton.new [45, -90]
|
130
|
+
# location.today.precip_intensity_text #=> text representation of precipitation intensity on day
|
131
|
+
# @since 0.1.3
|
132
|
+
# @return [String] text representation of precipitation intensity on day
|
133
|
+
def precip_intensity_text
|
134
|
+
if precip_intensity >= 0.400
|
135
|
+
'heavy'
|
136
|
+
elsif precip_intensity >= 0.100
|
137
|
+
'moderate'
|
138
|
+
elsif precip_intensity >= 0.017
|
139
|
+
'light'
|
140
|
+
elsif precip_intensity >= 0.002
|
141
|
+
'very light'
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
# @example
|
146
|
+
# location = DarkSky::Location.new [45, -90]
|
147
|
+
# location.today.precip_intensity_max #=> precipitation intensity on day
|
148
|
+
# @since 0.1.3
|
149
|
+
# @return [Numeric] maximum precipitation intensity on day
|
150
|
+
def precip_intensity_max
|
151
|
+
data[:precipIntensityMax]
|
152
|
+
end
|
153
|
+
|
154
|
+
# @example
|
155
|
+
# location = DarkSky::Locaiton.new [45, -90]
|
156
|
+
# location.today.precip_intensity_max_text #=> text representation of maximum precipitation intensity on day
|
157
|
+
# @since 0.1.3
|
158
|
+
# @return [String] text representation of maximum precipitation intensity on day
|
159
|
+
def precip_intensity_max_text
|
160
|
+
if precip_intensity_max >= 0.400
|
161
|
+
'heavy'
|
162
|
+
elsif precip_intensity_max >= 0.100
|
163
|
+
'moderate'
|
164
|
+
elsif precip_intensity_max >= 0.017
|
165
|
+
'light'
|
166
|
+
elsif precip_intensity_max >= 0.002
|
167
|
+
'very light'
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
# @example
|
172
|
+
# location = DarkSky::Location.new [45, -90]
|
173
|
+
# location.today.precip_intensity_max_time #=> object of max time
|
174
|
+
# @since 0.1.3
|
175
|
+
# @return [Time] time of maximum precipitation intensity
|
176
|
+
def precip_intensity_max_time
|
177
|
+
Time.at data[:precipIntensityMaxTime] if data[:precipIntensityMaxTime]
|
178
|
+
end
|
179
|
+
|
180
|
+
# @example
|
181
|
+
# location = DarkSky::Location.new [45, -90]
|
182
|
+
# location.today.precip_probability #=> precipitation probability on day
|
183
|
+
# @since 0.1.3
|
184
|
+
# @return [Numeric] precipitation probability
|
185
|
+
def precip_probability
|
186
|
+
data[:precipProbability]
|
187
|
+
end
|
188
|
+
|
189
|
+
# @example
|
190
|
+
# location = DarkSky::Location.new [45, -90]
|
191
|
+
# location.today.precip_type #=> precipitation type on day
|
192
|
+
# @since 0.1.3
|
193
|
+
# @return [String | nil] current precipitation type on day
|
194
|
+
def precip_type
|
195
|
+
data[:precipType]
|
196
|
+
end
|
197
|
+
|
198
|
+
# @example
|
199
|
+
# location = DarkSky::Location.new [45, -90]
|
200
|
+
# location.today.precip_accumulation #=> precipitation accumulation on day
|
201
|
+
# @since 0.1.3
|
202
|
+
# @return [Numeric] precipitation accumulation on day
|
203
|
+
def precip_accumulation
|
204
|
+
data[:precipAccumulation]
|
205
|
+
end
|
206
|
+
|
207
|
+
# @example
|
208
|
+
# location = DarkSky::Location.new [45, -90]
|
209
|
+
# location.today.apparent_temperature_high #=> high feels like on day
|
210
|
+
# @since 0.1.3
|
211
|
+
# @return [Numeric] high feels like on day
|
212
|
+
def apparent_temperature_high
|
213
|
+
data[:apparentTemperatureHigh]
|
214
|
+
end
|
215
|
+
alias high_apparent_temperature apparent_temperature_high
|
216
|
+
alias apparent_high_temperature apparent_temperature_high
|
217
|
+
alias high_feels_like apparent_temperature_high
|
218
|
+
alias feels_like_high apparent_temperature_high
|
219
|
+
alias high_heat_index apparent_temperature_high
|
220
|
+
alias heat_index_high apparent_temperature_high
|
221
|
+
alias high_wind_chill apparent_temperature_high
|
222
|
+
alias wind_chill_high apparent_temperature_high
|
223
|
+
|
224
|
+
# @example
|
225
|
+
# location = DarkSky::Location.new [45, -90]
|
226
|
+
# location.today.apparent_temperature_low #=> low feels like on day
|
227
|
+
# @since 0.1.3
|
228
|
+
# @return [Numeric] low feels like on day
|
229
|
+
def apparent_temperature_low
|
230
|
+
data[:apparentTemperatureLow]
|
231
|
+
end
|
232
|
+
alias low_apparent_temperature apparent_temperature_low
|
233
|
+
alias apparent_low_temperature apparent_temperature_low
|
234
|
+
alias low_feels_like apparent_temperature_low
|
235
|
+
alias feels_like_low apparent_temperature_low
|
236
|
+
alias low_heat_index apparent_temperature_low
|
237
|
+
alias heat_index_low apparent_temperature_low
|
238
|
+
alias low_wind_chill apparent_temperature_low
|
239
|
+
alias wind_chill_low apparent_temperature_low
|
240
|
+
|
241
|
+
# @example
|
242
|
+
# location = DarkSky::Location.new [45, -90]
|
243
|
+
# location.today.apparent_temperature_high_time #=> time of high apparent temperature
|
244
|
+
# @since 0.1.3
|
245
|
+
# @return [Numeric] time of high apparent temperature
|
246
|
+
def apparent_temperature_high_time
|
247
|
+
data[:apparentTemperatureHighTime]
|
248
|
+
end
|
249
|
+
alias high_apparent_temperature_time apparent_temperature_high_time
|
250
|
+
alias apparent_high_temperature_time apparent_temperature_high_time
|
251
|
+
alias high_feels_like_time apparent_temperature_high_time
|
252
|
+
alias feels_like_high_time apparent_temperature_high_time
|
253
|
+
alias high_heat_index_time apparent_temperature_high_time
|
254
|
+
alias heat_index_high_time apparent_temperature_high_time
|
255
|
+
alias high_wind_chill_time apparent_temperature_high_time
|
256
|
+
alias wind_chill_high_time apparent_temperature_high_time
|
257
|
+
|
258
|
+
# @example
|
259
|
+
# location = DarkSky::Location.new [45, -90]
|
260
|
+
# location.today.apparent_temperature_low_time #=> time of low apparent temperature
|
261
|
+
# @since 0.1.3
|
262
|
+
# @return [Numeric] time of low apparent temperature
|
263
|
+
def apparent_temperature_low_time
|
264
|
+
data[:apparentTemperatureLowTime]
|
265
|
+
end
|
266
|
+
alias low_apparent_temperature_time apparent_temperature_low_time
|
267
|
+
alias apparent_low_temperature_time apparent_temperature_low_time
|
268
|
+
alias low_feels_like_time apparent_temperature_low_time
|
269
|
+
alias feels_like_low_time apparent_temperature_low_time
|
270
|
+
alias low_heat_index_time apparent_temperature_low_time
|
271
|
+
alias heat_index_low_time apparent_temperature_low_time
|
272
|
+
alias low_wind_chill_time apparent_temperature_low_time
|
273
|
+
alias wind_chill_low_time apparent_temperature_low_time
|
274
|
+
|
275
|
+
# @example
|
276
|
+
# location = DarkSky::Location.new [45, -90]
|
277
|
+
# location.today.dew_point #=> dew point on day
|
278
|
+
# @since 0.1.3
|
279
|
+
# @return [Numeric] dew point on day
|
280
|
+
def dew_point
|
281
|
+
data[:dewPoint]
|
282
|
+
end
|
283
|
+
|
284
|
+
# @example
|
285
|
+
# location = DarkSky::Location.new [45, -90]
|
286
|
+
# location.today.humidity #=> humidity on day
|
287
|
+
# @since 0.1.3
|
288
|
+
# @return [Numeric] humidity on day
|
289
|
+
def humidity
|
290
|
+
data[:humidity]
|
291
|
+
end
|
292
|
+
|
293
|
+
# @example
|
294
|
+
# location = DarkSky::Location.new [45, -90]
|
295
|
+
# location.today.pressure #=> barometric pressue on day
|
296
|
+
# @since 0.1.3
|
297
|
+
# @return [Numeric] barometric pressure on day
|
298
|
+
def pressure
|
299
|
+
data[:pressure]
|
300
|
+
end
|
301
|
+
|
302
|
+
# @example
|
303
|
+
# location = DarkSky::Location.new [45, -90]
|
304
|
+
# location.today.wind_speed #=> wind speed on day
|
305
|
+
# @since 0.1.3
|
306
|
+
# @return [Numeric] wind speed on day
|
307
|
+
def wind_speed
|
308
|
+
data[:windSpeed]
|
309
|
+
end
|
310
|
+
|
311
|
+
# @example
|
312
|
+
# location = DarkSky::Location.new [45, -90]
|
313
|
+
# location.today.wind_gust #=> wind gust on day
|
314
|
+
# @since 0.1.3
|
315
|
+
# @return [Numeric] wind gust on day
|
316
|
+
def wind_gust
|
317
|
+
data[:windGust]
|
318
|
+
end
|
319
|
+
|
320
|
+
# @example
|
321
|
+
# location = DarkSky::Location.new [45, -90]
|
322
|
+
# location.today.wind_gust_time #=> wind gust time on day
|
323
|
+
# @since 0.1.3
|
324
|
+
# @return [Time] wind gust time on day
|
325
|
+
def wind_gust_time
|
326
|
+
Time.at data[:windGustTime]
|
327
|
+
end
|
328
|
+
|
329
|
+
# @example
|
330
|
+
# location = DarkSky::Location.new [45, -90]
|
331
|
+
# location.today.wind_bearing #=> wind bearing on day
|
332
|
+
# @since 0.1.3
|
333
|
+
# @return [Numeric] wind bearing on day
|
334
|
+
def wind_bearing
|
335
|
+
data[:windBearing]
|
336
|
+
end
|
337
|
+
|
338
|
+
# @example
|
339
|
+
# location = DarkSky::Location.new [45, -90]
|
340
|
+
# location.today.cloud_cover #=> cloud cover on day
|
341
|
+
# @since 0.1.3
|
342
|
+
# @return [Numeric] cloud cover on day
|
343
|
+
def cloud_cover
|
344
|
+
data[:cloudCover]
|
345
|
+
end
|
346
|
+
|
347
|
+
# @example
|
348
|
+
# location = DarkSky::Location.new [45, -90]
|
349
|
+
# location.today.uv_index #=> UV index on day
|
350
|
+
# @since 0.1.3
|
351
|
+
# @return [Numeric] UV index on day
|
352
|
+
def uv_index
|
353
|
+
data[:uvIndex]
|
354
|
+
end
|
355
|
+
|
356
|
+
# @example
|
357
|
+
# location = DarkSky::Location.new [45, -90]
|
358
|
+
# location.today.uv_index_time #=> max UV index time on day
|
359
|
+
# @since 0.1.3
|
360
|
+
# @return [Time] max UV index time on day
|
361
|
+
def uv_index_time
|
362
|
+
Time.at data[:uvIndexTime]
|
363
|
+
end
|
364
|
+
|
365
|
+
# @example
|
366
|
+
# location = DarkSky::Location.new [45, -90]
|
367
|
+
# location.today.visibility #=> visibility on day
|
368
|
+
# @since 0.1.3
|
369
|
+
# @return [Numeric] visibility on day
|
370
|
+
def visibility
|
371
|
+
data[:visibility]
|
372
|
+
end
|
373
|
+
|
374
|
+
# @example
|
375
|
+
# location = DarkSky::Location.new [45, -90]
|
376
|
+
# location.today.ozone #=> ozone on day
|
377
|
+
# @since 0.1.3
|
378
|
+
# @return [Numeric] ozone on day
|
379
|
+
def ozone
|
380
|
+
data[:ozone]
|
381
|
+
end
|
382
|
+
|
383
|
+
private
|
384
|
+
|
385
|
+
# helper to avoid typing this many times over
|
386
|
+
# @since 0.1.3
|
387
|
+
# @return [Hash] full data for the given day
|
388
|
+
def data
|
389
|
+
@location.full_data[:daily][:data][@days_from_current]
|
390
|
+
end
|
391
|
+
|
392
|
+
# convert numerical moon phase to text
|
393
|
+
# 10% around each phase (new, first quarter, full, last quarter)
|
394
|
+
# keep this a separate method for testing purposes
|
395
|
+
# @since 0.1.3
|
396
|
+
# @return [String] text representation of moon phase
|
397
|
+
def _moon_phase_text(phase) # rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/LineLength
|
398
|
+
if phase < 0.05
|
399
|
+
'new moon'
|
400
|
+
elsif phase < 0.20
|
401
|
+
'waxing crescent moon'
|
402
|
+
elsif phase < 0.30
|
403
|
+
'first quarter moon'
|
404
|
+
elsif phase < 0.45
|
405
|
+
'waxing gibbous moon'
|
406
|
+
elsif phase < 0.55
|
407
|
+
'full moon'
|
408
|
+
elsif phase < 0.70
|
409
|
+
'waning gibbous moon'
|
410
|
+
elsif phase < 0.80
|
411
|
+
'last quarter moon'
|
412
|
+
elsif phase < 0.95
|
413
|
+
'waning crescent moon'
|
414
|
+
else
|
415
|
+
'new moon'
|
416
|
+
end
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
# @example
|
421
|
+
# location = DarkSky::Location.new [45, -90]
|
422
|
+
# location.today #=> DarkSky::Location::Day
|
423
|
+
# @since 0.1.3
|
424
|
+
# @return [Day] class containing data for given day
|
425
|
+
def today
|
426
|
+
Day.new self, 0
|
427
|
+
end
|
428
|
+
alias in_0_days today
|
429
|
+
|
430
|
+
# @example
|
431
|
+
# location = DarkSky::Location.new [45, -90]
|
432
|
+
# location.tomorrow #=> DarkSky::Location::Day
|
433
|
+
# @since 0.1.3
|
434
|
+
# @return [Day] class containing data for given day
|
435
|
+
def tomorrow
|
436
|
+
Day.new self, 1
|
437
|
+
end
|
438
|
+
alias in_1_day tomorrow
|
439
|
+
|
440
|
+
# @example
|
441
|
+
# location = DarkSky::Location.new [45, -90]
|
442
|
+
# location.in_2_days #=> DarkSky::Location::Day
|
443
|
+
# @since 0.1.3
|
444
|
+
# @return [Day] class containing data for given day
|
445
|
+
def in_2_days
|
446
|
+
Day.new self, 2
|
447
|
+
end
|
448
|
+
|
449
|
+
# @example
|
450
|
+
# location = DarkSky::Location.new [45, -90]
|
451
|
+
# location.in_3_days #=> DarkSky::Location::Day
|
452
|
+
# @since 0.1.3
|
453
|
+
# @return [Day] class containing data for given day
|
454
|
+
def in_3_days
|
455
|
+
Day.new self, 3
|
456
|
+
end
|
457
|
+
|
458
|
+
# @example
|
459
|
+
# location = DarkSky::Location.new [45, -90]
|
460
|
+
# location.in_4_days #=> DarkSky::Location::Day
|
461
|
+
# @since 0.1.3
|
462
|
+
# @return [Day] class containing data for given day
|
463
|
+
def in_4_days
|
464
|
+
Day.new self, 4
|
465
|
+
end
|
466
|
+
|
467
|
+
# @example
|
468
|
+
# location = DarkSky::Location.new [45, -90]
|
469
|
+
# location.in_5_days #=> DarkSky::Location::Day
|
470
|
+
# @since 0.1.3
|
471
|
+
# @return [Day] class containing data for given day
|
472
|
+
def in_5_days
|
473
|
+
Day.new self, 5
|
474
|
+
end
|
475
|
+
|
476
|
+
# @example
|
477
|
+
# location = DarkSky::Location.new [45, -90]
|
478
|
+
# location.in_6_days #=> DarkSky::Location::Day
|
479
|
+
# @since 0.1.3
|
480
|
+
# @return [Day] class containing data for given day
|
481
|
+
def in_6_days
|
482
|
+
Day.new self, 6
|
483
|
+
end
|
484
|
+
|
485
|
+
# @example
|
486
|
+
# location = DarkSky::Location.new [45, -90]
|
487
|
+
# location.in_7_days #=> DarkSky::Location::Day
|
488
|
+
# @since 0.1.3
|
489
|
+
# @return [Day] class containing data for given day
|
490
|
+
def in_7_days
|
491
|
+
Day.new self, 7
|
492
|
+
end
|
493
|
+
end
|
494
|
+
end
|
@@ -0,0 +1,94 @@
|
|
1
|
+
require 'rest-client'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
module DarkSky
|
5
|
+
class Location
|
6
|
+
# @example
|
7
|
+
# location = DarkSky::Location.new [45, -90]
|
8
|
+
# location.location #=> [45, -90]
|
9
|
+
# @since 0.1.0
|
10
|
+
# @return [Array<Numeric>] coordinates of object and data
|
11
|
+
attr_reader :location
|
12
|
+
|
13
|
+
# @example
|
14
|
+
# location = DarkSky::Location.new [45, -90]
|
15
|
+
# location.current #=> DarkSky::Location::Current
|
16
|
+
# @since 0.1.0
|
17
|
+
# @return [Current] class containing data for current time and location
|
18
|
+
attr_reader :current
|
19
|
+
|
20
|
+
# @example
|
21
|
+
# location = DarkSky::Location.new [45, -90]
|
22
|
+
# location.units #=> :si
|
23
|
+
# @since 0.1.2
|
24
|
+
# @return [Symbol] what unit system is being used
|
25
|
+
attr_reader :units
|
26
|
+
|
27
|
+
# @example
|
28
|
+
# location = DarkSky::Location.new [45, -90]
|
29
|
+
# location.language #=> :en
|
30
|
+
# @since 0.1.2
|
31
|
+
# @return [Symbol] what language is used
|
32
|
+
attr_reader :language
|
33
|
+
|
34
|
+
# @example getter
|
35
|
+
# location = DarkSky::Location.new [45, -90]
|
36
|
+
# location.cache_duration #=> 300
|
37
|
+
# @example setter
|
38
|
+
# location = DarkSky::Location.new [45, -90]
|
39
|
+
# location.cache_duration = 600
|
40
|
+
# location.cache_duration #=> 600
|
41
|
+
# @since 0.1.0
|
42
|
+
# @return [Numeric] how long is data valid for before a new request is made?
|
43
|
+
attr_accessor :cache_duration
|
44
|
+
|
45
|
+
# @param location [[Numeric, Numeric]] coordinates to get data of
|
46
|
+
# @param [Numeric] cache_duration requests within this many seconds will be parsed on existing data
|
47
|
+
# @param [Symbol | String] units what unit system to use
|
48
|
+
# @param [Symbol | String] language what language to return results in
|
49
|
+
def initialize(
|
50
|
+
location = [0, 0],
|
51
|
+
cache_duration: 300,
|
52
|
+
units: :auto,
|
53
|
+
language: :en
|
54
|
+
)
|
55
|
+
# initial value to avoid errors
|
56
|
+
@cache_time = 1
|
57
|
+
|
58
|
+
# initialize instance variables from args & kwargs
|
59
|
+
@location = location
|
60
|
+
@cache_duration = cache_duration # in seconds
|
61
|
+
@language = language.to_sym
|
62
|
+
|
63
|
+
# aliases for some unit systems
|
64
|
+
units = units.to_sym
|
65
|
+
if units == :uk
|
66
|
+
@units == :uk2
|
67
|
+
elsif units == :canada
|
68
|
+
@units == :ca
|
69
|
+
else
|
70
|
+
@units = units
|
71
|
+
end
|
72
|
+
|
73
|
+
# initialize classes for namespace
|
74
|
+
@current = Current.new self
|
75
|
+
end
|
76
|
+
|
77
|
+
# update cache if necessary and get latest data
|
78
|
+
# @example
|
79
|
+
# location = DarkSky::Location.new
|
80
|
+
# location.full_data
|
81
|
+
# @since 0.1.0
|
82
|
+
# @return [Hash] raw data (in full) from DarkSky
|
83
|
+
def full_data
|
84
|
+
if (Time.now - @cache_time).to_i >= @cache_duration
|
85
|
+
response = RestClient.get "https://api.darksky.net/forecast/#{DarkSky.key}/#{@location.join ','}",
|
86
|
+
units: @units,
|
87
|
+
language: @language
|
88
|
+
@data = JSON.parse response.body, symbolize_names: true
|
89
|
+
@cache_time = Time.now
|
90
|
+
end
|
91
|
+
@data
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
metadata
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: darksky-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jacob Pratt
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: json
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rest-client
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '2.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.16'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.16'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description:
|
84
|
+
email:
|
85
|
+
- the.z.cuber@gmail.com
|
86
|
+
executables: []
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".rubocop.yml"
|
92
|
+
- ".yardopts"
|
93
|
+
- Gemfile
|
94
|
+
- Gemfile.lock
|
95
|
+
- LICENSE.txt
|
96
|
+
- README.md
|
97
|
+
- Rakefile
|
98
|
+
- bin/console
|
99
|
+
- bin/setup
|
100
|
+
- darksky-api.gemspec
|
101
|
+
- lib/darksky-api.rb
|
102
|
+
- lib/darksky-api/config.rb
|
103
|
+
- lib/darksky-api/current.rb
|
104
|
+
- lib/darksky-api/day.rb
|
105
|
+
- lib/darksky-api/location.rb
|
106
|
+
- lib/darksky-api/version.rb
|
107
|
+
homepage: https://github.com/jhpratt/darksky-api
|
108
|
+
licenses:
|
109
|
+
- MIT
|
110
|
+
metadata: {}
|
111
|
+
post_install_message:
|
112
|
+
rdoc_options: []
|
113
|
+
require_paths:
|
114
|
+
- lib
|
115
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
125
|
+
requirements: []
|
126
|
+
rubyforge_project:
|
127
|
+
rubygems_version: 2.7.3
|
128
|
+
signing_key:
|
129
|
+
specification_version: 4
|
130
|
+
summary: Library for the public API on DarkSky.net
|
131
|
+
test_files: []
|