Skip to content

Commit 3fb5f9e

Browse files
Initial commit
0 parents  commit 3fb5f9e

69 files changed

Lines changed: 4604 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Compiled class file
2+
*.class
3+
4+
# Log file
5+
*.log
6+
7+
# BlueJ files
8+
*.ctxt
9+
10+
# Mobile Tools for Java (J2ME)
11+
.mtj.tmp/
12+
13+
# Package Files #
14+
*.jar
15+
*.war
16+
*.nar
17+
*.ear
18+
*.zip
19+
*.tar.gz
20+
*.rar
21+
22+
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23+
hs_err_pid*
24+
25+
# IntelliJ
26+
.idea/
27+
*.iml
28+
29+
# Maven
30+
target/

LICENSE

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

README.md

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# Sonos API client for Java
2+
3+
This library provides a simple integration with the Sonos API, allowing you to control players and content from any Java app.
4+
5+
Please note that this library is currently still in development. Some aspects (particularly with the SMAPI) cannot be tested
6+
due to a lack of access, others due to not owning devices with specific features.
7+
8+
[![Build Status](https://travis-ci.org/nightowlengineer/sonos-api-java.svg?branch=master)](https://travis-ci.org/nightowlengineer/sonos-api-java)
9+
10+
## Prerequisites
11+
12+
Before using the library, it's recommended that you read the [official documentation](https://developer.sonos.com/build/connected-home-get-started/)
13+
published on the Sonos Developer site. The [reference documentation](https://developer.sonos.com/reference/) is also
14+
detailed and provides a good overview of the many different resources and endpoints open to you.
15+
16+
You'll need to [register with Sonos](https://integration.sonos.com/users/sign_up), [create a Control Integration](https://integration.sonos.com/control_integrations/new),
17+
and finally [generate client credentials](https://integration.sonos.com/integrations) to be able to connect with the Sonos API.
18+
It's also recommended that you have at least one Sonos device to be able to properly test and play with your application
19+
(plus, listening to music or watching movies with Sonos is awesome anyway!)
20+
21+
## Maven Setup
22+
23+
```xml
24+
<dependency>
25+
<groupId>engineer.nightowl</groupId>
26+
<artifactId>sonos-api-java</artifactId>
27+
<version>0.0.1</version>
28+
</dependency>
29+
```
30+
31+
## Getting Started
32+
33+
Create a new configuration object, set your integration's properties (see further above on how to obtain these),
34+
then create a client and pass in that configuration:
35+
```java
36+
final SonosApiConfiguration configuration = new SonosApiConfiguration();
37+
configuration.setApiKey(properties.getProperty("apiKey"));
38+
configuration.setApiSecret(properties.getProperty("apiSecret"));
39+
configuration.setApplicationId(properties.getProperty("applicationId"));
40+
41+
final SonosApiClient client = new SonosApiClient(configuration);
42+
```
43+
44+
Then use the client to view and modify the user's devices - the following types of resource are available:
45+
46+
* authorize
47+
* favorite
48+
* group
49+
* groupVolumeResource
50+
* homeTheater
51+
* household
52+
* musicServiceAccounts
53+
* playbackMetadata
54+
* playback
55+
* playbackSession
56+
* playerVolume
57+
58+
For example, to set all 'groups' (aka rooms) to use crossfade when music is playing, you could run the following:
59+
60+
```java
61+
final SonosGroups groups = client.group().getGroups("authToken", "householdId");
62+
final SonosPlayMode playMode = new SonosPlayMode();
63+
playMode.setCrossfade(true);
64+
65+
for (final SonosGroup group : groups.getGroups())
66+
{
67+
client.playback().setPlayModes("authToken", group.getId(), playMode);
68+
}
69+
```
70+
71+
## Todo
72+
73+
* Continue to add detailed Javadoc throughout the resources
74+
* Add unit testing throughout
75+
* Complete manual testing of all available endpoints

pom.xml

Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<modelVersion>4.0.0</modelVersion>
6+
7+
<groupId>engineer.nightowl</groupId>
8+
<artifactId>sonos-api-java</artifactId>
9+
<version>0.0.1-SNAPSHOT</version>
10+
<packaging>jar</packaging>
11+
12+
<name>sonos-api-java</name>
13+
<description>Java client for the Sonos API</description>
14+
<url>https://github.com/nightowlengineer/sonos-api-java</url>
15+
<inceptionYear>2018</inceptionYear>
16+
17+
<scm>
18+
<connection>scm:git:git://github.com/nightowlengineer/sonos-api-java.git</connection>
19+
<developerConnection>scm:git:ssh://git@github.com/nightowlengineer/sonos-api-java.git</developerConnection>
20+
<url>https://github.com/nightowlengineer/sonos-api-java/tree/master</url>
21+
<tag>HEAD</tag>
22+
</scm>
23+
24+
<developers>
25+
<developer>
26+
<id>nightowlengineer</id>
27+
<email>hello@nightowl.engineer</email>
28+
<url>https://nightowl.engineer</url>
29+
</developer>
30+
</developers>
31+
32+
<distributionManagement>
33+
<snapshotRepository>
34+
<id>ossrh</id>
35+
<url>https://oss.sonatype.org/content/repositories/snapshots</url>
36+
</snapshotRepository>
37+
<repository>
38+
<id>ossrh</id>
39+
<url>https://oss.sonatype.org/service/local/staging/deploy/maven2/</url>
40+
</repository>
41+
</distributionManagement>
42+
43+
<licenses>
44+
<license>
45+
<name>MIT License</name>
46+
<url>https://github.com/nightowlengineer/sonos-api-java/blob/master/LICENSE</url>
47+
<distribution>repo</distribution>
48+
</license>
49+
</licenses>
50+
51+
<properties>
52+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
53+
<maven.compiler.source>1.8</maven.compiler.source>
54+
<maven.compiler.target>1.8</maven.compiler.target>
55+
</properties>
56+
57+
<dependencies>
58+
<dependency>
59+
<groupId>junit</groupId>
60+
<artifactId>junit</artifactId>
61+
<version>4.12</version>
62+
</dependency>
63+
<dependency>
64+
<groupId>org.mockito</groupId>
65+
<artifactId>mockito-core</artifactId>
66+
<version>2.22.0</version>
67+
<scope>test</scope>
68+
</dependency>
69+
<dependency>
70+
<groupId>org.slf4j</groupId>
71+
<artifactId>slf4j-api</artifactId>
72+
<version>1.7.25</version>
73+
</dependency>
74+
<dependency>
75+
<groupId>org.slf4j</groupId>
76+
<artifactId>slf4j-simple</artifactId>
77+
<version>1.7.25</version>
78+
<scope>test</scope>
79+
</dependency>
80+
<dependency>
81+
<groupId>org.apache.commons</groupId>
82+
<artifactId>commons-lang3</artifactId>
83+
<version>3.6</version>
84+
</dependency>
85+
<dependency>
86+
<groupId>commons-io</groupId>
87+
<artifactId>commons-io</artifactId>
88+
<version>1.3.2</version>
89+
</dependency>
90+
<dependency>
91+
<groupId>org.apache.httpcomponents</groupId>
92+
<artifactId>httpclient</artifactId>
93+
<version>4.5.2</version>
94+
</dependency>
95+
<dependency>
96+
<groupId>com.fasterxml.jackson.core</groupId>
97+
<artifactId>jackson-databind</artifactId>
98+
<version>2.8.7</version>
99+
</dependency>
100+
</dependencies>
101+
102+
<build>
103+
<resources>
104+
<resource>
105+
<directory>src/main/resources</directory>
106+
<filtering>true</filtering>
107+
</resource>
108+
</resources>
109+
<plugins>
110+
<plugin>
111+
<groupId>org.apache.maven.plugins</groupId>
112+
<artifactId>maven-source-plugin</artifactId>
113+
<version>3.0.1</version>
114+
<executions>
115+
<execution>
116+
<id>attach-sources</id>
117+
<goals>
118+
<goal>jar-no-fork</goal>
119+
</goals>
120+
</execution>
121+
</executions>
122+
</plugin>
123+
<plugin>
124+
<groupId>org.apache.maven.plugins</groupId>
125+
<artifactId>maven-javadoc-plugin</artifactId>
126+
<version>3.0.1</version>
127+
<executions>
128+
<execution>
129+
<id>attach-javadocs</id>
130+
<goals>
131+
<goal>jar</goal>
132+
</goals>
133+
</execution>
134+
</executions>
135+
</plugin>
136+
<plugin>
137+
<groupId>org.apache.maven.plugins</groupId>
138+
<artifactId>maven-gpg-plugin</artifactId>
139+
<version>1.6</version>
140+
<executions>
141+
<execution>
142+
<id>sign-artifacts</id>
143+
<phase>verify</phase>
144+
<goals>
145+
<goal>sign</goal>
146+
</goals>
147+
</execution>
148+
</executions>
149+
</plugin>
150+
<plugin>
151+
<groupId>org.sonatype.plugins</groupId>
152+
<artifactId>nexus-staging-maven-plugin</artifactId>
153+
<version>1.6.8</version>
154+
<extensions>true</extensions>
155+
<configuration>
156+
<serverId>ossrh</serverId>
157+
<nexusUrl>https://oss.sonatype.org/</nexusUrl>
158+
<autoReleaseAfterClose>true</autoReleaseAfterClose>
159+
</configuration>
160+
</plugin>
161+
<plugin>
162+
<groupId>org.apache.maven.plugins</groupId>
163+
<artifactId>maven-release-plugin</artifactId>
164+
<version>2.5.3</version>
165+
<configuration>
166+
<tagNameFormat>@{project.version}</tagNameFormat>
167+
</configuration>
168+
</plugin>
169+
</plugins>
170+
</build>
171+
</project>

0 commit comments

Comments
 (0)