Dropbox Api v2 - confusion with cursor and paging for list_folders - dropbox-api

The files/list _folders method in api docs has the following for the description of the cursor parameter:
cursor - Pass the cursor into list_folder/continue to see what's changed in the folder since your previous query.
has_more - If true, then there are more entries available. Pass the cursor to list_folder/continue to retrieve the rest.
https://www.dropbox.com/developers/documentation/http/documentation#files-list_folder
Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder? If I am requesting another page of results, what is the limit that was applied? And can I control that?
The docs also have the list_folder method under sharing, which appears to have more precise definition of the cursor and the support for the limit parameter
https://www.dropbox.com/developers/documentation/http/documentation#sharing-list_folders
Will the method under files have that too?

Which is it then? If I make another request to list_folders_continue passing in the token, am I requesting another page of results or changes to the folder?
It's both. The /files/list_folder/continue endpoint is used both for returning additional pages of items, as well as getting further updates in the future.
Each page returned by /files/list_folder[/continue] is limited in size, but there is no guaranteed limit, nor can you control that limit. Your app should just always check has_more and call back to /files/list_folder/continue if it is true.
Also, the endpoints /files/list_folder and /sharing/list_folders are different endpoints with different functionality.
The /files/list_folder endpoint is documented as:
Returns the contents of a folder.
The /sharing/list_folders endpoint is documented as:
Return the list of all shared folders the current user has access to.
The two endpoints use different cursors, for use with /files/list_folder/continue and /sharing/list_folders/continue, respectively.

Which is it then? If I make another request to list_folders_continue
passing in the token, am I requesting another page of results or
changes to the folder? If I am requesting another page of results,
what is the limit that was applied? And can I control that?
My own trial and error experimentation has determined that the "It's both" answer posted by Greg is not correct. Specifically, the correct answer is "it's either". See below for more details.
When you call files/list_folder and it returns the entire list of contents (with a has_more value of false), then the cursor returned is suitable for monitoring subsequent changes to the path specified by passing that cursor to files/list_folder/continue.
If files/list_folder returns the first of multiple pages of contents (with a has_more value of true), then the cursor returned is suitable for getting the next page of contents by passing it to files/list_folder/continue. This cursor is not suitable for monitoring for changes (try it yourself, you can call continue as many times as you want with that cursor and you will always get the second page of contents).
It's not entirely clear from the docs, but when getting pages of contents from files/list_folder/continue, each call will return a new cursor, and that new cursor must be passed to a subsequent call to files/list_folder/continue in order to get the next page. You must chain the cursors together in this way until you get the last page (where has_more is false).
The cursor returned in that last call to files/list_folder/continue can then be used in subsequent calls to files/list_folder/continue to monitor for changes to the original path specified in the very first call to files/list_folder.
So the cursor is either suitable for monitoring for changes (when it is returned with a has_more value of false) OR it is suitable for getting a subsequent page of contents (when it is returned with a has_more value of true), regardless of whether the call that produced the cursor was files/list_folder or files/list_folder/continue, but it is never both.

Related

Is it possible to move the location pointer up or down with MS Word Javascript API

I am currently working on a plugin which will take voice commands and upon receiving a response from the server, act accordingly. For example if i say "delete word", the last word will be deleted. I want to be able to move the pointer left/right/up one line/down one line. Does Word Javascript API provide a way to achieve this?
There are no cursor movement APIs. But there are methods on the Paragraph object for getting the previous paragraph and the next paragraph. There are also ways to move among Ranges, if you can get a collection or an array of the ranges that you want to move around. And you can find the AdjacentAfter and AdjacentBefore ranges using the Range.compareLocationWith method. The Range object also has getNextRange and getNextRangeOrNullObject methods. Finally, the Range.select("Start") and Range.select("End") will put the cursor just before/after the current selected range.

How can I get all Actions for a Board using Trello's Rest API?

