diff --git a/CHANGELOG.md b/CHANGELOG.md index 83b2236..84f81d6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,8 @@ ### 0.2.1 (Next) -* Your contribution here. * [#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). +* Your contribution here. ### 0.2.0 (2020/05/17) diff --git a/README.md b/README.md index ba94852..c7573d9 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,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) -A Ruby client for the [OpenWeather API v2.5](https://openweathermap.org/api). +A Ruby client for the [OpenWeather API v2.5 and v3.0](https://openweathermap.org/api). Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_open_weather_map), provides a rich first class interface to OpenWeather models, structured timestamps, built-in metrics conversion for temperature and wind speed, offers more consistent error handling, and is implemented with thorough test coverage using actual OpenWeather data. @@ -309,7 +309,7 @@ setting | description api_key | Required API key. lang | Default language in API responses. units | Default units in API responses. -endpoint | Defaults to `https://api.openweathermap.org/data/2.5/`. +endpoint | Defaults to `https://api.openweathermap.org/data`. user_agent | User-agent, defaults to _OpenWeather Ruby Client/version_. proxy | Optional HTTP proxy. ca_path | Optional SSL certificates path. diff --git a/lib/open_weather/config.rb b/lib/open_weather/config.rb index c2a8861..bde8814 100644 --- a/lib/open_weather/config.rb +++ b/lib/open_weather/config.rb @@ -21,7 +21,7 @@ module Config attr_accessor(*Config::ATTRIBUTES) def reset - self.endpoint = 'https://api.openweathermap.org/data/2.5' + 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 diff --git a/lib/open_weather/endpoints/current.rb b/lib/open_weather/endpoints/current.rb index 40a02db..cebb705 100644 --- a/lib/open_weather/endpoints/current.rb +++ b/lib/open_weather/endpoints/current.rb @@ -38,7 +38,7 @@ def current_weather(options = {}) options.delete(:country) ].compact.join(',') end - OpenWeather::Models::City::Weather.new(get('weather', options), options) + OpenWeather::Models::City::Weather.new(get('2.5/weather', options), options) end def current_cities_geo_box(*args) @@ -51,7 +51,7 @@ def current_cities_geo_box(*args) options.delete(:lat_top), options.delete(:zoom) ].join(',') - OpenWeather::Models::List.new(get('box/city', options), options) + OpenWeather::Models::List.new(get('2.5/box/city', options), options) end def current_cities_geo_circle(*args) @@ -63,7 +63,7 @@ def current_cities_geo_circle(*args) options[:cnt] = args.shift || 1 end - OpenWeather::Models::List.new(get('find', options), options) + OpenWeather::Models::List.new(get('2.5/find', options), options) end def current_cities_id(*args) @@ -71,7 +71,7 @@ def current_cities_id(*args) options[:id] = args.join(',') if args.any? options[:id] = options.delete(:ids) if options.key?(:ids) options[:id] = options[:id].join(',') if options[:id].is_a?(Array) - OpenWeather::Models::List.new(get('group', options), options) + OpenWeather::Models::List.new(get('2.5/group', options), options) end end end diff --git a/lib/open_weather/endpoints/one_call.rb b/lib/open_weather/endpoints/one_call.rb index 5009793..33b0f0f 100644 --- a/lib/open_weather/endpoints/one_call.rb +++ b/lib/open_weather/endpoints/one_call.rb @@ -7,7 +7,7 @@ def one_call(lat, lon = nil, options = {}) options = lat.is_a?(Hash) ? options.merge(lat) : options.merge(lat: lat, lon: lon) options[:exclude] = options[:exclude].join(',') if options[:exclude].is_a?(Array) options[:dt] = options[:dt].to_i if options[:dt].is_a?(Time) - path = options.key?(:dt) ? 'onecall/timemachine' : 'onecall' + path = options.key?(:dt) ? '2.5/onecall/timemachine' : '2.5/onecall' OpenWeather::Models::OneCall::Weather.new(get(path, options), options) end end diff --git a/lib/open_weather/endpoints/stations.rb b/lib/open_weather/endpoints/stations.rb index a951213..b3ba880 100644 --- a/lib/open_weather/endpoints/stations.rb +++ b/lib/open_weather/endpoints/stations.rb @@ -4,34 +4,34 @@ module OpenWeather module Endpoints module Stations def register_station(options = {}) - OpenWeather::Models::Station.new(post('stations', options)) + OpenWeather::Models::Station.new(post('3.0/stations', options)) end def list_stations - get('stations').map { |data| OpenWeather::Models::Station.new(data) } + get('3.0/stations').map { |data| OpenWeather::Models::Station.new(data) } end def get_station(id) validate_id(id) - OpenWeather::Models::Station.new(get("stations/#{id}")) + OpenWeather::Models::Station.new(get("3.0/stations/#{id}")) end def update_station(id, options = {}) validate_id(id) - OpenWeather::Models::Station.new(put("stations/#{id}", options)) + OpenWeather::Models::Station.new(put("3.0/stations/#{id}", options)) end def delete_station(id) validate_id(id) - delete("stations/#{id}") + delete("3.0/stations/#{id}") nil end def create_measurements(measurements, options = {}) - post('measurements', options.merge(body: measurements)) + post('3.0/measurements', options.merge(body: measurements)) nil end @@ -40,7 +40,7 @@ def get_measurements(options) missing_keys = required_keys - options.keys raise ArgumentError, "Missing params: #{missing_keys.join(', ')}" if missing_keys.any? - get('measurements', options).map { |m| OpenWeather::Models::Stations::Measurement.new(m) } + get('3.0/measurements', options).map { |m| OpenWeather::Models::Stations::Measurement.new(m) } end private diff --git a/spec/lib/open_weather/models/station_spec.rb b/spec/lib/open_weather/models/station_spec.rb index 6fed6b7..a4f78fc 100644 --- a/spec/lib/open_weather/models/station_spec.rb +++ b/spec/lib/open_weather/models/station_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe OpenWeather::Models::Station do - include_context 'API client', endpoint: 'https://api.openweathermap.org/data/3.0' + include_context 'API client' describe '.register!' do let(:create_attributes) do diff --git a/spec/open_weather/config/config_spec.rb b/spec/open_weather/config/config_spec.rb index 0145024..34f9e34 100644 --- a/spec/open_weather/config/config_spec.rb +++ b/spec/open_weather/config/config_spec.rb @@ -8,7 +8,7 @@ end describe '#defaults' do it 'sets endpoint' do - expect(OpenWeather.config.endpoint).to eq 'https://api.openweathermap.org/data/2.5' + expect(OpenWeather.config.endpoint).to eq 'https://api.openweathermap.org/data' end end describe '#configure' do diff --git a/spec/open_weather/endpoints/stations_spec.rb b/spec/open_weather/endpoints/stations_spec.rb index 4be7d04..1ad56bb 100644 --- a/spec/open_weather/endpoints/stations_spec.rb +++ b/spec/open_weather/endpoints/stations_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe OpenWeather::Endpoints::Stations do - include_context 'API client', endpoint: 'https://api.openweathermap.org/data/3.0' + include_context 'API client' describe '#register_station' do it 'registers a station', vcr: { cassette_name: 'stations/register_success' } do @@ -114,7 +114,7 @@ } expect(client).to receive(:post) - .with('measurements', body: [create_params]) + .with('3.0/measurements', body: [create_params]) .and_call_original data = client.create_measurements([create_params])