diff --git a/.github/workflows/danger.yml b/.github/workflows/danger.yml new file mode 100644 index 0000000..5a4dba5 --- /dev/null +++ b/.github/workflows/danger.yml @@ -0,0 +1,19 @@ +name: PR Linter +on: [pull_request] +jobs: + danger: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: 3.1 + - run: | + # the personal token is public, this is ok, base64 encode to avoid tripping Github + TOKEN=$(echo -n Z2hwX0xNQ3VmanBFeTBvYkZVTWh6NVNqVFFBOEUxU25abzBqRUVuaAo= | base64 --decode) + DANGER_GITHUB_API_TOKEN=$TOKEN bundle exec danger --verbose + diff --git a/.github/workflows/rubocop.yml b/.github/workflows/rubocop.yml new file mode 100644 index 0000000..571aa08 --- /dev/null +++ b/.github/workflows/rubocop.yml @@ -0,0 +1,15 @@ +name: RuboCop +on: [push, pull_request] +jobs: + lint: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Set up Ruby + uses: ruby/setup-ruby@v1 + with: + ruby-version: 3.1 + bundler-cache: true + - name: Run RuboCop + run: bundle exec rubocop + diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..d98b39b --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,26 @@ +name: Tests +on: [push, pull_request] +jobs: + test: + runs-on: ubuntu-latest + strategy: + matrix: + entry: + - { ruby: "2.7" } + - { ruby: "3.0" } + - { ruby: "3.1" } + - { ruby: "3.2" } + - { ruby: ruby-head, ignore: true } + - { ruby: jruby-head, ignore: true } + name: Test (ruby=${{ matrix.entry.ruby }}) + steps: + - uses: actions/checkout@v3 + - name: Install Ruby + uses: ruby/setup-ruby@v1 + with: + bundler-cache: true + ruby-version: ${{ matrix.entry.ruby }} + - name: Run Tests + continue-on-error: ${{ matrix.entry.ignore || false }} + run: bundle exec rspec + diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3552c84..d65d3e8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,21 +1,44 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2020-05-15 23:25:38 -0400 using RuboCop version 0.81.0. +# on 2023-03-20 09:58:58 UTC using RuboCop version 1.48.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. # Offense count: 1 -# Configuration parameters: ExpectMatchingDefinition, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# Configuration parameters: Severity, Include. +# Include: **/*.gemspec +Gemspec/RequiredRubyVersion: + Exclude: + - 'open-weather-ruby-client.gemspec' + +# Offense count: 1 +# This cop supports unsafe autocorrection (--autocorrect-all). +# Configuration parameters: AllowedMethods. +# AllowedMethods: instance_of?, kind_of?, is_a?, eql?, respond_to?, equal? +Lint/RedundantSafeNavigation: + Exclude: + - 'lib/open_weather/endpoints/stations.rb' + +# Offense count: 1 +# Configuration parameters: ExpectMatchingDefinition, CheckDefinitionPathHierarchy, CheckDefinitionPathHierarchyRoots, Regex, IgnoreExecutableScripts, AllowedAcronyms. +# CheckDefinitionPathHierarchyRoots: lib, spec, test, src # AllowedAcronyms: CLI, DSL, ACL, API, ASCII, CPU, CSS, DNS, EOF, GUID, HTML, HTTP, HTTPS, ID, IP, JSON, LHS, QPS, RAM, RHS, RPC, SLA, SMTP, SQL, SSH, TCP, TLS, TTL, UDP, UI, UID, UUID, URI, URL, UTF8, VM, XML, XMPP, XSRF, XSS Naming/FileName: Exclude: - 'lib/open-weather-ruby-client.rb' -# Offense count: 76 -# Cop supports --auto-correct. -# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. +# Offense count: 2 +# This cop supports unsafe autocorrection (--autocorrect-all). +Style/GlobalStdStream: + Exclude: + - 'lib/open_weather/logger.rb' + - 'spec/open_weather/client_spec.rb' + +# Offense count: 7 +# This cop supports safe autocorrection (--autocorrect). +# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, AllowedPatterns. # URISchemes: http, https Layout/LineLength: Max: 181 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 8882f18..0000000 --- a/.travis.yml +++ /dev/null @@ -1,9 +0,0 @@ -language: ruby - -cache: bundler - -rvm: - - 2.6.6 - -before_script: - - bundle exec danger diff --git a/CHANGELOG.md b/CHANGELOG.md index cb1da78..83fd134 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,15 @@ -### 0.2.1 (Next) +### 0.4.1 (Next) +* Your contribution here. + +### 0.4.0 (2023/08/13) + +* [#33](https://github.com/dblock/open-weather-ruby-client/pull/33): Upgrade Faraday to 2.x - [@dgarwood](https://github.com/dgarwood). + +### 0.3.0 (2023/03/25) + +* [#30](https://github.com/dblock/open-weather-ruby-client/pull/30): Added support for Ruby 3.2 - [@petergoldstein](https://github.com/petergoldstein). +* [#27](https://github.com/dblock/open-weather-ruby-client/pull/27): Removed default values for Faraday’s SSL settings ca_file and ca_path - [@sunny](https://github.com/sunny). * [#21](https://github.com/dblock/open-weather-ruby-client/pull/21), [#20](https://github.com/dblock/open-weather-ruby-client/pull/20), [#19](https://github.com/dblock/open-weather-ruby-client/pull/19), [#18](https://github.com/dblock/open-weather-ruby-client/pull/18): Added support for Stations API - [@wasabigeek](https://github.com/wasabigeek). * [#22](https://github.com/dblock/open-weather-ruby-client/pull/23): Removed API version from `Config#endpoint` - [@dblock](https://github.com/dblock). * [#25](https://github.com/dblock/open-weather-ruby-client/pull/25): Exposed the national weather alerts response in the One Call API [@troya2](https://github.com/troya2). diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6a7d61b..e27623d 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -114,7 +114,7 @@ git push origin my-feature-branch -f ### Check on Your Pull Request -Go back to your pull request after a few minutes and see whether it passed muster with Travis-CI. Everything should look green, otherwise fix issues and amend your commit as described above. +Go back to your pull request after a few minutes and see whether it passed muster with GitHub Actions. Everything should look green, otherwise fix issues and amend your commit as described above. ### Be Patient diff --git a/Gemfile b/Gemfile index f83280a..f7200f1 100644 --- a/Gemfile +++ b/Gemfile @@ -3,15 +3,3 @@ source 'http://rubygems.org' gemspec - -group :development, :test do - gem 'danger-changelog', '~> 0.4.2' - gem 'danger-toc', '~> 0.1.3' - gem 'dotenv' - gem 'pry' - gem 'rake' - gem 'rspec' - gem 'rubocop', '~> 0.81.0' - gem 'vcr' - gem 'webmock' -end diff --git a/README.md b/README.md index 01b043e..d098bae 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ OpenWeather Ruby Client ======================= [![Gem Version](https://badge.fury.io/rb/open-weather-ruby-client.svg)](https://badge.fury.io/rb/open-weather-ruby-client) -[![Build Status](https://travis-ci.org/dblock/open-weather-ruby-client.svg?branch=master)](https://travis-ci.org/dblock/open-weather-ruby-client) +[![Tests Status](https://github.com/dblock/open-weather-ruby-client/actions/workflows/test.yml/badge.svg)](https://github.com/dblock/open-weather-ruby-client/actions) A Ruby client for the [OpenWeather API v2.5 and v3.0](https://openweathermap.org/api). diff --git a/RELEASING.md b/RELEASING.md index 9de534a..bda68ae 100644 --- a/RELEASING.md +++ b/RELEASING.md @@ -11,7 +11,7 @@ bundle install rake ``` -Check that the last build succeeded in [Travis CI](https://travis-ci.org/dblock/open-weather-ruby-client) for all supported platforms. +Check that the last build succeeded in GitHub Actions for all supported platforms. Change "Next" in [CHANGELOG.md](CHANGELOG.md) to the current date. diff --git a/UPGRADING.md b/UPGRADING.md new file mode 100644 index 0000000..aaddaaf --- /dev/null +++ b/UPGRADING.md @@ -0,0 +1,15 @@ +Upgrading OpenWeather Ruby Client +================================= + +### Upgrading to >= 0.3.0 + +[#27](https://github.com/dblock/open-weather-ruby-client/pull/27) Removes default values for Faraday's SSL settings `ca_file` and `ca_path`. + +If you previously relied on `OpenSSL::X509::DEFAULT_CERT_FILE` or `OpenSSL::X509::DEFAULT_CERT_DIR` to set these values you must now do so explicitly. E.g.: + +```ruby +OpenWeather::Client.configure do |config| + config.ca_path = OpenSSL::X509::DEFAULT_CERT_DIR + config.ca_file = OpenSSL::X509::DEFAULT_CERT_FILE +end +``` diff --git a/lib/open-weather-ruby-client.rb b/lib/open-weather-ruby-client.rb index a2cab32..41807fe 100644 --- a/lib/open-weather-ruby-client.rb +++ b/lib/open-weather-ruby-client.rb @@ -1,7 +1,8 @@ # frozen_string_literal: true require 'faraday' -require 'faraday_middleware' +require 'faraday/multipart' + require 'json' require 'logger' require 'hashie' diff --git a/lib/open_weather/config.rb b/lib/open_weather/config.rb index bde8814..7a51e29 100644 --- a/lib/open_weather/config.rb +++ b/lib/open_weather/config.rb @@ -24,8 +24,8 @@ def reset self.endpoint = 'https://api.openweathermap.org/data' self.api_key = nil self.user_agent = "OpenWeather Ruby Client/#{OpenWeather::VERSION}" - self.ca_path = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_DIR : nil - self.ca_file = defined?(OpenSSL) ? OpenSSL::X509::DEFAULT_CERT_FILE : nil + self.ca_path = nil + self.ca_file = nil self.proxy = nil self.logger = nil self.timeout = nil diff --git a/lib/open_weather/connection.rb b/lib/open_weather/connection.rb index cdfaa80..74965bc 100644 --- a/lib/open_weather/connection.rb +++ b/lib/open_weather/connection.rb @@ -26,13 +26,12 @@ def connection request_options[:open_timeout] = open_timeout if open_timeout options[:request] = request_options if request_options.any? - ::Faraday::Connection.new(endpoint, options) do |connection| - connection.use ::Faraday::Request::Multipart - connection.use ::Faraday::Request::UrlEncoded - connection.use ::OpenWeather::Response::RaiseError - connection.use ::FaradayMiddleware::ParseJson, content_type: /\bjson$/ - connection.response :logger, logger if logger - connection.adapter ::Faraday.default_adapter + Faraday.new(endpoint, options) do |f| + f.request :multipart + f.request :url_encoded + f.use ::OpenWeather::Response::RaiseError + f.response :json, content_type: /\bjson$/ + f.response :logger, logger if logger end end end diff --git a/lib/open_weather/raise_error.rb b/lib/open_weather/raise_error.rb index 14aa0e7..6677953 100644 --- a/lib/open_weather/raise_error.rb +++ b/lib/open_weather/raise_error.rb @@ -2,7 +2,7 @@ module OpenWeather module Response - class RaiseError < ::Faraday::Response::Middleware + class RaiseError < ::Faraday::Response::RaiseError def on_complete(env) case env[:status] when 404 diff --git a/lib/open_weather/version.rb b/lib/open_weather/version.rb index 575b7e5..999240c 100644 --- a/lib/open_weather/version.rb +++ b/lib/open_weather/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module OpenWeather - VERSION = '0.2.1' + VERSION = '0.4.1' end diff --git a/open-weather-ruby-client.gemspec b/open-weather-ruby-client.gemspec index d12db4c..35cfc19 100644 --- a/open-weather-ruby-client.gemspec +++ b/open-weather-ruby-client.gemspec @@ -17,7 +17,17 @@ Gem::Specification.new do |s| s.licenses = ['MIT'] s.summary = 'OpenWeather API Ruby client.' s.add_dependency 'activesupport' - s.add_dependency 'faraday', '>= 1.0.0' - s.add_dependency 'faraday_middleware' + s.add_dependency 'faraday', '>= 2.0.1' + s.add_dependency 'faraday-multipart' s.add_dependency 'hashie' + + s.add_development_dependency 'danger-changelog', '~> 0.4.2' + s.add_development_dependency 'danger-toc', '~> 0.1.3' + s.add_development_dependency 'dotenv' + s.add_development_dependency 'pry' + s.add_development_dependency 'rake' + s.add_development_dependency 'rspec' + s.add_development_dependency 'rubocop', '~> 1.48.1' + s.add_development_dependency 'vcr' + s.add_development_dependency 'webmock' end diff --git a/spec/open_weather/endpoints/stations_spec.rb b/spec/open_weather/endpoints/stations_spec.rb index 1ad56bb..f25fb22 100644 --- a/spec/open_weather/endpoints/stations_spec.rb +++ b/spec/open_weather/endpoints/stations_spec.rb @@ -114,7 +114,7 @@ } expect(client).to receive(:post) - .with('3.0/measurements', body: [create_params]) + .with('3.0/measurements', { body: [create_params] }) .and_call_original data = client.create_measurements([create_params])