iem-devs / apna-library-server

NodeJS REST Server for Apna Library [WIP]
MIT License
2 stars 2 forks source link

Getting a book & author details from Goodreads API #5

Open koustuvsinha opened 8 years ago

koustuvsinha commented 8 years ago

As per #4, we need a plan to get a book details from Goodreads API. Here in this issue I will note down some endpoints we can use.

a. GET https://www.goodreads.com/search/index.xml?key={dev_key}&q={title / author / isbn}

returns book information, which comes in the following format (example : Harry Potter and the Sorcerers Stone) :

<?xml version="1.0" encoding="UTF-8"?>
<GoodreadsResponse>
  <Request>
    <authentication>true</authentication>
      <key><![CDATA[vTLGrgTXOJ4OI4wUeuSzXA]]></key>
    <method><![CDATA[search_index]]></method>
  </Request>
  <search>
  <query><![CDATA[Harry Potter and the Sorcerers Stone]]></query>
    <results-start>1</results-start>
    <results-end>18</results-end>
    <total-results>54</total-results>
    <source>Goodreads</source>
    <query-time-seconds>0.19</query-time-seconds>
    <results>
        <work>
  <id type="integer">4640799</id>
  <books_count type="integer">410</books_count>
  <ratings_count type="integer">3700234</ratings_count>
  <text_reviews_count type="integer">55457</text_reviews_count>
  <original_publication_year type="integer">1997</original_publication_year>
  <original_publication_month type="integer">6</original_publication_month>
  <original_publication_day type="integer">26</original_publication_day>
  <average_rating>4.41</average_rating>
  <best_book type="Book">
    <id type="integer">3</id>
    <title>Harry Potter and the Sorcerer's Stone (Harry Potter, #1)</title>
    <author>
      <id type="integer">1077326</id>
      <name>J.K. Rowling</name>
    </author>
    <image_url>https://d.gr-assets.com/books/1361572757m/3.jpg</image_url>
    <small_image_url>https://d.gr-assets.com/books/1361572757s/3.jpg</small_image_url>
  </best_book>
</work>
...
    </results>
</search>

</GoodreadsResponse>

From this response, we have to extract the relevant data. Our main focus should be getting the Goodreads ID and Image urls

b. GET https://www.goodreads.com/book/show.xml?key={developer_key}&id={book_id}

This API will get the book details in xml, with the help of Goodreads book_id and developer_key as registered from Goodreads.

c. GET https://www.goodreads.com/author/show.xml?key={key}&id=383606

This API will fetch an author information, the response would be kind of like this :

