- Sponsor
-
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 measurements #21
Add measurements #21
Conversation
to: 1591620047 | ||
) | ||
expect(data.size).to eq(1) | ||
expect(data.first['station_id']).to eq('5ed21a12cca8ce0001f1aef1') |
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.
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?
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.
You should make a new structure for anything unique.
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.
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 :/
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.
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.
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.
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.
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.
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.
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.
You should be returning and accepting a first class Measurements
model, similar to all other models.
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({}) |
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.
Best guess, see #21 (comment)
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.
Very close. Some nitpicks and questions.
README.md
Outdated
|
||
#### Get Measurements | ||
|
||
To get measurements, call the client method with the mandatory parameters: |
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.
mandatory -> required
Doesn't look like all these are required, so I'd say "The following parameters are required: ...".
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.
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) } |
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.
m_hash is a weird name, just make it |m|
or |h|
, since it's a temporary var
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.
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 |
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.
We have to make sure the API was called, expect a POST
to occur, and_call_original
to enable the VCR trace
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.
To clarify, we do this because the nil
return is more likely to hide a false positive?
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.
Absolutely
] | ||
} | ||
expect { client.create_measurements([create_params]) } | ||
.to raise_error(OpenWeather::Errors::Fault, /expected=string, got=number/) |
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.
This is an odd error, doesn't tell me that the station was invalid? Should this be a specialized error?
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.
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
Merged, thank you. |
I think we need #22 to make this usable. Want to do that one? |
I released 0.3.0, sorry for the "delay" :) |
I only just saw this 🤦 no worries! |
Fixes #10