Friday, February 27, 2015

Changes 2/27/15 - LibriVox Search API

Today, Finn and I worked on getting searching working for our LibriFox app. We are using LibriVox's json api, so our url string looks like:
"https://librivox.org/api/feed/audiobooks/title/^" + input + "?&format=json"
However, we want to make sure that our input string is web safe (so there aren't spaces, slashes, or other characters that don't gel with urls) so we did some googling and found the Javascript built-in function #encodeURIComponent, which takes a string and substitutes all non url-safe characters with their ascii encoded values. For example, the string 'twelve / six' would become 'twelve%20%2F%20six'

This ended up not mattering quite so much after we realized that the LibriVox api gives an error response if any spaces are used in the url query, even if they are properly escaped. For example: space vs. sp ace.

With that done, we continued working on our search functionality, but ran into a bit of a hurdle as LibriVox's response to our queries kept returning null when they ran after text was entered into the search bar, even though they worked fine when doing it from the web console or pasting the url directly into a browser.

What I eventually figured out is that because we were grabbing our response object right after issuing a request, it would always end up as null because the net traffic wouldn't have had time to go through in the split second before we called #response on our object


In order to fix this, I added an onload callback into the #getJSON method, so that we could pass in a function that would execute once the server had responded.


We're now trying to actually get these results to display in our app. However, jQuery Mobile does some weird stuff, and our code to append list items for each book referenced in our url_request.response object doesn't append the list items for some reason.

1 comment:

  1. I can't begin to tell you how much I enjoy reading your posts. Your blog is going to be a diamond mine for curriculum materials!

    ReplyDelete