<?xml version="1.0" encoding="UTF-8"?>
<GoodreadsResponse>
  <Request>
    <authentication>true</authentication>
      <key><![CDATA[vTLGrgTXOJ4OI4wUeuSzXA]]></key>
    <method><![CDATA[author_show]]></method>
  </Request>
  <author>
  <id>383606</id>
  <name>Robert Galbraith</name>
  <link><![CDATA[https://www.goodreads.com/author/show/383606.Robert_Galbraith]]></link>
  <fans_count type="integer">6516</fans_count>
  <author_followers_count type="integer">6516</author_followers_count>
  <large_image_url><![CDATA[https://d.gr-assets.com/authors/1409176860p7/383606.jpg]]></large_image_url>
  <image_url><![CDATA[https://d.gr-assets.com/authors/1409176860p5/383606.jpg]]></image_url>
  <small_image_url><![CDATA[https://d.gr-assets.com/authors/1409176860p2/383606.jpg]]></small_image_url>
  <about><![CDATA[<em>This is a pseudonym for <a href="https://www.goodreads.com/author/show/1077326.J_K_Rowling"> J.K. Rowling</a>, the author of the Harry Potter series and The Casual Vacancy.</em><br><br><em>
  <strong>NOTE: There is more than one author with this name on Goodreads.</strong>
</em><br><a href="https://www.goodreads.com/author/show/7171901.Robert_Galbraith">Robert Galbraith - Marine Biologist</a><br><br>Rowling was born to Peter James Rowling, a Rolls-Royce aircraft engineer, and Anne Rowling (née Volant), on 31 July 1965 in Yate, Gloucestershire, England, 10 miles (16 km) northeast of Bristol. Her mother Anne was half-French and half-Scottish. Her parents first met on a train departing from King's Cross Station bound for Arbroath in 1964. They married on 14 March 1965. Her mother's maternal grandfather, Dugald Campbell, was born in Lamlash on the Isle of Arran. Her mother's paternal grandfather, Louis Volant, was awarded the Croix de Guerre for exceptional bravery in defending the village of Courcelles-le-Comte during the First World War.<br><br>Rowling's sister Dianne was born at their home when Rowling was 23 months old. The family moved to the nearby village Winterbourne when Rowling was four. She attended St Michael's Primary School, a school founded by abolitionist William Wilberforce and education reformer Hannah More. Her headmaster at St Michael's, Alfred Dunn, has been suggested as the inspiration for the Harry Potter headmaster Albus Dumbledore.<br><br>As a child, Rowling often wrote fantasy stories, which she would usually then read to her sister. She recalls that: "I can still remember me telling her a story in which she fell down a rabbit hole and was fed strawberries by the rabbit family inside it. Certainly the first story I ever wrote down (when I was five or six) was about a rabbit called Rabbit. He got the measles and was visited by his friends, including a giant bee called Miss Bee." At the age of nine, Rowling moved to Church Cottage in the Gloucestershire village of Tutshill, close to Chepstow, Wales. When she was a young teenager, her great aunt, who Rowling said "taught classics and approved of a thirst for knowledge, even of a questionable kind," gave her a very old copy of Jessica Mitford's autobiography, Hons and Rebels. Mitford became Rowling's heroine, and Rowling subsequently read all of her books.<br><br>Rowling has said of her teenage years, in an interview with The New Yorker, "I wasn’t particularly happy. I think it’s a dreadful time of life." She had a difficult homelife; her mother was ill and she had a difficult relationship with her father (she is no longer on speaking terms with him). She attended secondary school at Wyedean School and College, where her mother had worked as a technician in the science department. Rowling said of her adolescence, "Hermione [a bookish, know-it-all Harry Potter character] is loosely based on me. She's a caricature of me when I was eleven, which I'm not particularly proud of." Steve Eddy, who taught Rowling English when she first arrived, remembers her as "not exceptional" but "one of a group of girls who were bright, and quite good at English." Sean Harris, her best friend in the Upper Sixth owned a turquoise Ford Anglia, which she says inspired the one in her books.<br><br>]]></about>
  <influences></influences>
  <works_count>4</works_count>
  <gender></gender>
  <hometown></hometown>
  <born_at></born_at>
  <died_at></died_at>
  <goodreads_author></goodreads_author>

    <books>
      <book>
  <id type="integer">16160797</id>
  <isbn>0316206849</isbn>
  <isbn13>9780316206846</isbn13>
  <text_reviews_count type="integer">18883</text_reviews_count>
  <title>The Cuckoo's Calling (Cormoran Strike, #1)</title>
  <image_url>https://d.gr-assets.com/books/1358716559m/16160797.jpg</image_url>
  <small_image_url>https://d.gr-assets.com/books/1358716559s/16160797.jpg</small_image_url>
  <large_image_url/>
  <link>https://www.goodreads.com/book/show/16160797-the-cuckoo-s-calling</link>
  <num_pages>455</num_pages>
  <format>Hardcover</format>
  <edition_information/>
  <publisher>Mulholland Books / Little, Brown and Company</publisher>
  <publication_day>30</publication_day>
  <publication_year>2013</publication_year>
  <publication_month>4</publication_month>
  <average_rating>3.81</average_rating>
  <ratings_count>241104</ratings_count>
  <description>A BRILLIANT DEBUT MYSTERY IN A CLASSIC VEIN: DETECTIVE CORMORAN STRIKE INVESTIGATES A SUPERMODEL'S SUICIDE.&lt;br&gt;&lt;br&gt; After losing his leg to a land mine in Afghanistan, Cormoran Strike is barely scraping by as a private investigator. Strike is down to one client, and creditors are calling. He has also just broken up with his longtime girlfriend and is living in his office.&lt;br&gt;&lt;br&gt;Then John Bristow walks through his door with an amazing story: His sister, the legendary supermodel Lula Landry, known to her friends as the Cuckoo, famously fell to her death a few months earlier. The police ruled it a suicide, but John refuses to believe that. The case plunges Strike into the world of multimillionaire beauties, rock-star boyfriends, and desperate designers, and it introduces him to every variety of pleasure, enticement, seduction, and delusion known to man.&lt;br&gt;&lt;br&gt;You may think you know detectives, but you've never met one quite like Strike. You may think you know about the wealthy and famous, but you've never seen them under an investigation like this. Introducing Cormoran Strike, this is the acclaimed first crime novel by J.K. Rowling, writing under the pseudonym Robert Galbraith.</description>
<authors>
<author>
<id>383606</id>
<name>Robert Galbraith</name>
<role>Pseudonym</role>
<image_url nophoto='false'>
<![CDATA[https://d.gr-assets.com/authors/1409176860p5/383606.jpg]]>
</image_url>
<small_image_url nophoto='false'>
<![CDATA[https://d.gr-assets.com/authors/1409176860p2/383606.jpg]]>
</small_image_url>
<link><![CDATA[https://www.goodreads.com/author/show/383606.Robert_Galbraith]]></link>
<average_rating>3.90</average_rating>
<ratings_count>368280</ratings_count>
<text_reviews_count>37483</text_reviews_count>
</author>
</authors>
  <published>2013</published>
</book>
...
    </books>
</author>

</GoodreadsResponse>
hitswa commented 6 years ago

I have made a javascript function to get goodread book data. Have a look https://gist.github.com/hitswa/b0d5c161a0507a54d2e4e72b12dd4537