forked from maximilianvoss/toniebox-api
-
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.
In which our hero did all the adaptions which are necessary for the n…
…ew Toniebox API
- Loading branch information
Maximilian Voß
committed
Mar 8, 2019
1 parent
c1ff54f
commit fc1dd42
Showing
26 changed files
with
530 additions
and
411 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
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,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
57
example/src/main/java/rocks/voss/toniebox/example/Application.java
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,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 not shown.
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
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 |
---|---|---|
@@ -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/"; | ||
} |
Oops, something went wrong.