Skip to content
This repository has been archived by the owner on Oct 24, 2019. It is now read-only.

Commit

Permalink
Add a getDocument() function that calls the api docs.getSettings func…
Browse files Browse the repository at this point in the history
…tion to create a Document from a document id.
  • Loading branch information
carmen committed Nov 18, 2011
1 parent c2a4399 commit de27252
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
3 changes: 3 additions & 0 deletions examples/SimpleTest.java
Expand Up @@ -59,5 +59,8 @@ public static void main(String[] args) {
for (ScribdDocument doc : featuredList) {
System.out.println(doc);
}

System.out.println("===== Get Document =====");
System.out.println(scribd.getDocument(73038675));
}
}
21 changes: 21 additions & 0 deletions src/com/scribd/jscribd/Scribd.java
Expand Up @@ -109,4 +109,25 @@ public List<ScribdDocument> getFeaturedDocuments(String scope, int limit, int of

return list;
}

/**
* For more information, see the Scribd API documentation:
* http://www.scribd.com/developers/api?method_name=docs.getSettings
*
* @param doc_id The ID for the document.
* @return The ScribdDocument corresponding to the ID.
*/
public ScribdDocument getDocument(int doc_id) {
Map<String, Object> fields = new HashMap<String, Object>();
fields.put("doc_id", doc_id);

Document xml = api.sendRequest("docs.getSettings", fields);
NodeList results = xml.getElementsByTagName("rsp");

if (results.getLength() < 1) {
return null;
}

return new ScribdDocument(api, results.item(0));
}
}

0 comments on commit de27252

Please sign in to comment.