Skip to content

Commit

Permalink
Add list stations endpoint (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
wasabigeek authored Jun 1, 2020
1 parent 79ee36f commit 0a7168f
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
### 0.2.1 (Next)

* Your contribution here.
* [#19](https://github.com/dblock/open-weather-ruby-client/pull/19): Add list_stations endpoint - [@wasabigeek](https://github.com/wasabigeek).
* [#18](https://github.com/dblock/open-weather-ruby-client/pull/18): Add register_station endpoint - [@wasabigeek](https://github.com/wasabigeek).

### 0.2.0 (2020/05/17)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o
- [Historical Weather](#historical-weather)
- [Stations](#stations)
- [Register a Station](#register-a-station)
- [List Stations](#list-stations)
- [Configuration](#configuration)
- [Units](#units)
- [Converting Temperature](#converting-temperature)
Expand Down Expand Up @@ -214,6 +215,13 @@ model.register!
model.id # => '5ed2118acca8ce0001f1aeg1'
```

#### List Stations

To list all stations, you can call the client method:
```ruby
data = client.list_stations # => Array[OpenWeather::Models::Station]
```

## Configuration

You can configure client options, globally.
Expand Down
4 changes: 4 additions & 0 deletions lib/open_weather/endpoints/stations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ module Stations
def register_station(options = {})
OpenWeather::Models::Station.new(post('stations', options))
end

def list_stations
get('stations').map { |data| OpenWeather::Models::Station.new(data) }
end
end
end
end
45 changes: 45 additions & 0 deletions spec/fixtures/open_weather/stations/list_stations_success.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

55 changes: 37 additions & 18 deletions spec/open_weather/endpoints/stations_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,44 @@

require 'spec_helper'

RSpec.describe 'stations' do
RSpec.describe OpenWeather::Endpoints::Stations do
include_context 'API client', endpoint: 'https://api.openweathermap.org/data/3.0'

it 'registers a station', vcr: { cassette_name: 'stations/register_success' } do
data = client.register_station(
external_id: 'SF_TEST001',
name: 'San Francisco Test Station',
latitude: 37.76,
longitude: -122.43,
altitude: 150
)
expect(data).to be_a(OpenWeather::Models::Station)
expect(data).to have_attributes(
id: '5ed21a12cca8ce0001f1aef1',
external_id: 'SF_TEST001',
name: 'San Francisco Test Station',
latitude: 37.76,
longitude: -122.43,
altitude: 150
)
describe '#register_station' do
it 'registers a station', vcr: { cassette_name: 'stations/register_success' } do
data = client.register_station(
external_id: 'SF_TEST001',
name: 'San Francisco Test Station',
latitude: 37.76,
longitude: -122.43,
altitude: 150
)
expect(data).to be_a(OpenWeather::Models::Station)
expect(data).to have_attributes(
id: '5ed21a12cca8ce0001f1aef1',
external_id: 'SF_TEST001',
name: 'San Francisco Test Station',
latitude: 37.76,
longitude: -122.43,
altitude: 150
)
end
end

describe '#list_stations' do
it 'registers a station', vcr: { cassette_name: 'stations/list_stations_success' } do
data = client.list_stations
expect(data).to be_a(Array)
expect(data.size).to eq(2)
expect(data.first).to be_a(OpenWeather::Models::Station)
expect(data.first).to have_attributes(
id: '5ed21311cca8ce0001f1aef0',
external_id: 'SF_TEST001',
name: 'San Francisco Test Station',
latitude: 37.76,
longitude: -122.43,
altitude: 150
)
end
end
end

0 comments on commit 0a7168f

Please sign in to comment.