Skip to content

Commit 2b720b7

Browse files
authored
Merge pull request #1 from Advik-B/dev
First release?
2 parents f8e86d4 + d09e471 commit 2b720b7

30 files changed

Lines changed: 1675 additions & 17 deletions

.github/workflows/publish.yml

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: Publish to GitHub Packages
2+
3+
on:
4+
release:
5+
types: [published]
6+
7+
jobs:
8+
publish:
9+
name: Build and Publish
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout source code
14+
uses: actions/checkout@v4
15+
16+
- name: Set up JDK 17
17+
uses: actions/setup-java@v4
18+
with:
19+
distribution: 'temurin'
20+
java-version: 17
21+
22+
- name: Configure Gradle
23+
uses: gradle/actions/setup-gradle@v3
24+
25+
- name: Publish package
26+
env:
27+
USERNAME: ${{ secrets.GITHUB_ACTOR }}
28+
TOKEN: ${{ secrets.GITHUB_TOKEN }}
29+
run: ./gradlew publish

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,6 @@ bin/
3939
.vscode/
4040

4141
### Mac OS ###
42-
.DS_Store
42+
.DS_Store
43+
44+
capacitor-java/

.idea/gradle.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/misc.xml

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.txt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Advik-B
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 156 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,156 @@
1+
2+
# Wattpad API - Java Client
3+
4+
![Wattpad API](https://img.shields.io/badge/Wattpad-API-orange?style=for-the-badge)
5+
![Java](https://img.shields.io/badge/Java-17+-blue?style=for-the-badge)
6+
![License](https://img.shields.io/badge/License-MIT-green?style=for-the-badge)
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)

build.gradle.kts

Lines changed: 79 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,92 @@
11
plugins {
22
id("java")
3+
id("com.github.johnrengelman.shadow") version "8.1.1"
4+
id("maven-publish")
35
}
46

5-
group = "dev.advik"
6-
version = "1.0-SNAPSHOT"
7+
group = "io.github.advik-b"
8+
version = "1.1"
79

810
repositories {
911
mavenCentral()
12+
repositories {
13+
maven {
14+
name = "GitHubPackages"
15+
url = uri("https://maven.pkg.github.com/Advik-B/Wattpad-API.jar")
16+
credentials {
17+
username = (project.findProperty("gpr.user") ?: System.getenv("USERNAME")) as String?
18+
password = (project.findProperty("gpr.token") ?: System.getenv("TOKEN")) as String?
19+
}
20+
}
21+
}
1022
}
1123

1224
dependencies {
13-
testImplementation(platform("org.junit:junit-bom:5.10.0"))
14-
testImplementation("org.junit.jupiter:junit-jupiter")
25+
// HTTP Client (OkHttp is robust and Android-friendly)
26+
implementation("com.squareup.okhttp3:okhttp:4.12.0")
27+
28+
// JSON Parsing (Gson is standard and works on Android)
29+
implementation("com.google.code.gson:gson:2.10.1")
30+
31+
// HTML Parsing (Jsoup is the standard Java equivalent to BeautifulSoup)
32+
implementation("org.jsoup:jsoup:1.17.2")
33+
34+
}
35+
36+
java {
37+
sourceCompatibility = JavaVersion.VERSION_11 // Good balance for library compatibility
38+
targetCompatibility = JavaVersion.VERSION_11
39+
40+
withSourcesJar()
1541
}
1642

17-
tasks.test {
18-
useJUnitPlatform()
43+
44+
// Add manifest attributes for JAR
45+
tasks.jar {
46+
manifest {
47+
attributes(
48+
"Implementation-Title" to project.name,
49+
"Implementation-Version" to project.version,
50+
"Main-Class" to "dev.advik.Main" // Adjust this if your main class is different
51+
)
52+
}
53+
}
54+
55+
tasks.shadowJar {
56+
archiveBaseName.set(project.name) // Base name for the JAR file
57+
archiveClassifier.set("") // Set classifier to empty string to avoid '-all' suffix (optional)
58+
archiveVersion.set(project.version.toString())
59+
60+
manifest {
61+
attributes(
62+
"Implementation-Title" to project.name,
63+
"Implementation-Version" to project.version,
64+
"Main-Class" to "dev.advik.Main" // Specify the main class here
65+
)
66+
}
67+
}
68+
69+
tasks.build {
70+
dependsOn(tasks.shadowJar)
71+
}
72+
73+
publishing {
74+
publications {
75+
create<MavenPublication>("mavenJava") {
76+
from(components["java"])
77+
78+
groupId = group as String
79+
version = version
80+
}
81+
}
82+
repositories {
83+
maven {
84+
name = "GitHubPackages"
85+
url = uri("https://maven.pkg.github.com/Advik-B/Wattpad-API.jar")
86+
credentials {
87+
username = (project.findProperty("gpr.user") ?: System.getenv("USERNAME")) as String?
88+
password = (project.findProperty("gpr.token") ?: System.getenv("TOKEN")) as String?
89+
}
90+
}
91+
}
1992
}

0 commit comments

Comments
 (0)