AndyCW / MovesenseDotNet

Movesense .NET SDK for Xamarin Android and Xamarin iOS
MIT License
16 stars 6 forks source link

GetLogbookEntries API not functional - when status 100 #19

Open delasource opened 4 years ago

delasource commented 4 years ago

The API /Mem/Logbook/Entries (see docs), is supposed to return either status code 200 or 100 if there is much data, that needs to be spiltted to multiple requests.

In that case the method GetLogEntriesAsync as well as ApiCallAsync throws an MdsException.

Example call:

IMovesense mds /* ... */;
string data = await mds.ApiCallAsync<string>(myMovesenseDevice, MdsOp.GET, "/Mem/Logbook/Entries");

The call works for small amounts of data on the movesense device. However not, if there are plenty of LogbookEntries stored (about 50).

As stated in the above linked docs, the api caller has to react to status code 100. In that case, the first 4-5 entries are already in the body of the "Status 100"-response, as seen in logcat. that should be cached, and the api call needs to be called again (with parameter StartAfterId), as long as there are no more data available.

Edit: The same seems to apply to /Mem/Logbook/byId/{LogId}/Data docs

Btw: Please provide the steps to compile the project in src folder, so we can try to fork and PR a solution ourself.

delasource commented 4 years ago

I would like to hear a reply from @AndyCW

AndyCW commented 4 years ago

Apologies - been focused elsewhere. I can't play with this for a couple of days, but I suspect the workaround will be something like this:

    public async Task<LogEntriesResult> GetLogEntriesAsync()
    {
        var op = new ApiCallAsync<LogEntriesResult>(this, MdsOp.GET, LOGBOOK_ENTRIES_PATH);
        op.RetryFunction = new Func<Exception, bool?>((Exception ex) =>
            {
                bool? cancel = false;
                {Do something here if it's a 100........}
                if (++retries > MAX_RETRY_COUNT)
                {
                    cancel = true;
                }
                return cancel;
            }
        );
        return await op.CallWithRetryAsync();
    }

Good call on providing "How to Build" instructions - I will add them into the update I'm working on now.

AndyCW commented 4 years ago

@genyx Sorry for the delay in responding to this.

Your point about the 'low-level' methods is correct and I have a fix in mind about it. However, there are already two methods in Movesense.NET that call the MDS proxy service rather than the low-level movesense APIs. These methods takes care of all the paging and returns the whole list to you in JSON.

These methods in the MDS library are not well documented - only reference I can find is at: https://bitbucket.org/suunto/movesense-mobile-lib/src/03d327a69027cadfae7cc7bd8f1a8ed0ef53e947/IOS/Movesense/readme.txt#lines-251

Let me know if that unblocks you. Or if you must use the low-level calls, please let me know why. I can either fix them, or remove them altogether.