|
| 1 | + |
| 2 | +# Wattpad API - Java Client |
| 3 | + |
| 4 | + |
| 5 | + |
| 6 | + |
| 7 | + |
| 8 | +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. |
| 9 | + |
| 10 | +--- |
| 11 | + |
| 12 | +## 🌟 Features |
| 13 | + |
| 14 | +- Fetch Wattpad stories by ID or part ID. |
| 15 | +- Retrieve metadata such as title, author, description, tags, and cover images. |
| 16 | +- Render story parts with support for text and images. |
| 17 | +- Built-in caching for optimized performance. |
| 18 | +- Fully customizable client configuration. |
| 19 | + |
| 20 | +--- |
| 21 | + |
| 22 | +## 📦 Installation |
| 23 | + |
| 24 | +### Prerequisites |
| 25 | +- Java 17 or higher |
| 26 | +- Maven or Gradle for dependency management |
| 27 | + |
| 28 | +### Using Maven |
| 29 | +Add the following dependency to your `pom.xml`: |
| 30 | +```xml |
| 31 | +<dependency> |
| 32 | + <groupId>dev.advik</groupId> |
| 33 | + <artifactId>wattpad-api</artifactId> |
| 34 | + <version>1.0.0</version> |
| 35 | +</dependency> |
| 36 | +``` |
| 37 | + |
| 38 | +### Using Gradle |
| 39 | +Add the following to your `build.gradle`: |
| 40 | +```gradle |
| 41 | +implementation 'dev.advik:wattpad-api:1.0.0' |
| 42 | +``` |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +## 🚀 Usage |
| 47 | + |
| 48 | +### Quick Start |
| 49 | +Here's an example of how to use the Wattpad API client to fetch and render a story: |
| 50 | + |
| 51 | +```java |
| 52 | +import dev.advik.wattpad.WattpadClient; |
| 53 | +import dev.advik.wattpad.models.Story; |
| 54 | + |
| 55 | +public class Main { |
| 56 | + public static void main(String[] args) { |
| 57 | + WattpadClient client = new WattpadClient.Builder().useCache(true).build(); |
| 58 | + long storyId = 336166598L; // Example story ID |
| 59 | + |
| 60 | + try { |
| 61 | + Story story = Story.fromId(storyId, client); |
| 62 | + System.out.println("Title: " + story.getTitle()); |
| 63 | + System.out.println("Author: " + story.getAuthor().getName()); |
| 64 | + } catch (Exception e) { |
| 65 | + e.printStackTrace(); |
| 66 | + } |
| 67 | + } |
| 68 | +} |
| 69 | +``` |
| 70 | + |
| 71 | +### Rendering Story Parts |
| 72 | +The library supports rendering story parts with text and images: |
| 73 | +```java |
| 74 | +RenderedPage renderedPage = part.renderWith(client); |
| 75 | +for (HTMLContent content : renderedPage.getContentStack()) { |
| 76 | + if (content.getType() == HTMLContent.Type.TEXT) { |
| 77 | + System.out.println(content.getTextData()); |
| 78 | + } else if (content.getType() == HTMLContent.Type.IMAGE) { |
| 79 | + System.out.println("[IMAGE: " + content.getImageUrl() + "]"); |
| 80 | + } |
| 81 | +} |
| 82 | +``` |
| 83 | + |
| 84 | +--- |
| 85 | + |
| 86 | +## 📖 Examples |
| 87 | + |
| 88 | +### Fetching a Story by ID |
| 89 | +```java |
| 90 | +Story story = Story.fromId(336166598L, client); |
| 91 | +System.out.println("Title: " + story.getTitle()); |
| 92 | +System.out.println("Description: " + story.getDescription()); |
| 93 | +``` |
| 94 | + |
| 95 | +### Fetching Metadata |
| 96 | +```java |
| 97 | +System.out.println("Author: " + story.getAuthor().getName()); |
| 98 | +System.out.println("Tags: " + story.getTags()); |
| 99 | +System.out.println("Cover URL: " + story.getCoverUrl()); |
| 100 | +``` |
| 101 | + |
| 102 | +### Clearing Cache |
| 103 | +```java |
| 104 | +client.clearCache(); |
| 105 | +System.out.println("Cache cleared."); |
| 106 | +``` |
| 107 | + |
| 108 | +--- |
| 109 | + |
| 110 | +## 🛠️ Development |
| 111 | + |
| 112 | +### Building the Project |
| 113 | +Clone the repository and build the project using Maven: |
| 114 | +```bash |
| 115 | +git clone https://github.com/your-username/Wattpad-API.git |
| 116 | +cd Wattpad-API |
| 117 | +mvn clean install |
| 118 | +``` |
| 119 | + |
| 120 | +### Running the Demo |
| 121 | +Run the `Main.java` file to see the API in action: |
| 122 | +```bash |
| 123 | +java -cp target/wattpad-api-1.0.0.jar dev.advik.Main |
| 124 | +``` |
| 125 | + |
| 126 | +--- |
| 127 | + |
| 128 | +## 🤝 Contributing |
| 129 | + |
| 130 | +Contributions are welcome! Please follow these steps: |
| 131 | +1. Fork the repository. |
| 132 | +2. Create a new branch for your feature or bugfix. |
| 133 | +3. Commit your changes and push them to your fork. |
| 134 | +4. Submit a pull request. |
| 135 | + |
| 136 | +--- |
| 137 | + |
| 138 | +## 📜 License |
| 139 | + |
| 140 | +This project is licensed under the [MIT License](LICENSE.txt). |
| 141 | + |
| 142 | +--- |
| 143 | + |
| 144 | +## 💬 Contact |
| 145 | + |
| 146 | +For questions or support, feel free to reach out: |
| 147 | +- **Author**: Advik |
| 148 | +- **GitHub**: [github.com/Advik-B](https://github.com/Advik-B) |
| 149 | + |
| 150 | +--- |
| 151 | + |
| 152 | +## 🌐 Links |
| 153 | + |
| 154 | +- [Wattpad](https://www.wattpad.com) |
| 155 | +- ~~[API Documentation](https://www.wattpad.com/api-docs)~~ LMFAO WATTPAD DOES NOT HAVE DOCUMENTATION I HAD TO FIGURE ALL OF THIS OUT BY HAND |
| 156 | +- [GitHub Repository](https://github.com/Advik-B/Wattpad-API.jar) |
0 commit comments