internetarchive / openlibrary

One webpage for every book ever published!
https://openlibrary.org
GNU Affero General Public License v3.0
5.7k stars 1.57k forks source link

Add Edition IDs to work JSON #67

Closed george08 closed 13 years ago

george08 commented 13 years ago

Hi ol-tech,

I was wondering if you've ever gotten a feature request to add the Edition links to the Work JSON, for example:

http://openlibrary.org/works/OL27258W.json

I don't see the links to the editions in the JSON, but they are definitely in the work HTML, and you have the corresponding work keys in the edition JSON, for example:

http://openlibrary.org/books/OL1627167M.json

I guess this would be similar data to what ThingISBN and xISBN offer, except not oriented around ISBN so much. I just thought I'd inquire if it was easy to add, since it would be handy to have for some work I'm doing.

//Ed

anandology commented 13 years ago

I think

http://openlibrary.org/works/OL27258W.json

should have a links section that contains

"editions": http://openlibrary.org/works/OL27258W/editions.json

and /editions.json should provide the editions.

edsu commented 13 years ago

I don't see it there.

george08 commented 13 years ago

Note Anand's use of "should" ;)

edsu commented 13 years ago

Ahh, ok ... I should've guessed from the fact that the ticket wasn't closed. I will be patient :-)

anandology commented 13 years ago

Sorry for the confusion.

How about this?

http://anand.openlibrary.org/works/OL27258W/editions.json?limit=5

The response includes links to the work and next and prev pagination.

edsu commented 13 years ago

I was hoping it would be possible to add the book keys to the work JSON. I think this would mirror the works are linked to from books, and also the way authors are linked to from works. So something like:

curl http://anand.openlibrary.org/works/OL27258W.json
{
  "first_publish_date": "1984", 
  "description": {
    "type": "/type/text", 
    "value": "The first of William Gibson's 'Sprawl' trilogy, Neuromancer is the classic cyberpunk novel.\r\n\r\nMore information on the [novel's official page][1].\r\n\r\n\r\n  [1]: http://www.williamgibsonbooks.com/books/neuromancer.asp"
  }, 
  "created": {
    "type": "/type/datetime", 
    "value": "2009-10-12T22:31:17.033421"
  }, 
  "title": "Neuromancer", 
  "books": [
    {
      "key": "/books/OL17987798M"
    }, 
    {
      "key": "/books/OL2154100M"
    }, 
    {
      "key": "/books/OL22822383M"
    }, 
    {
      "key": "/books/OL23054075M"
    }, 
    {
      "key": "/books/OL22849249M"
    }, 
    {
      "key": "/books/OL19969875M"
    }, 
    {
      "key": "/books/OL16064340M"
    }, 
    {
      "key": "/books/OL3305354M"
    }, 
    {
      "key": "/books/OL3963678M"
    }, 
    {
      "key": "/books/OL21395048M"
    }, 
    {
      "key": "/books/OL16541408M"
    }, 
    {
      "key": "/books/OL19160947M"
    }, 
    {
      "key": "/books/OL16541422M"
    }, 
    {
      "key": "/books/OL19726291M"
    }, 
    {
      "key": "/books/OL17407456M"
    }, 
    {
      "key": "/books/OL1627167M"
    }, 
    {
      "key": "/books/OL1234381M"
    }, 
    {
      "key": "/books/OL21795410M"
    }, 
    {
      "key": "/books/OL20872554M"
    }
  ], 
  "covers": [
    284192
  ], 
  "subject_places": [
    "Japan", 
    "Earth Orbit"
  ], 
  "last_modified": {
    "type": "/type/datetime", 
    "value": "2011-02-09T21:26:11.305812"
  }, 
  "subject_people": [
    "Case", 
    "Molly Millions"
  ], 
  "key": "/works/OL27258W", 
  "authors": [
    {
      "type": {
        "key": "/type/author_role"
      }, 
      "author": {
        "key": "/authors/OL26283A"
      }
    }
  ], 
  "latest_revision": 8, 
  "excerpts": [
    {
      "comment": "This is some of Gibson's best writing - compact, expressive, vivid.", 
      "excerpt": "The sky above the port was the color of television, tuned to a dead channel.", 
      "pages": "1"
    }
  ], 
  "type": {
    "key": "/type/work"
  }, 
  "subjects": [
    "Fiction", 
    "Information superhighway", 
    "Conspiracies in fiction", 
    "Computer hackers", 
    "Nervous system", 
    "Conspiracies", 
    "Business intelligence", 
    "Information superhighway in fiction", 
    "Business intelligence in fiction", 
    "Japan in fiction", 
    "Computer hackers in fiction", 
    "Nervous system in fiction", 
    "Wounds and injuries", 
    "Ciencia-ficci\u00f3n", 
    "Science fiction", 
    "Accessible book", 
    "Protected DAISY", 
    "In library"
  ], 
  "revision": 8
}

Would this be too difficult to add? The benefit I think is that the API becomes self documenting, people can follow their nose in the data without having to read API documentation.

//Ed

anandology commented 13 years ago

Some times the number of entries are too big and requires pagination.

For example, http://openlibrary.org/authors/OL18485A/United_States has 23K works. It won't be practical to list all of them in its author record.

2011/9/20 Ed Summers reply@reply.github.com:

I was hoping it would be possible to add the book keys to the work JSON. I think this would mirror the works are linked to from books, and also the way authors are linked to from works. So something like:

   curl http://anand.openlibrary.org/works/OL27258W.json

