Skip to content

Commit

Permalink
In which our hero did all the adaptions which are necessary for the n…
Browse files Browse the repository at this point in the history
…ew Toniebox API
  • Loading branch information
Maximilian Voß committed Mar 8, 2019
1 parent c1ff54f commit fc1dd42
Show file tree
Hide file tree
Showing 26 changed files with 530 additions and 411 deletions.
39 changes: 2 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,48 +15,13 @@ mvn clean install
<dependency>
<groupId>rocks.voss</groupId>
<artifactId>toniebox-api</artifactId>
<version>1.0-SNAPSHOT</version>
<version>2.0</version>
</dependency>
</dependencies>
```

# Getting Started
```Java
package rocks.voss;

import org.apache.commons.lang3.StringUtils;
import rocks.voss.toniebox.beans.Tonie;
import rocks.voss.toniebox.TonieHandler;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.Properties;

public class Application {
public static void main(String[] args) throws IOException {

TonieHandler tonieHandler = new TonieHandler("USERNAME", "PASSWORD");
List<Tonie> tonies = tonieHandler.getTonies();

for (Tonie tonie : tonies) {
if (StringUtils.equals(tonie.getTonieName(), "TONIES NAME")) {

// delete entire content from the Tonie
tonieHandler.deleteTonieContent(tonie);

// rename the Tonie
tonieHandler.changeTonieName(tonie, "Tonies New Name");

// upload file to Tonie
tonieHandler.uploadFile(tonie, "New Track", "PATH_TO_MP3.mp3");
return;
}
}
}
}

```
See code in [example/src/main/java/rocks/voss/toniebox/example/Application.java]

# Known Issues
No issues known yet
Expand Down
81 changes: 81 additions & 0 deletions example/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?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>rocks.voss</groupId>
<artifactId>toniebox-api-example</artifactId>
<version>2.0-SNAPSHOT</version>
<name>Toniebox API Example</name>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>

<dependencies>
<dependency>
<groupId>rocks.voss</groupId>
<artifactId>toniebox-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>rocks.voss.toniebox.example.Application</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
57 changes: 57 additions & 0 deletions example/src/main/java/rocks/voss/toniebox/example/Application.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package rocks.voss.toniebox.example;

import org.apache.commons.io.IOUtils;
import rocks.voss.toniebox.TonieHandler;
import rocks.voss.toniebox.beans.toniebox.Chapter;
import rocks.voss.toniebox.beans.toniebox.CreativeTonie;
import rocks.voss.toniebox.beans.toniebox.Household;
import rocks.voss.toniebox.beans.toniebox.Me;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.List;

public class Application {
private final static String USERNAME = "<YOUR TONIEBOX USERNAME>";
private final static String PASSWORD = "<YOUR TONIEBOX PASSWORD";

public static void main(String[] args) throws IOException, InterruptedException {
TonieHandler tonieHandler = new TonieHandler(USERNAME, PASSWORD);

// get what is stored about you as a person
Me me = tonieHandler.getMe();
System.out.println(me);

// get all households you're in & select first one
List<Household> households = tonieHandler.getHouseholds();
Household household = households.get(0);

// get all creative tonies & select first one
List<CreativeTonie> creativeTonies = tonieHandler.getCreativeTonies(household);
CreativeTonie creativeTonie = creativeTonies.get(0);

// load a MP3 out of the resource as dummy
ClassLoader loader = Thread.currentThread().getContextClassLoader();
File tempFile = File.createTempFile("test", ".mp3");
tempFile.deleteOnExit();
tempFile.getAbsoluteFile();
IOUtils.copy(loader.getResourceAsStream("file.mp3"), new FileOutputStream(tempFile));

// upload the dummy MP3 to the tonie box
creativeTonie.uploadFile("--THIS IS A TEST UPLOAD--", tempFile.getAbsolutePath());

// find the uploaded chapter again and delete it
Chapter chapter = creativeTonie.findChapterByTitle("--THIS IS A TEST UPLOAD--");
creativeTonie.deleteChapter(chapter);

// rename the creative tonie and reset the name
String oldName = creativeTonie.getName();
creativeTonie.setName("--THIS IS A TEST NAME--");
creativeTonie.setName(oldName);

// do a commit - write changes to tonie box
// there seems to be a request limit per second/minute so don't commit every small change
creativeTonie.commit();
}
}
Binary file added example/src/main/resources/file.mp3
Binary file not shown.
19 changes: 14 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>rocks.voss</groupId>
<artifactId>toniebox-api</artifactId>
<version>1.3-SNAPSHOT</version>
<version>2.0-SNAPSHOT</version>
<name>Toniebox API</name>
<url>https://maximilian.voss.rocks</url>

Expand Down Expand Up @@ -43,15 +43,25 @@

<dependencies>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.7</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.0</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
Expand Down Expand Up @@ -167,7 +177,6 @@
</plugins>
</build>


<distributionManagement>
<snapshotRepository>
<id>ossrh</id>
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/rocks/voss/toniebox/Constants.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package rocks.voss.toniebox;

class Constants {
protected final static String LOGIN_PAGE = "https://meine.tonies.de/accounts/login/";
protected final static String SUMMARY_PAGE = "https://meine.tonies.de/";
protected final static String TONIE_PAGE = "https://meine.tonies.de/tonies/%s/";
protected final static String TONIE_CONTENT = "https://meine.tonies.de/tonies/%s/content/";
protected final static String TONIE_NAME = "https://meine.tonies.de/tonies/%s/name/";
protected final static String TONIE_AMAZON_PRE_SIGNED_URL = "https://meine.tonies.de/tonies/pre_signed_url/?csrfmiddlewaretoken=%s";
protected final static String CREATIVE_TONIES = "https://api.tonie.cloud/v2/households/%h/creativetonies";
protected final static String CREATIVE_TONIE = "https://api.tonie.cloud/v2/households/%h/creativetonies/%t";
protected final static String SESSION = "https://api.tonie.cloud/v2/sessions";
protected final static String ME = "https://api.tonie.cloud/v2/me";
protected final static String HOUSEHOLDS = "https://api.tonie.cloud/v2/households";
protected final static String FILE_UPLOAD = "https://api.tonie.cloud/v2/file";
protected final static String FILE_UPLOAD_AMAZON = "https://bxn-toniecloud-prod-upload.s3.amazonaws.com/";
}
Loading

0 comments on commit fc1dd42

Please sign in to comment.