https://github.com/kenjij/darksky-ruby
Pure simple Ruby based Dark Sky API gem
https://github.com/kenjij/darksky-ruby
api darksky gem ruby weather
Last synced: 3 months ago
JSON representation
Pure simple Ruby based Dark Sky API gem
- Host: GitHub
- URL: https://github.com/kenjij/darksky-ruby
- Owner: kenjij
- License: mit
- Created: 2017-07-19T16:56:39.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2019-09-09T23:24:21.000Z (over 5 years ago)
- Last Synced: 2024-04-27T08:22:53.825Z (about 1 year ago)
- Topics: api, darksky, gem, ruby, weather
- Language: Ruby
- Homepage:
- Size: 17.6 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# darksky-ruby
[](http://badge.fury.io/rb/darksky-ruby) [](https://codeclimate.com/github/kenjij/darksky-ruby/maintainability)
Pure simple Ruby based [Dark Sky API](https://darksky.net/dev/) gem
## Install
```
$ gem install darksky-ruby
```## Use
### [Forecast Request](https://darksky.net/dev/docs#forecast-request)
Example of querying weather forecast for [SFO](https://www.airport-sfo.com/).
```ruby
require 'darksky-ruby'api = DarkSkyAPI.new(key: 'Your_Dark_Sky_API_Secret_Key')
data = api.forecast(lat: 37.6211, lon: -122.383)
p data[:hourly][:summary]
# => "Partly cloudy throughout the day."
```### [Time Machine Request](https://darksky.net/dev/docs#time-machine-request)
Requesting observed weather for noon of Jan. 1, 2018 at SFO.
```ruby
data = api.timemachine(lat: 37.6211, lon: -122.383, ts: Time.new(2018,1,1,12))
p data[:currently][:temperature]
# => 57.56
```### [Response Format](https://darksky.net/dev/docs#response-format)
`data` in above examples would contain a Ruby Hash of the entire API response; all keys are symbolized.
### Options
You can limit the response data size by excluding unnecessary blocks.
```ruby
api.blocks = {minutely: false, hourly: false} # excludes blocks marked false
api.include_only([:currently, :alerts]) # excludes everything except specified
api.blocks
# => {:currently=>true, :minutely=>false, :hourly=>false, :daily=>false,
# :alerts=>true, :flags=>false}
```Hint, you can use `api.blocks` first to get a default Hash to get started. After you've modified the Hash, you can save it with `api.blocks =`.
Other options can be set like so.
```ruby
api.options = {lang: 'es', units: 'si'} # Spanish language, SI units
data = api.timemachine(lat: 37.6211, lon: -122.383, ts: Time.new(2018,1,1,12))
p data[:currently][:summary]
# => "Parcialmente Nublado"
p data[:currently][:temperature]
# => 14.2
```## CLI
This gem includes an executable as an example.
```
$ darksky -h
darksky [options]
-k, --key= API secret key
-l, --loc= Location (latitude,longtitude)
-o, --log= Log file
-t, --time= Timestamp for Time Machine request
-v, --verbose Verbose mode
-h, --help Show this message
```## More
Since this is a simple gem with no external dependencies, you can directly include the `lib` contents in your project if you prefer not to use Ruby Gems, such as in [AWS Lambda](https://docs.aws.amazon.com/lambda/latest/dg/ruby-package.html). If you do, be sure to include my copyright and license details.