I want to get all the actions for a board, but Trello limits the results to 1000. I understand the correct way to deal with this is to paginate. I've tried both before and page as keywords:
Basic Call:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000
Alternatives:
Before:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
before=[oldest_returned_action's_date]
Page:
https://api.trello.com/1/board/[boardID]/
?key=[key]&token=[token]
&actions=commentCard&actions_limit=1000&
page=[page_number]
The result never varies --- I always get back [limit] number of actions, and they're always the same no matter the call. I checked the dates in what was returned and they certainly don't respect the before parameter. I even tried lowering the limit to make sure I wasn't trying to return more than I possessed. The problem persists.
How can I correctly get all actions for a Trello board?
Actions are in reverse chronological order (newest-to-oldest), so to page through the actions on a board, you would use something like:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000"
then, from the last element of the array returned by the the above, select the date or id and pass that as the before parameter in the next call, e.g.:
curl "https://api.trello.com/1/boards/${BOARD_ID}/actions/?key=${TRELLO_API_KEY}&token=${TRELLO_TOKEN}&limit=1000&before=${DATE_OR_ID_OF_LAST_ACTION}"
and repeat, passing in either the id or date of the last action as the subsequent before parameter.
References:
Paging
Board Actions
Actions Nested Resource

How to filter by both text and property in Chrome DevTool's network panel?

I want to filter Chrome DevTool's network panel by the method property and text in the URL. For example, if I am searching for the text chromequestion in the URL and only HTTP GET requests (ignore PUT, POST, DELETE, etc).
I am able to filter by text or by method:
I am not able to combine the filter to search by both text and method:
I read the documentation at https://developers.google.com/web/tools/chrome-devtools/network-performance/reference#filters and I am able to filter by multiple properties (.e.g, domain:*.com method:GET). However, I am unable to filter by text and property (e.g., method:GET chromequestion).
Unfortunately, it's not possible to do this currently. I played around in DevTools originally, but couldn't find a way. I later had a look into how the filtering was implemented, and can confirm there's a limitation preventing you from mixing the pre-defined filters and text filters.
Implementation details
This is a bit long but I thought it might be interesting for some to see how it's implemented. I will probably look into improving the implementation, either myself or I'll log it because it's limited.
There's a _parseFilterQuery function that parses the input field and categorises the entries into two arrays. The first is called filters, and it's the pre-defined filtering options, such as method:GET etc. The second is a text array filter, split up by spaces. The parser determines the difference fairly naively, by checking for the occurrence of :, and - at the start (for negation).
Scenario 1
You only input a pre-defined filter, or multiple filters. For each filter, the specific filter function, which looks at the different properties of the request object, is pushed to a network module filters array (this._filters). Later on, for each request, the function is called on it, and a match returns true, otherwise false. This will determine whether the request is shown. There's obviously a requirement for ALL filters to return true for the row to show.
Scenario 2
This is the interesting one, where you input both a pre-defined filter and a bit of text. This covers the Stack Overflow question. The _parseFilterQuery function looks at the text filters first, before the pre-defined ones. In Scenario 1, this was empty, so it was skipped.
We pass each text word to the _createTextFilter, and push each of the resulting filters to the network module filters array. However, the implementation of this is questionable. The only time the actual word passed in is used is to check whether its a negation filter for a bit of text. If the first character is -, it means the user doesn't want to see a request with the following word in the name. For example -icon means don't show any request with that in the name/page. If there is no negation, it simply returns the WHOLE input text as a regular expression, NOT the word passed in. In my case, it returns /method:GET icon/i.
The pre-defined filters are looked at next. In this case, method:GET is pushed.
Finally, it loops over the requests calling each filter on it. However, since the first filter is /method:GET icon/i, it makes ALL other filters redundant because it will NEVER pass. The text filters only apply to name and path, so method:GET in a text filter will be invalid.

Visual Studio Code Api: Get active signature

I develop language-extension with SignatureHelpProvider.
Some functions have several signatures, so I push several SignatureInfo to SignatureHelp.signatures array.
The problem is - how to get current active signature selected by user?
Current realization switches the activeSingature to 0 every time User types a character.
Also in vscode >=1.6 you must set an activeSingature to some value - otherwise the hint mini-window won't pop up.
Any ideas how to get this work properly?
It's up to you to decide which signature you want to set to active for your user.
It might for example be the one with fewer parameters that satisfies your activeParameter. It's your call as an extension developer.
When he types a character, you are probably invoking the signatureHelpProvider (with your trigger characters) and that's reseting activeSignature back to 0.

Redirect in around filter after action has been yielded

I'm using an around filter which on certain occasions should redirect user to other path AFTER an action has been yielded (either ending with render or redirect).
Writing redirect_to in around filter after yield statement results in double render error. Trying to "reconfigure" response object (by setting body to nil and location header to desired url) results in folloing error (taken from controller specs):
Failure/Error: Unable to find matching line from backtrace
You have a nil object when you didn't expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Has anybody done anything similar to this?
actually I manged to do redirect in around filter after action has been yielded. You just have to redefine the response.location attribute and reset the response.status to 302 (instead of 200).
You can't yield and then redirect/render afterwards. If you need to use some of the logic in the controller action in your around filter, consider moving that logic to a before_filter, or the first block of your around filter so that its available both in the around filter to determine what to do (redirect, or otherwise yield), and also available to the action you will be yielding to