Hi team,
writing this email to describe the issues I faced with the current iOS API trying to add a
paging test case for Reddit and the changes I made to support it.
a)
To explain better I will start with the reddit response:
{
"data": {
"after": "t4_a7k1lt",
"before": t3_13j5ks,
"children": [
{
"data": {
/*snip*/
}
}
],
"modhash": ""
},
"kind": "Listing"
Currently in the iOS API with our default paging mechanisms (body and header), we
don't support page parameters to be deeply nested in the body. Here the
"after" and "before" params reside nested in the parent
"data" element. Further, the value of those parameters are not 'query
params', just simple strings pointing to the next and previous page.
For the Reddit case and for others that may come in the future which may have
"unknown" paging mechanisms, I followed the approach Android does and introduced
a PageExtractor interface. It's only purpose is to parse the appropriate content and
return us with the "next" and "previous" links. Existing header/body
mechanisms were refactored to separate classes that implement the PageExtractor interface.
Further an additional configuration option in the PipeConfig was added
[setPageExtractor] that set the appropriate extractor class.
Important to state is that this config option is entirely optional. Internally if not
set, we will still use the appropriate page/header mechanism (still depending on the
metadataLocation config option). Having this option will allow different and
"exotic" page extractors to be plugged in by the users if necessary or if not
still rely on our defaults.
You can see the Reddit page extractor in the test case here
b)
Reddit authentication relies on setting more than one headers in the request, named
"Cookie" and "modhash". The way these headers are set :
--> client issues a login request
<-- reddit responds with 'cookie' and 'modhash' elements in the body of
the response
The client then post process the response. That is, it creates two headers, the
'Cookie' header with the value prefixed to "reddit_session=<cookie value
from the previous step.>' and the 'modhash' from the previous step.
Our existing AGRestAuthenticator couldn't support this. Here there is more than one
header returned in the body of the response and further it requires a small
post-processing on the 'Cookie' element to add a 'reddit_session=' prefix.
In order to support this, a new AGRedditAuthenticationModule was created that follows the
AGAuthenticationModule interface. You can see it here
I've seen that a similar approach is followed in Android too.
Thanks
Christos