Skip to content

Advik-B/Wattpad-API-Java

Repository files navigation

Wattpad API - Java Client

Wattpad API Java License

A powerful and easy-to-use Java client for interacting with Wattpad's API. This library allows developers to fetch stories, parts, and metadata from Wattpad, enabling seamless integration into your Java applications.


🌟 Features

  • Fetch Wattpad stories by ID or part ID.
  • Retrieve metadata such as title, author, description, tags, and cover images.
  • Render story parts with support for text and images.
  • Built-in caching for optimized performance.
  • Fully customizable client configuration.

📦 Installation

Prerequisites

  • Java 17 or higher
  • Maven or Gradle for dependency management

TODO


🚀 Usage

Quick Start

Here's an example of how to use the Wattpad API client to fetch and render a story:

import dev.advik.wattpad.WattpadClient;
import dev.advik.wattpad.models.Story;

public class Main {
    public static void main(String[] args) {
        WattpadClient client = new WattpadClient.Builder().useCache(true).build();
        long storyId = 336166598L; // Example story ID

        try {
            Story story = Story.fromId(storyId, client);
            System.out.println("Title: " + story.getTitle());
            System.out.println("Author: " + story.getAuthor().getName());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Rendering Story Parts

The library supports rendering story parts with text and images:

RenderedPage renderedPage = part.renderWith(client);
for (HTMLContent content : renderedPage.getContentStack()) {
    if (content.getType() == HTMLContent.Type.TEXT) {
        System.out.println(content.getTextData());
    } else if (content.getType() == HTMLContent.Type.IMAGE) {
        System.out.println("[IMAGE: " + content.getImageUrl() + "]");
    }
}

📖 Examples

Fetching a Story by ID

Story story = Story.fromId(336166598L, client);
System.out.println("Title: " + story.getTitle());
System.out.println("Description: " + story.getDescription());

Fetching Metadata

System.out.println("Author: " + story.getAuthor().getName());
System.out.println("Tags: " + story.getTags());
System.out.println("Cover URL: " + story.getCoverUrl());

Clearing Cache

client.clearCache();
System.out.println("Cache cleared.");

🛠️ Development

Building the Project

Clone the repository and build the project using Maven:

git clone https://github.com/your-username/Wattpad-API.git
cd Wattpad-API
mvn clean install

Running the Demo

Run the Main.java file to see the API in action:

java -cp target/wattpad-api-1.0.0.jar dev.advik.Main

🤝 Contributing

Contributions are welcome! Please follow these steps:

  1. Fork the repository.
  2. Create a new branch for your feature or bugfix.
  3. Commit your changes and push them to your fork.
  4. Submit a pull request.

📜 License

This project is licensed under the MIT License.


💬 Contact

For questions or support, feel free to reach out:


🌐 Links

About

A rewrite of my wrapper around the Wattpad API in java

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages