pirate_weather_forecast_ruby 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.devcontainer/devcontainer.json +22 -0
- data/.github/workflows/main.yml +27 -0
- data/.gitignore +18 -0
- data/.rspec +3 -0
- data/.rubocop.yml +23 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/CHANGELOG.md +5 -0
- data/Gemfile +12 -0
- data/LICENSE +21 -0
- data/README.md +90 -0
- data/Rakefile +18 -0
- data/bin/console +15 -0
- data/bin/setup +8 -0
- data/lib/pirate_weather_forecast_ruby/configuration.rb +47 -0
- data/lib/pirate_weather_forecast_ruby/version.rb +5 -0
- data/lib/pirate_weather_forecast_ruby.rb +50 -0
- data/pirate_weather_forecast_ruby.gemspec +33 -0
- data/sig/pirate_weather_forecast_ruby.rbs +4 -0
- data/spec/cassettes/.keep +0 -0
- data/spec/cassettes/forecast_for_latitude_longitude.yml +385 -0
- data/spec/cassettes/forecast_for_latitude_longitude_and_query_params.yml +391 -0
- data/spec/cassettes/forecast_for_latitude_longitude_and_time.yml +47 -0
- data/spec/pirate_weather_forecast_ruby/configuration_spec.rb +15 -0
- data/spec/pirate_weather_forecast_ruby/pirate_weather_forecast_ruby_spec.rb +115 -0
- data/spec/pirate_weather_forecast_ruby/version_spec.rb +8 -0
- data/spec/spec_helper.rb +23 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 607191d92bac7b13f41e405eb6e7bdfcdb4907f53ad6136c1c17767304f0251b
|
4
|
+
data.tar.gz: 39fec03a81d4a2af78b44ba9f74b05c2653a2dbc81aab02e37c00642ff36c1cf
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3037f44e1b656f68170df5ff4508d326b693b8db5712bd737e1a56c6ae5256f75a771f5614274d749e1d245cb871c8e344249c32d9bbe08b74772c39109960e7
|
7
|
+
data.tar.gz: a7751e814b6e7b322a9a2037454003b2d7485e9559fda9c3d5680693ee5f1d9fbf2d6b0db536c2ab05dcbaa05257d0ae59018f2b2426852a44966b338c128a3d
|
@@ -0,0 +1,22 @@
|
|
1
|
+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
|
2
|
+
// README at: https://github.com/devcontainers/templates/tree/main/src/ruby
|
3
|
+
{
|
4
|
+
"name": "Ruby",
|
5
|
+
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
|
6
|
+
"image": "mcr.microsoft.com/devcontainers/ruby:1-3.2-bullseye",
|
7
|
+
|
8
|
+
// Features to add to the dev container. More info: https://containers.dev/features.
|
9
|
+
// "features": {},
|
10
|
+
|
11
|
+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
12
|
+
// "forwardPorts": [],
|
13
|
+
|
14
|
+
// Use 'postCreateCommand' to run commands after the container is created.
|
15
|
+
// "postCreateCommand": "ruby --version",
|
16
|
+
|
17
|
+
// Configure tool-specific properties.
|
18
|
+
// "customizations": {},
|
19
|
+
|
20
|
+
// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
|
21
|
+
"remoteUser": "root"
|
22
|
+
}
|
@@ -0,0 +1,27 @@
|
|
1
|
+
name: Ruby
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches:
|
6
|
+
- main
|
7
|
+
|
8
|
+
pull_request:
|
9
|
+
|
10
|
+
jobs:
|
11
|
+
build:
|
12
|
+
runs-on: ubuntu-latest
|
13
|
+
name: Ruby ${{ matrix.ruby }}
|
14
|
+
strategy:
|
15
|
+
matrix:
|
16
|
+
ruby:
|
17
|
+
- '3.2.2'
|
18
|
+
|
19
|
+
steps:
|
20
|
+
- uses: actions/checkout@v3
|
21
|
+
- name: Set up Ruby
|
22
|
+
uses: ruby/setup-ruby@v1
|
23
|
+
with:
|
24
|
+
ruby-version: ${{ matrix.ruby }}
|
25
|
+
bundler-cache: true
|
26
|
+
- name: Run the default task
|
27
|
+
run: bundle exec rake
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 3.2.2
|
3
|
+
|
4
|
+
Style/StringLiterals:
|
5
|
+
Enabled: true
|
6
|
+
EnforcedStyle: double_quotes
|
7
|
+
|
8
|
+
Style/StringLiteralsInInterpolation:
|
9
|
+
Enabled: true
|
10
|
+
EnforcedStyle: double_quotes
|
11
|
+
|
12
|
+
Layout/LineLength:
|
13
|
+
Max: 120
|
14
|
+
|
15
|
+
# TODO: remove + fix code to pass everything
|
16
|
+
Metrics/BlockLength:
|
17
|
+
Enabled: false
|
18
|
+
|
19
|
+
# TODO: remove + fix code to pass everything
|
20
|
+
Style/Documentation:
|
21
|
+
Enabled: false
|
22
|
+
|
23
|
+
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pirate_weather_forecast_ruby
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
3.2.2
|
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
source "https://rubygems.org"
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in pirate_weather_forecast_ruby.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
gem "dotenv-rails", groups: %i[development test]
|
9
|
+
|
10
|
+
gem "rake", "~> 13.0"
|
11
|
+
|
12
|
+
gem "rubocop", "~> 1.21"
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2023 Alex Cochran
|
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,90 @@
|
|
1
|
+
# pirate_weather_forecast_ruby
|
2
|
+
|
3
|
+
[![Workflow: Ruby](https://github.com/alexcochran/pirate-weather-forecast-ruby/actions/workflows/main.yml/badge.svg)](https://github.com/alexcochran/pirate-weather-forecast-ruby/actions/workflows/main.yml)
|
4
|
+
|
5
|
+
[Pirate Weather forecast.io](https://pirateweather.net/en/latest/) API wrapper in Ruby, forked from
|
6
|
+
[Dark Sky's forecast.io](https://github.com/darkskyapp/forecast-ruby).
|
7
|
+
|
8
|
+
Pirate Weather aims to be a drop-in replacement for Apple's (now) non-free Dark Sky API. Similarly, this
|
9
|
+
project's goal is to provide a drop-in replacement for the [Ruby Dark Sky API wrapper](https://github.com/darkskyapp/forecast-ruby).
|
10
|
+
|
11
|
+
---
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
`gem install pirate_weather_forecast_ruby`
|
16
|
+
|
17
|
+
or in your `Gemfile`
|
18
|
+
|
19
|
+
```ruby
|
20
|
+
gem 'pirate_weather_forecast_ruby'
|
21
|
+
```
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
Make sure you require the library.
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
require 'pirate_weather_forecast_ruby'
|
29
|
+
```
|
30
|
+
|
31
|
+
You need to set an API key before you can make requests to the API. Grab one from
|
32
|
+
[Pirate Weather](https://pirateweather.net/en/latest/).
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
ForecastIO.configure do |configuration|
|
36
|
+
configuration.api_key = 'this-is-your-api-key'
|
37
|
+
end
|
38
|
+
```
|
39
|
+
|
40
|
+
Alternatively:
|
41
|
+
|
42
|
+
```ruby
|
43
|
+
ForecastIO.api_key = 'this-is-your-api-key'
|
44
|
+
```
|
45
|
+
|
46
|
+
You can then make requests to the `ForecastIO.forecast(latitude, longitude, options = {})` method.
|
47
|
+
|
48
|
+
Valid options in the `options` hash are:
|
49
|
+
|
50
|
+
* `:time` - Unix time in seconds.
|
51
|
+
* `:params` - Query parameters that can contain the following:
|
52
|
+
* `:jsonp` - JSONP callback.
|
53
|
+
* `:units` - Return the API response in SI units, rather than the default Imperial units.
|
54
|
+
* `:exclude` - "Exclude some number of data blocks from the API response. This is useful for reducing latency and saving cache space. [blocks] should be a comma-delimeted list (without spaces) of any of the following: currently, minutely, hourly, daily, alerts, flags." (via Dark Sky's [v2 docs](https://developer.forecast.io/docs/v2#changelog))
|
55
|
+
|
56
|
+
Get the current forecast:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
forecast = ForecastIO.forecast(37.8267, -122.423)
|
60
|
+
```
|
61
|
+
|
62
|
+
Get the current forecast at a given time:
|
63
|
+
|
64
|
+
```ruby
|
65
|
+
forecast = ForecastIO.forecast(37.8267, -122.423, time: Time.new(2013, 3, 11).to_i)
|
66
|
+
```
|
67
|
+
|
68
|
+
Get the current forecast and use SI units:
|
69
|
+
|
70
|
+
```ruby
|
71
|
+
forecast = ForecastIO.forecast(37.8267, -122.423, params: { units: 'si' })
|
72
|
+
```
|
73
|
+
|
74
|
+
The `forecast(...)` method will return a response that you can interact with in a more-friendly way, such as:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
forecast = ForecastIO.forecast(37.8267, -122.423)
|
78
|
+
forecast.latitude
|
79
|
+
forecast.longitude
|
80
|
+
```
|
81
|
+
|
82
|
+
---
|
83
|
+
|
84
|
+
## Contributing
|
85
|
+
|
86
|
+
⏳
|
87
|
+
|
88
|
+
## [License](./LICENSE)
|
89
|
+
|
90
|
+
Copyright (c) 2023 Alex Cochran
|
data/Rakefile
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "bundler/gem_tasks"
|
4
|
+
require "rake"
|
5
|
+
require "rspec/core/rake_task"
|
6
|
+
require "rubocop/rake_task"
|
7
|
+
|
8
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
9
|
+
spec.pattern = "spec/**/*_spec.rb"
|
10
|
+
spec.rspec_opts = ["--backtrace"]
|
11
|
+
# spec.ruby_opts = ['-w']
|
12
|
+
end
|
13
|
+
|
14
|
+
task default: :spec
|
15
|
+
|
16
|
+
RuboCop::RakeTask.new
|
17
|
+
|
18
|
+
task default: :rubocop
|
data/bin/console
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require "bundler/setup"
|
5
|
+
require "pirate_weather_forecast_ruby"
|
6
|
+
|
7
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
8
|
+
# with your gem easier. You can also use a different console, if you like.
|
9
|
+
|
10
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
11
|
+
# require "pry"
|
12
|
+
# Pry.start
|
13
|
+
|
14
|
+
require "irb"
|
15
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ForecastIO
|
4
|
+
module Configuration
|
5
|
+
# Default API endpoint
|
6
|
+
DEFAULT_FORECAST_IO_API_ENDPOINT = "https://api.pirateweather.net"
|
7
|
+
|
8
|
+
# Forecast API endpoint
|
9
|
+
attr_writer :api_endpoint
|
10
|
+
|
11
|
+
# API key
|
12
|
+
attr_writer :api_key
|
13
|
+
|
14
|
+
# Request read timeout
|
15
|
+
attr_writer :timeout
|
16
|
+
|
17
|
+
# Default parameters
|
18
|
+
attr_accessor :default_params
|
19
|
+
|
20
|
+
# Yield self to be able to configure ForecastIO with block-style configuration.
|
21
|
+
#
|
22
|
+
# Example:
|
23
|
+
#
|
24
|
+
# ForecastIO.configure do |configuration|
|
25
|
+
# configuration.api_key = 'this-is-your-api-key'
|
26
|
+
# configuration.timeout = 500
|
27
|
+
# end
|
28
|
+
def configure
|
29
|
+
yield self
|
30
|
+
end
|
31
|
+
|
32
|
+
# API endpoint
|
33
|
+
def api_endpoint
|
34
|
+
@api_endpoint ||= DEFAULT_FORECAST_IO_API_ENDPOINT
|
35
|
+
end
|
36
|
+
|
37
|
+
# API key
|
38
|
+
def api_key
|
39
|
+
@api_key
|
40
|
+
end
|
41
|
+
|
42
|
+
# Request read timeout
|
43
|
+
def timeout
|
44
|
+
@timeout
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative "pirate_weather_forecast_ruby/configuration"
|
4
|
+
require_relative "pirate_weather_forecast_ruby/version"
|
5
|
+
|
6
|
+
require "hashie"
|
7
|
+
require "multi_json"
|
8
|
+
require "faraday"
|
9
|
+
|
10
|
+
module ForecastIO
|
11
|
+
extend Configuration
|
12
|
+
|
13
|
+
self.default_params = {}
|
14
|
+
|
15
|
+
class << self
|
16
|
+
# Retrieve the forecast for a given latitude and longitude.
|
17
|
+
#
|
18
|
+
# @param latitude [String] Latitude.
|
19
|
+
# @param longitude [String] Longitude.
|
20
|
+
# @param options [String] Optional parameters. Valid options are `:time` and `:params`.
|
21
|
+
def forecast(latitude, longitude, options = {})
|
22
|
+
forecast_url = "#{ForecastIO.api_endpoint}/forecast/#{ForecastIO.api_key}/#{latitude},#{longitude}"
|
23
|
+
forecast_url += ",#{options[:time]}" if options[:time]
|
24
|
+
|
25
|
+
forecast_response = get(forecast_url, options[:params])
|
26
|
+
|
27
|
+
return unless forecast_response.success?
|
28
|
+
|
29
|
+
Hashie::Mash.new(MultiJson.load(forecast_response.body))
|
30
|
+
end
|
31
|
+
|
32
|
+
# Build or get an HTTP connection object.
|
33
|
+
def connection
|
34
|
+
@connection ||= Faraday.new(request: { timeout: ForecastIO.timeout })
|
35
|
+
end
|
36
|
+
|
37
|
+
# Set an HTTP connection object.
|
38
|
+
#
|
39
|
+
# @param connection Connection object to be used.
|
40
|
+
attr_writer :connection
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def get(path, params = {})
|
45
|
+
params = ForecastIO.default_params.merge(params || {})
|
46
|
+
|
47
|
+
connection.get(path, params)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
$LOAD_PATH.push File.expand_path("lib", __dir__)
|
4
|
+
|
5
|
+
require_relative "lib/pirate_weather_forecast_ruby/version"
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = "pirate_weather_forecast_ruby"
|
9
|
+
spec.version = ForecastIO::VERSION
|
10
|
+
spec.authors = ["Alex Cochran"]
|
11
|
+
spec.email = ["acochran50@gmail.com"]
|
12
|
+
spec.homepage = "https://github.com/alexcochran/pirate-weather-forecast-ruby"
|
13
|
+
spec.summary = "forecast.io API wrapper in Ruby"
|
14
|
+
spec.description = "forecast.io API wrapper in Ruby"
|
15
|
+
|
16
|
+
spec.required_ruby_version = ">= 3.2.2"
|
17
|
+
|
18
|
+
spec.rubyforge_project = "pirate_weather_forecast_ruby"
|
19
|
+
|
20
|
+
spec.files = `git ls-files`.split("\n")
|
21
|
+
spec.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
22
|
+
spec.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
23
|
+
spec.require_paths = ["lib"]
|
24
|
+
|
25
|
+
spec.add_dependency("faraday")
|
26
|
+
spec.add_dependency("hashie")
|
27
|
+
spec.add_dependency("multi_json")
|
28
|
+
|
29
|
+
spec.add_development_dependency("faraday-typhoeus")
|
30
|
+
spec.add_development_dependency("rake")
|
31
|
+
spec.add_development_dependency("rspec")
|
32
|
+
spec.add_development_dependency("vcr")
|
33
|
+
end
|
File without changes
|