-
Notifications
You must be signed in to change notification settings - Fork 58
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
Improve method return values and scope limiting #59
base: master
Are you sure you want to change the base?
Conversation
Why switch from exported to private on all of these? |
@geekgonecrazy Please correct me if I am wrong, but I cannot see a reason that any user of this SDK or any other package in this library would need to access raw response types. It seems more logical to return a model type and an error compared to a response object with nested model and error. |
Hi, sorry to intrude, I was just going through some other pr and this caught my eye. @evanofslack - if you just return the models, you are misinforming the users about the actual result. For example, the server can return And in the code I don't see the status being checked by the functions themselves either. You could potentially wrap the error like if e := resp.Status.Ok(); e != nil {
return nil, e
} But tbh idk if this is something the sdk should do or the user. There is a distinction right now that makes sense and is easier to comprehend imo. Like for the methods themselves if |
@debdutdeb Thank you for the feedback. Maybe I am misunderstanding but it is my interpretation that the func (c *Client) doRequest(...)
...
bodyBytes, err := ioutil.ReadAll(resp.Body)
var parse bool
if err == nil {
if e := json.Unmarshal(bodyBytes, response); e == nil {
parse = true
}
}
if resp.StatusCode != http.StatusOK {
if parse {
return response.OK()
}
return errors.New("Request error: " + resp.Status)
}
return response.OK() Then in the specific resource methods, we check if this error occurred and return |
I see, my misunderstanding then. Thanks |
evan slack seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
This PR addresses #56
Summary
Existing methods of
client
have been modified to return more concrete types in favor of response types.Other Changes
models
package and into respective files in therest
package.UserStatus
andRoom
in themodels
package.im
andusers
.As some of these are backward incompatible changes, we might want to target a new release to encompass any other additional breaking changes.