Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
official-wizard committed Aug 20, 2024
0 parents commit 9e37a47
Show file tree
Hide file tree
Showing 22 changed files with 829 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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/
.idea/discord.xml
.idea/encodings.xml
*.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
8 changes: 8 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/kotlinc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 14 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

125 changes: 125 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@

<p align="center" dir="auto">
<a href="https://omdbapi.com" rel="nofollow">
<img src="https://i.imgur.com/2oq2xSh.png" width="200" alt="OMDb API Icon" style="max-width: 100%;"/>
</a>
</p>

<h1 align="center"><a href="https://omdbapi.com">OMDbAPI.com</a> Client for Kotlin</h1>

## Installation

To begin, import the library using jitpack.io.

You can include jitpack in your `pom.xml` by adding the following jitpack repository:

```xml
<repository>
<id>jitpack.io</id>
<url>https://www.jitpack.io</url>
</repository>
```

Then add this `omdb-kotlin` dependency to your `pom.xml` project!

```xml
<dependency>
<groupId>com.github.official-wizard</groupId>
<artifactId>omdb-kotlin</artifactId>
<version>1.0.0</version>
</dependency>
```

## Usage

### Basic Usage

```kotlin
val credentials = Credentials("<web api key>")
val api: OmdbInterface = OmdbClient(credentials).api

// access the api interface in `api`
```

#### Search

<details>
<summary>Search Title (or imdb ID)</summary>
<br>

> A call to this function will retrieve a single result for the provided title or Imdb ID
**Available Parameters**

> NOTE: Although `Title` and `ImdbId` are optional, at least 1 of them is required!
| Name | Type | Description | Example | OPTIONAL |
|:--------------|:----------|:-------------------------------------------------------------------|:----------------|----------|
| title | String | The name of the film you'd like to search for. | Demons | yes |
| imdbId | String | The imdb ID for the film you'd like to search for. | tt0089013 | yes |
| type | QueryType | The type of film you'd like to search for (Movie, Series, Episode) | QueryType.movie | yes |
| yearOfRelease | String | The year the film was released | 1985 | yes |
| plot | Plot | Short or full plot. | Plot.short | yes |

**Example**
```kotlin
val credentials = Credentials("<web api key>")
val api: OmdbInterface = OmdbClient(credentials).api

val response: NetworkResponse<Search.Response, Error.Response> = api.searchTitle(
title = "Demons"
)

if (response is NetworkResponse.Success) {
// handle the data
val searchResult: Search.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: Error.Response? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

</details>

<details>
<summary>Search List</summary>
<br>

> A call to this function will retrieve a list of results for the provided title
**Available Parameters**

| Name | Type | Description | Example | OPTIONAL |
|:--------------|:----------|:-------------------------------------------------------------------|:----------------|----------|
| title | String | The name of the film you'd like to search for. | Demons | no |
| type | QueryType | The type of film you'd like to search for (Movie, Series, Episode) | QueryType.movie | yes |
| yearOfRelease | String | The year the film was released | 1985 | yes |
| page | Int | The page number to search through. | Plot.short | yes |

**Example**
```kotlin
val credentials = Credentials("<web api key>")
val api: OmdbInterface = OmdbClient(credentials).api

val response: NetworkResponse<SearchList.Response, Error.Response> = api.searchList(
title = "Demons"
)

if (response is NetworkResponse.Success) {
// handle the data
val searchResult: SearchList.Response = response.body

} else if (response is NetworkResponse.Error) {
// if the server returns an error it be found here
val errorResponse: Error.Response? = response.body

// if the api (locally) had an internal error, it'll be found here
val internalError: Throwable? = response.error
}
```

</details>
137 changes: 137 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
<?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>com.omdbapi</groupId>
<artifactId>omdb-kotlin</artifactId>
<version>1.0.0</version>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.10.2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<kotlin.code.style>official</kotlin.code.style>
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
</properties>

<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>

<repository>
<id>mavenCentral</id>
<url>https://repo1.maven.org/maven2/</url>
</repository>
</repositories>

<build>
<sourceDirectory>src/main/kotlin</sourceDirectory>
<testSourceDirectory>src/test/kotlin</testSourceDirectory>
<plugins>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>1.9.22</version>
<executions>
<execution>
<id>compile</id>
<phase>compile</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>test-compile</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.22.2</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<mainClass>MainKt</mainClass>
</configuration>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-test-junit5</artifactId>
<version>1.9.22</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>1.9.22</version>
</dependency>

<!-- RetroFit Dependencies -->
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.12.0</version>
</dependency>

<dependency>
<groupId>com.github.haroldadmin</groupId>
<artifactId>NetworkResponseAdapter</artifactId>
<version>5.0.0</version>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>retrofit</artifactId>
<version>2.9.0</version>
</dependency>

<dependency>
<groupId>com.squareup.retrofit2</groupId>
<artifactId>converter-gson</artifactId>
<version>2.11.0</version>
</dependency>

<dependency>
<groupId>co.infinum</groupId>
<artifactId>retromock</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>

</project>
11 changes: 11 additions & 0 deletions src/main/kotlin/com/omdbapi/api/OMDbClient.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.omdbapi.api

import com.omdbapi.api.core.Credentials
import com.omdbapi.api.core.CoreClient

class OMDbClient(credentials: Credentials, debugging: Boolean = false)
: CoreClient(credentials, "https://www.omdbapi.com/", debugging) {

// the API interface for the client
val api: OMDbInterface = omdbClient.create(OMDbInterface::class.java)
}
Loading

0 comments on commit 9e37a47

Please sign in to comment.