-
-
Notifications
You must be signed in to change notification settings - Fork 22
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add remaining stations endpoints #20
Changes from 6 commits
a90f274
de1bc07
2914c24
05c6695
536c430
0c91fb6
63463b2
bdbd91b
f9cfb45
6940096
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,6 +23,9 @@ Unlike other clients, including [open-weather](https://github.com/coderhs/ruby_o | |
- [Stations](#stations) | ||
- [Register a Station](#register-a-station) | ||
- [List Stations](#list-stations) | ||
- [Get Station](#get-station) | ||
- [Update Station](#update-station) | ||
- [Delete Station](#delete-station) | ||
- [Configuration](#configuration) | ||
- [Units](#units) | ||
- [Converting Temperature](#converting-temperature) | ||
|
@@ -222,6 +225,33 @@ To list all stations, you can call the client method: | |
data = client.list_stations # => Array[OpenWeather::Models::Station] | ||
``` | ||
|
||
#### Get Station | ||
|
||
To get a stations, you can call the client method: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: remove "you can", it goes without saying :) same below |
||
```ruby | ||
data = client.get_station('5ed2118acca8ce0001f1aeg1') # => OpenWeather::Models::Station | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: because you're not using |
||
``` | ||
|
||
#### Update Station | ||
|
||
To update a station, you can call the client method: | ||
```ruby | ||
data = client.update_station('5ed2118acca8ce0001f1aeg1', external_id: 'SF_TEST002') # => OpenWeather::Models::Station | ||
``` | ||
Alternatively, call `update!` on an instance of `Station`: | ||
```ruby | ||
model = OpenWeather::Models::Station.new(external_id: 'SF_TEST001', ...).register! | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Put |
||
model.update!(external_id: 'SF_TEST002') | ||
model.external_id # => 'SF_TEST002' | ||
``` | ||
|
||
#### Delete Station | ||
|
||
To delete a station, you can call the client method: | ||
```ruby | ||
data = client.delete_station('5ed2118acca8ce0001f1aeg1') # => nil | ||
``` | ||
|
||
## Configuration | ||
|
||
You can configure client options, globally. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,6 +10,19 @@ def register_station(options = {}) | |
def list_stations | ||
get('stations').map { |data| OpenWeather::Models::Station.new(data) } | ||
end | ||
|
||
def get_station(id) | ||
OpenWeather::Models::Station.new(get("stations/#{id}")) | ||
end | ||
|
||
def update_station(id, options = {}) | ||
OpenWeather::Models::Station.new(put("stations/#{id}", options)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure why, but it seems like the API requires There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, I could potentially raise an error if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If a parameter is missing, raise ArgumentError, generally I don't specialize errors unless they can happen on all APIs (e.g. incorrect HTTP proxy) |
||
end | ||
|
||
def delete_station(id) | ||
delete("stations/#{id}") | ||
nil | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dblock what would you suggest to return here? Currently it the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
end | ||
end | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,7 @@ | |
end | ||
|
||
describe '#list_stations' do | ||
it 'registers a station', vcr: { cassette_name: 'stations/list_stations_success' } do | ||
it 'retrieves all stations', vcr: { cassette_name: 'stations/list_stations_success' } do | ||
data = client.list_stations | ||
expect(data).to be_a(Array) | ||
expect(data.size).to eq(2) | ||
|
@@ -42,4 +42,38 @@ | |
) | ||
end | ||
end | ||
|
||
describe '#get_station' do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh I’ve been following this convention http://www.betterspecs.org/#describe (describe for the method under test, context for a scenario) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've been schooled ;) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. They’re aliases so all good either way! |
||
it 'retrieves a station', vcr: { cassette_name: 'stations/get_station_success' } do | ||
data = client.get_station('5ed21311cca8ce0001f1aef0') | ||
expect(data).to be_a(OpenWeather::Models::Station) | ||
expect(data).to have_attributes( | ||
id: '5ed21311cca8ce0001f1aef0', | ||
external_id: 'SF_TEST001', | ||
name: 'San Francisco Test Station', | ||
latitude: 37.76, | ||
longitude: -122.43, | ||
altitude: 150 | ||
) | ||
end | ||
end | ||
|
||
describe '#update_station' do | ||
it 'updates a station', vcr: { cassette_name: 'stations/update_station_success' } do | ||
update_attributes = { | ||
external_id: 'SF_TEST002', | ||
name: 'San Francisco Test Station 2' | ||
} | ||
data = client.update_station('5ed21311cca8ce0001f1aef0', update_attributes) | ||
expect(data).to be_a(OpenWeather::Models::Station) | ||
expect(data).to have_attributes(update_attributes) | ||
end | ||
end | ||
|
||
describe '#delete_station' do | ||
it 'deletes a station', vcr: { cassette_name: 'stations/delete_station_success' } do | ||
data = client.delete_station('5ed21311cca8ce0001f1aef0') | ||
expect(data).to be_nil | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Combine these into
[#20](), [#19](), ...: Add support for weather stations - ...