Skip to content
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 measurements #21

Merged
merged 22 commits into from
Jun 10, 2020
Merged

Add measurements #21

merged 22 commits into from
Jun 10, 2020

Conversation

wasabigeek
Copy link
Collaborator

Fixes #10

lib/open_weather/endpoints/stations.rb Show resolved Hide resolved
lib/open_weather/request.rb Outdated Show resolved Hide resolved
lib/open_weather/request.rb Outdated Show resolved Hide resolved
spec/open_weather/endpoints/stations_spec.rb Outdated Show resolved Hide resolved
to: 1591620047
)
expect(data.size).to eq(1)
expect(data.first['station_id']).to eq('5ed21a12cca8ce0001f1aef1')
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems like the request / response structures for measurements are somewhat different e.g. wind_speed vs wind: { speed: ... }, I've left it as a raw hash for now. I could make it into a Hashie I suppose?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should make a new structure for anything unique.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There would potentially be two structures then, so OpenWeather::Stations::MeasurementRequest / MeasurementResponse? I could try to normalize the differences, but the response isn't as well documented as the request :/

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should make one, Measurement that would match the response since it's more frequently queried I imagine than sent, and convert into the right hash for requests for the OO model.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've made a best effort one :/ I guessed the properties for some of the "submodels" based on personal testing, but there are some weird ones e.g. I created a measurement with wind_gust and wind_speed, but in the response wind is an empty hash. This makes a OO type model a bit tricky.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine. You should double-check whether such documentation is really missing on their site, then send them an email asking to document the structures.

@wasabigeek wasabigeek marked this pull request as ready for review June 8, 2020 13:14
Copy link
Owner

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be returning and accepting a first class Measurements model, similar to all other models.

lib/open_weather/request.rb Outdated Show resolved Hide resolved
Comment on lines 177 to 179
expect(data.first.precipitation).to be_a(OpenWeather::Models::Stations::Precipitation)
expect(data.first.precipitation).to have_attributes(rain: 2)
expect(data.first.wind).to eq({})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Best guess, see #21 (comment)

Copy link
Owner

@dblock dblock left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very close. Some nitpicks and questions.

README.md Outdated

#### Get Measurements

To get measurements, call the client method with the mandatory parameters:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mandatory -> required

Doesn't look like all these are required, so I'd say "The following parameters are required: ...".

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They are apparently all required, unfortunately >_< https://openweathermap.org/stations#get_measurements

missing_keys = required_keys - options.keys
raise ArgumentError, "Missing params: #{missing_keys.join(', ')}" unless missing_keys.empty?

get('measurements', options).map { |m_hash| OpenWeather::Models::Stations::Measurement.new(m_hash) }
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

m_hash is a weird name, just make it |m| or |h|, since it's a temporary var

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, for a future PR you might want to consider integrating something like dry-types where there's an explicit way to define required arguments and check for them

]
}
data = client.create_measurements([create_params])
expect(data).to be_nil
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have to make sure the API was called, expect a POST to occur, and_call_original to enable the VCR trace

Copy link
Collaborator Author

@wasabigeek wasabigeek Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To clarify, we do this because the nil return is more likely to hide a false positive?

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely

]
}
expect { client.create_measurements([create_params]) }
.to raise_error(OpenWeather::Errors::Fault, /expected=string, got=number/)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an odd error, doesn't tell me that the station was invalid? Should this be a specialized error?

Copy link
Collaborator Author

@wasabigeek wasabigeek Jun 9, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems to be what the API returns, at least with a number:
https://github.com/dblock/open-weather-ruby-client/pull/21/files#diff-9b98e6c2b2b1880dacb9ff685ba9c676R41

Let me try with a string

EDIT: You were right, good catch

spec/open_weather/endpoints/stations_spec.rb Outdated Show resolved Hide resolved
spec/open_weather/endpoints/stations_spec.rb Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@wasabigeek wasabigeek requested a review from dblock June 10, 2020 15:23
@dblock dblock merged commit dbbd6d7 into dblock:master Jun 10, 2020
@dblock
Copy link
Owner

dblock commented Jun 10, 2020

Merged, thank you.

@dblock
Copy link
Owner

dblock commented Jun 10, 2020

I think we need #22 to make this usable. Want to do that one?

@dblock
Copy link
Owner

dblock commented Mar 25, 2023

I released 0.3.0, sorry for the "delay" :)

@wasabigeek
Copy link
Collaborator Author

I only just saw this 🤦 no worries!

@wasabigeek wasabigeek deleted the add-measurements branch June 5, 2023 13:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for weather stations
2 participants