-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 65d8217
Showing
14 changed files
with
519 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
target/ | ||
!.mvn/wrapper/maven-wrapper.jar | ||
!**/src/main/**/target/ | ||
!**/src/test/**/target/ | ||
|
||
### IntelliJ IDEA ### | ||
.idea/modules.xml | ||
.idea/jarRepositories.xml | ||
.idea/compiler.xml | ||
.idea/libraries/ | ||
*.iws | ||
*.iml | ||
*.ipr | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
build/ | ||
!**/src/main/**/build/ | ||
!**/src/test/**/build/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store | ||
/.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,158 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>lk.klass</groupId> | ||
<artifactId>dyntube-java</artifactId> | ||
<version>1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
<name>DynTube Java</name> | ||
<description>This is a java SDK for Dyntube</description> | ||
<url>https://klass.lk</url> | ||
|
||
<developers> | ||
<developer> | ||
<name>Danushka Herath</name> | ||
<email>[email protected]</email> | ||
<organization>KlassLK</organization> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<maven.compiler.source>17</maven.compiler.source> | ||
<maven.compiler.target>17</maven.compiler.target> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
</properties> | ||
|
||
<scm> | ||
<connection>scm:git:git://github.com/klass-lk/dyntube-java.git</connection> | ||
<developerConnection>scm:git:ssh://github.com:klass-lk/dyntube-java.git</developerConnection> | ||
<url>http://github.com/klass-lk/dyntube-java/tree/master</url> | ||
</scm> | ||
|
||
<licenses> | ||
<license> | ||
<name>Apache License, Version 2.0</name> | ||
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url> | ||
<distribution>repo</distribution> | ||
</license> | ||
</licenses> | ||
|
||
<profiles> | ||
<profile> | ||
<id>deploy</id> | ||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-source-plugin</artifactId> | ||
<version>3.2.1</version> | ||
<executions> | ||
<execution> | ||
<id>attach-sources</id> | ||
<goals> | ||
<goal>jar-no-fork</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-javadoc-plugin</artifactId> | ||
<version>3.2.0</version> | ||
<executions> | ||
<execution> | ||
<id>attach-javadocs</id> | ||
<goals> | ||
<goal>jar</goal> | ||
</goals> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-gpg-plugin</artifactId> | ||
<version>1.6</version> | ||
<executions> | ||
<execution> | ||
<id>sign-artifacts</id> | ||
<phase>verify</phase> | ||
<goals> | ||
<goal>sign</goal> | ||
</goals> | ||
<configuration> | ||
<!-- Prevent `gpg` from using pinentry programs --> | ||
<gpgArguments> | ||
<arg>--pinentry-mode</arg> | ||
<arg>loopback</arg> | ||
</gpgArguments> | ||
</configuration> | ||
</execution> | ||
</executions> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</profile> | ||
</profiles> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<configuration> | ||
<source>8</source> | ||
<target>8</target> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.sonatype.plugins</groupId> | ||
<artifactId>nexus-staging-maven-plugin</artifactId> | ||
<version>1.6.8</version> | ||
<extensions>true</extensions> | ||
<configuration> | ||
<serverId>ossrh</serverId> | ||
<nexusUrl>https://s01.oss.sonatype.org/</nexusUrl> | ||
<autoReleaseAfterClose>true</autoReleaseAfterClose> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.springframework</groupId> | ||
<artifactId>spring-webflux</artifactId> | ||
<version>6.0.2</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-annotations</artifactId> | ||
<version>2.13.0</version> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.projectlombok</groupId> | ||
<artifactId>lombok</artifactId> | ||
<version>1.18.22</version> | ||
<scope>compile</scope> | ||
</dependency> | ||
</dependencies> | ||
<distributionManagement> | ||
<snapshotRepository> | ||
<id>ossrh</id> | ||
<name>Maven Central Snapshot Repository</name> | ||
<url>https://s01.oss.sonatype.org/content/repositories/snapshots</url> | ||
</snapshotRepository> | ||
<repository> | ||
<id>ossrh</id> | ||
<name>Maven Central Staging Repository</name> | ||
<url>https://s01.oss.sonatype.org/service/local/staging/deploy/maven2/</url> | ||
</repository> | ||
</distributionManagement> | ||
|
||
|
||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package lk.klass; | ||
|
||
import lk.klass.dtos.CreateProjectRequest; | ||
import lk.klass.dtos.GetProjectsResponse; | ||
import lk.klass.dtos.UploadVideoResponse; | ||
import lk.klass.dtos.GetVideosResponse; | ||
import lk.klass.models.Video; | ||
import org.springframework.http.HttpEntity; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.client.MultipartBodyBuilder; | ||
import org.springframework.http.codec.multipart.FilePart; | ||
import org.springframework.util.MultiValueMap; | ||
import org.springframework.web.reactive.function.BodyInserters; | ||
import org.springframework.web.reactive.function.client.WebClient; | ||
import reactor.core.publisher.Mono; | ||
import reactor.util.retry.Retry; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
public class DyntubeVideoService { | ||
private final WebClient webClient; | ||
private final String token; | ||
|
||
public DyntubeVideoService(String token) { | ||
this.token = token; | ||
String endPoint = "https://api.dyntube.com/v1/"; | ||
webClient = WebClient.builder() | ||
.baseUrl(endPoint) | ||
.defaultHeader(HttpHeaders.AUTHORIZATION, "bearer" + " " + token) | ||
.build(); | ||
} | ||
|
||
public Mono<UploadVideoResponse> uploadVideo(FilePart file) { | ||
return WebClient.builder() | ||
.baseUrl("https://upload.dyntube.com/v1/videos") | ||
.defaultHeader(HttpHeaders.AUTHORIZATION, "bearer" + " " + token) | ||
.build() | ||
.post() | ||
.contentType(MediaType.MULTIPART_FORM_DATA) | ||
.body(BodyInserters.fromMultipartData(fromFile(file))) | ||
.retrieve().bodyToMono(UploadVideoResponse.class) | ||
.retryWhen(Retry.backoff(3, Duration.ofSeconds(2)).jitter(0.75)); | ||
} | ||
|
||
public Mono<Video> getVideo(String videoId) { | ||
return webClient | ||
.get() | ||
.uri(String.format("videos/%s", videoId)) | ||
.retrieve() | ||
.bodyToMono(Video.class); | ||
} | ||
|
||
public Mono<GetVideosResponse> getVideos() { | ||
return webClient | ||
.get() | ||
.uri("videos") | ||
.retrieve() | ||
.bodyToMono(GetVideosResponse.class); | ||
} | ||
|
||
public Mono<GetProjectsResponse> getProjects() { | ||
return webClient | ||
.get() | ||
.uri("projects") | ||
.retrieve() | ||
.bodyToMono(GetProjectsResponse.class); | ||
} | ||
|
||
public Mono<String> createProject(CreateProjectRequest request) { | ||
return webClient | ||
.post() | ||
.uri("projects") | ||
.body(BodyInserters.fromValue(request)) | ||
.retrieve() | ||
.bodyToMono(String.class); | ||
} | ||
|
||
private MultiValueMap<String, HttpEntity<?>> fromFile(FilePart file) { | ||
MultipartBodyBuilder builder = new MultipartBodyBuilder(); | ||
builder.part("file", file); | ||
return builder.build(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lk.klass.dtos; | ||
|
||
import lk.klass.models.ProjectOptions; | ||
import lombok.Data; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class CreateProjectRequest { | ||
public String name; | ||
public String description; | ||
public String region; | ||
public int planType; | ||
public ProjectOptions options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lk.klass.dtos; | ||
|
||
import lk.klass.models.Pager; | ||
import lk.klass.models.Project; | ||
import lombok.Data; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class GetProjectsResponse { | ||
private Pager pager; | ||
private List<Project> projects; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lk.klass.dtos; | ||
|
||
import lk.klass.models.Pager; | ||
import lk.klass.models.Video; | ||
import lombok.Data; | ||
|
||
import java.util.ArrayList; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class GetVideosResponse { | ||
public Pager pager; | ||
public ArrayList<Video> videos; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package lk.klass.dtos; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class UploadVideoResponse { | ||
public String videoKey; | ||
public String uploadId; | ||
public String videoId; | ||
public String channelKey; | ||
public String privateLink; | ||
public String iframeLink; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package lk.klass.models; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class Formats { | ||
public boolean hls; | ||
public boolean mp4; | ||
public VideoOptions options; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package lk.klass.models; | ||
|
||
import lombok.Data; | ||
|
||
/** | ||
* @author danushka | ||
* 2023-03-12 | ||
*/ | ||
@Data | ||
public final class Image { | ||
public String xsUrl; | ||
public String smUrl; | ||
public String mdUrl; | ||
public String lgUrl; | ||
} |
Oops, something went wrong.