-
Notifications
You must be signed in to change notification settings - Fork 5
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 API to change entries #5
Comments
In wallabako, I did this through a more generic doAPI request: // doAPI sends an arbitrary API call to the Wallabag API, getting a
// new token in the process. it returns the body of the response in
// bytes and any possible errors returned by the API, particularly if
// the returned status code is not 200.
func doAPI(method string, url string, body io.Reader) (data []byte, err error) {
// this is copied from getBodyOfAPIURL(), should probably be
// factored out
client := &http.Client{}
req, err := http.NewRequest(method, url, body)
req.Header.Add("Authorization", wallabago.GetAuthTokenHeader())
resp, err := client.Do(req)
if err != nil {
return data, err
}
defer resp.Body.Close()
data, err = ioutil.ReadAll(resp.Body)
if resp.StatusCode != 200 {
return data, fmt.Errorf("error from the API: %s", resp.Status)
}
return data, err
} (Notice how I pass up the errors instead of printing them right away? That would be a welcome addition elsewhere in the API, btw...) It's not very pretty, but it works - i use it like this to mark articles as read: func markAsRead(id int) (err error) {
log.Printf("marking entry %d as read", id)
tmp := map[string]string{"archive": "1"}
body, _ := json.Marshal(tmp)
_, err = doAPI("PATCH", wallabago.Config.WallabagURL+"/api/entries/"+strconv.Itoa(id)+".json", bytes.NewBuffer(body))
return err
} |
This looks good to me. Now, the doAPI() needs to be integrated in the utils and the getBodyOfAPIURL() and postToAPI() need to be reworked to make use of the new doAPI(). Passing up the errors, since this a lib, absolutely makes sense. I could do that. But not today anymore. If you want, i would appreciate a pull request. |
yes. i think this all needs to be reshuffled... #4 is necessary insofar as I need to build my own requests - if the API was more flexible, i wouldn't quite need it as much (but i still think it's useful to have it there)... honestly, at this point, i would rather let you finish the job, since i see you are already refactoring the code and adding functionality... i don't want another conflicting change. ;) |
note - the doAPI code changed slightly... i would also recommend to call the function just |
the doAPI code changed again, for the record, just some small changes to return value semantics (avoid crashing on error, for example). |
different types of http methods should be possible since commit 3fd8d89 |
thanks! i cannot, however, directly use the API as-is, as there are a few things missing:
should i open separate issues or pull requests for those? thanks! |
If you could open a PR, that would be cool. Otherwise i would try to integrate your feedback. |
the easiest is probably step 3, for which i can send a PR. for step 1 and 2, i'm not sure what to do: maybe a callback for debug output? for headings, i guess we could pass a list or something... ideas? |
for 1 i suggest adding a contentType parameter to the APICall(). If i have some time again i am going to implement the DELETE, PUT and PATCH calls, too. Maybe there is a better common way i did not think about yet. for 2 i have no idea yet for 3 i welcome your PR regarding 4 i would leave the code as it currently is. |
I would need to set read status and similar settings through the API. This is not currently possible as we can only do
GET
requests. I would need to doPATCH
requests. As a workaround, I have implemented a patch that allows me to generate new access tokens in #4 - but that's not ideal.The text was updated successfully, but these errors were encountered: