- Built as a standalone Java 1.5+ library, usable in Android.
- Builds with Gradle.
- Uses fluent syntax wherever possible (perhaps at a slight loss of efficiency as mikaelhg's UrlBuilder is final)
Table of Contents generated with DocToc
PbsOauth oauth = PbsOauth("key", "secret");
String requestTokenUrl = oauth.getRequestTokenUrl("http://localhost:8080/capture_verifier")
System.out.println(oauth.isAuthorizing()); // "true"
// Go do things in the browser with requestTokenUrl, capture verifier from callback
oauth.retrieveAccessToken(verifier)
System.out.println(oauth.isAuthorizing()); // "false"
String signedUrl = oauth.signRequest(
PbsUrlInfo.MEMBER_WISH_LIST.toString();
);
PbsOauth oauth = PbsOauth("key", "secret", "token", "tokensecret");
String signedUrl = oauth.signRequest(
PbsUrlInfo.MEMBER_WISH_LIST.toString()
);
PbsUrlInfo.MEMBER_WISH_LIST.toString();
PbsUrlInfo.MEMBER_WISH_LIST.toUri();
PbsUrlInfo.MEMBER_WISH_LIST.toBuilder();
PbsUrlBuilder builder = PbsUrlBuilder
.fromPath(PbsUrlInfo.MEMBER_WISH_LIST)
.toString();
In the event that you need to build your own URL
PbsUrlBuilder builder = PbsUrlBuilder
.fromUrl(url)
.toString();
PbsUrlInfo.MEMBER_WISH_LIST.toBuilder()
.withOffsetLimit(10, 10)
.toString();
PbsUrlInfo.ADD_TO_WISH_LIST.toBuilder()
.withIsbn(0312851820)
.toString();
It should be noted that the BookListBuilder will process single book responses (e.g. RequestType=ISBNList when only one ISBN is provided) or a list of books. May not work properly with Requests at this point. Not every field is guaranteed to be deseralized (feel free to PR more).
// Go fetch response with your favorite HTTP client stack => response
BookList bookList = BooksFactory.getBookList(response);
for (Book book : bookList) {
System.out.println(book.getTitle());
}
This is useful when using HTTP, as PBS API automatically generates HTTPS URLs in paging elements. The getNextPage() method fixes this behavior, and maintains HTTP.
// Go fetch response with your favorite HTTP client stack => response
BookList bookList = BooksFactory.getBookList(response);
// Returns PbsUrlBuilder, so you can manipulate if needed
System.out.println(bookList.getNextPage().toString());
// Extract one book's JSON => json
// Not typically used directly, this is used internally by getBookList
// Will not work correctly with PBS response
Book book = BooksFactory.getBook(json)
System.out.println(book.getTitle());
Thanks to a few great Java libraries that made this much tidier
- Signpost by mttkay for OAuth
- Urlbuilder by mikaelhg for manipulating URLs
- Guava by Google for dependency injection & testing