Skip to content

Commit

Permalink
Remove API version from endpoint.
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock committed Jun 12, 2020
1 parent dbbd6d7 commit 1f55920
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/open_weather/endpoints/current.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -63,15 +63,15 @@ 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)
options = args[-1].is_a?(Hash) ? args.pop.dup : {}
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
Expand Down
2 changes: 1 addition & 1 deletion lib/open_weather/endpoints/one_call.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 7 additions & 7 deletions lib/open_weather/endpoints/stations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/lib/open_weather/models/station_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/open_weather/config/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions spec/open_weather/endpoints/stations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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])
Expand Down

0 comments on commit 1f55920

Please sign in to comment.