{
 "first_publish_date": "1984",
 "description": {
   "type": "/type/text",
   "value": "The first of William Gibson's 'Sprawl' trilogy, Neuromancer is the classic cyberpunk novel.\r\n\r\nMore information on the [novel's official page][1].\r\n\r\n\r\n  [1]: http://www.williamgibsonbooks.com/books/neuromancer.asp"
 },
 "created": {
   "type": "/type/datetime",
   "value": "2009-10-12T22:31:17.033421"
 },
 "title": "Neuromancer",
 "books": [
   {
     "key": "/books/OL17987798M"
   },
   {
     "key": "/books/OL2154100M"
   },
   {
     "key": "/books/OL22822383M"
   },
   {
     "key": "/books/OL23054075M"
   },
   {
     "key": "/books/OL22849249M"
   },
   {
     "key": "/books/OL19969875M"
   },
   {
     "key": "/books/OL16064340M"
   },
   {
     "key": "/books/OL3305354M"
   },
   {
     "key": "/books/OL3963678M"
   },
   {
     "key": "/books/OL21395048M"
   },
   {
     "key": "/books/OL16541408M"
   },
   {
     "key": "/books/OL19160947M"
   },
   {
     "key": "/books/OL16541422M"
   },
   {
     "key": "/books/OL19726291M"
   },
   {
     "key": "/books/OL17407456M"
   },
   {
     "key": "/books/OL1627167M"
   },
   {
     "key": "/books/OL1234381M"
   },
   {
     "key": "/books/OL21795410M"
   },
   {
     "key": "/books/OL20872554M"
   }
 ],
 "covers": [
   284192
 ],
 "subject_places": [
   "Japan",
   "Earth Orbit"
 ],
 "last_modified": {
   "type": "/type/datetime",
   "value": "2011-02-09T21:26:11.305812"
 },
 "subject_people": [
   "Case",
   "Molly Millions"
 ],
 "key": "/works/OL27258W",
 "authors": [
   {
     "type": {
       "key": "/type/author_role"
     },
     "author": {
       "key": "/authors/OL26283A"
     }
   }
 ],
 "latest_revision": 8,
 "excerpts": [
   {
     "comment": "This is some of Gibson's best writing - compact, expressive, vivid.",
     "excerpt": "The sky above the port was the color of television, tuned to a dead channel.",
     "pages": "1"
   }
 ],
 "type": {
   "key": "/type/work"
 },
 "subjects": [
   "Fiction",
   "Information superhighway",
   "Conspiracies in fiction",
   "Computer hackers",
   "Nervous system",
   "Conspiracies",
   "Business intelligence",
   "Information superhighway in fiction",
   "Business intelligence in fiction",
   "Japan in fiction",
   "Computer hackers in fiction",
   "Nervous system in fiction",
   "Wounds and injuries",
   "Ciencia-ficci\u00f3n",
   "Science fiction",
   "Accessible book",
   "Protected DAISY",
   "In library"
 ],
 "revision": 8
}

Would this be too difficult to add? The benefit I think is that the API becomes self documenting, people can follow their nose in the data without having to read API documentation.

//Ed

Reply to this email directly or view it on GitHub: https://github.com/internetarchive/openlibrary/issues/67#issuecomment-2144286

edsu commented 13 years ago

Does that even make sense that the United States is a Work :-)

But nevermind that, yes pagination is clearly a good idea for that situation. I wonder, would it make sense to have the path be:

http://anand.openlibrary.org/works/OL27258W/books.json?limit=5

instead of:

http://anand.openlibrary.org/works/OL27258W/editions.json?limit=5

since Books seems to be the object type that is baked into OpenLibrary and not Edition?

Thanks Anand! //Ed

anandology commented 13 years ago

But nevermind that, yes pagination is clearly a good idea for that situation. I wonder, would it make sense to have the path be:

   http://anand.openlibrary.org/works/OL27258W/books.json?limit=5

instead of:

   http://anand.openlibrary.org/works/OL27258W/editions.json?limit=5

since Books seems to be the object type that is baked into OpenLibrary and not Edition?

I prefer calling it editions as we use the term "editions" in the work page and the type of that object is /type/edition. Also we have a .../editions.json in the Lists API.

edsu commented 13 years ago

Oh makes sense to keep things consistent.

edsu commented 13 years ago

Hold on a second, that example you had above for United States was actually an Author not a Work... Are there really Works with thousands of Editions?

anandology commented 13 years ago

2011/9/20 Ed Summers reply@reply.github.com:

Hold on a second, that example you had above for United States was actually an Author not a Work... Are there really Works with thousands of Editions?

I would like to provide similar API for authors too. Thats why I quoted that example.

And there are works with more than 1000 editions too.

http://openlibrary.org/search?q=*:*&sort=editions

anandology commented 13 years ago

Done and deployed. Update the docs of Restful API to reflect this.

edsu commented 13 years ago

Thanks Anand, one little thing I noticed is the content-type is wrong:

Content-Type: applicaiton/json

edsu commented 13 years ago

Any idea what's going on here?

http://openlibrary.org/works/OL86329W/editions.json?limit=200

anandology commented 13 years ago

Found the bug that caused it. Will fix it shortly.

2011/11/13 Ed Summers reply@reply.github.com:

Any idea what's going on here?

http://openlibrary.org/works/OL86329W/editions.json?limit=200


Reply to this email directly or view it on GitHub: https://github.com/internetarchive/openlibrary/issues/67#issuecomment-2719639

anandology commented 13 years ago

Fixed. Try now.

2011/11/13 Ed Summers reply@reply.github.com:

Any idea what's going on here?

http://openlibrary.org/works/OL86329W/editions.json?limit=200


Reply to this email directly or view it on GitHub: https://github.com/internetarchive/openlibrary/issues/67#issuecomment-2719639