-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from evanwong/release/0.2
Release/0.2
- Loading branch information
Showing
43 changed files
with
1,975 additions
and
4 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,9 @@ | ||
language: java | ||
|
||
jdk: | ||
- oraclejdk8 | ||
|
||
branches: | ||
only: | ||
- master | ||
- develop |
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,2 +1,114 @@ | ||
[![Build Status](https://snap-ci.com/evanwong/hipchat-java/branch/develop/build_image)](https://snap-ci.com/evanwong/hipchat-java/branch/develop) | ||
|
||
hipchat-java | ||
============ | ||
Java client for the HipChat V2 API. The implementation is base on [this doc](https://www.hipchat.com/docs/apiv2). | ||
|
||
|
||
### Requirements: | ||
Java 8 | ||
|
||
### Quick Start: | ||
To add this client into your project: | ||
|
||
* maven | ||
```xml | ||
<dependency> | ||
<groupId>io.evanwong.oss</groupId> | ||
<artifactId>hipchat-java</artifactId> | ||
<version>0.2.0</version> | ||
</dependency> | ||
``` | ||
* gradle | ||
```gradle | ||
compile 'io.evanwong.oss:hipchat-java:0.2.0' | ||
``` | ||
|
||
To send a notification | ||
```java | ||
String defaultAccessToken = "abcd1234"; | ||
HipChatClient client = new HipChatClient(defaultAccessToken); | ||
SendRoomNotificationRequestBuilder builder = client.prepareSendRoomNotificationRequestBuilder("myRoom", "hello world!"); | ||
Future<NoContent> future = builder.setColor(Color.YELLOW).setNotify(true).build().execute(); | ||
//optional... if you want/need to inspect the result: | ||
NoContent noContent = future.get(); | ||
``` | ||
|
||
### Methods | ||
|
||
##### CAPABILITIES | ||
- [ ] Get capabilities | ||
|
||
##### EMOTICONS | ||
- [x] Get emoticon | ||
- [x] Get all emoticons | ||
|
||
##### OAUTH SESSIONS | ||
- [ ] Generate token | ||
- [ ] Get session | ||
- [ ] Delete session | ||
|
||
##### ROOMS | ||
- [x] Get all rooms | ||
- [x] Create room | ||
- [x] Get room | ||
- [ ] Update room | ||
- [x] Delete room | ||
- [ ] View room history | ||
- [ ] Get room message | ||
- [ ] View recent room history | ||
- [ ] Invite user | ||
- [ ] Add member | ||
- [ ] Remove member | ||
- [ ] Get all members | ||
- [ ] Send room notification redirect | ||
- [x] Send room notification | ||
- [ ] Get all participants | ||
- [ ] Reply to message | ||
- [ ] Share file with room | ||
- [ ] Share link with room | ||
- [ ] Get room statistics | ||
- [ ] Set topic | ||
- [ ] Get all webhooks | ||
- [ ] Create webhook | ||
- [ ] Get webhook | ||
- [ ] Delete webhook | ||
|
||
##### USERS | ||
- [ ] Get all users | ||
- [ ] Create user | ||
- [ ] View user | ||
- [ ] Update user | ||
- [ ] Delete user | ||
- [ ] Get privatechat message | ||
- [ ] View recent privatechat history | ||
- [ ] Private message user | ||
- [ ] Update photo | ||
- [ ] Delete photo | ||
- [ ] Get auto join rooms | ||
- [ ] Share file with user | ||
- [ ] Share link with user | ||
|
||
### License | ||
|
||
The MIT License (MIT) | ||
|
||
Copyright (c) 2014 Evan Wong | ||
|
||
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: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
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. |
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,46 @@ | ||
apply plugin: 'java' | ||
apply plugin: 'groovy' | ||
apply plugin: 'maven' | ||
apply plugin: 'signing' | ||
|
||
repositories { | ||
mavenCentral() | ||
mavenCentral() | ||
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" } | ||
} | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '2.1' | ||
sourceCompatibility = 1.8 | ||
|
||
group = 'io.evanwong.oss' | ||
version = "0.2.0" | ||
|
||
dependencies { | ||
compile 'org.apache.httpcomponents:httpclient:4.3.5' | ||
compile 'org.slf4j:slf4j-api:1.7.7' | ||
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2' | ||
testCompile "org.codehaus.groovy:groovy-all:2.3.7" | ||
testCompile "org.spockframework:spock-core:1.0-groovy-2.3-SNAPSHOT" | ||
runtime 'org.slf4j:slf4j-simple:1.7.7' | ||
} | ||
|
||
test { | ||
systemProperty 'hipchat.token', System.properties['hipchat.token'] | ||
} | ||
|
||
task javadocJar(type: Jar) { | ||
classifier = 'javadoc' | ||
from javadoc | ||
} | ||
|
||
task sourcesJar(type: Jar) { | ||
classifier = 'sources' | ||
from sourceSets.main.allSource | ||
} | ||
|
||
artifacts { | ||
archives javadocJar, sourcesJar | ||
} | ||
|
||
apply from: 'sonatype.gradle' | ||
|
||
task wrapper(type: Wrapper) { | ||
gradleVersion = '2.2.1' | ||
} |
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,47 @@ | ||
signing { | ||
sign configurations.archives | ||
} | ||
|
||
uploadArchives { | ||
repositories { | ||
mavenDeployer { | ||
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) } | ||
|
||
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") { | ||
authentication(userName: ossrhUsername, password: ossrhPassword) | ||
} | ||
|
||
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") { | ||
authentication(userName: ossrhUsername, password: ossrhPassword) | ||
} | ||
|
||
pom.project { | ||
name 'hipchat-java' | ||
packaging 'jar' | ||
description 'The Java client for HipChat v2 API.' | ||
url 'https://github.com/evanwong/hipchat-java' | ||
|
||
scm { | ||
connection 'scm:git:[email protected]:evanwong/hipchat-java.git' | ||
developerConnection 'scm:git:[email protected]:evanwong/hipchat-java.git' | ||
url '[email protected]:evanwong/hipchat-java.git' | ||
} | ||
|
||
licenses { | ||
license { | ||
name 'MIT License' | ||
url 'http://www.opensource.org/licenses/mit-license.php' | ||
} | ||
} | ||
|
||
developers { | ||
developer { | ||
id 'evanwong' | ||
name 'Evan Wong' | ||
email '[email protected]' | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
120 changes: 120 additions & 0 deletions
120
src/main/java/io/evanwong/oss/hipchat/v2/HipChatClient.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,120 @@ | ||
package io.evanwong.oss.hipchat.v2; | ||
|
||
import io.evanwong.oss.hipchat.v2.emoticons.GetAllEmoticonsRequestBuilder; | ||
import io.evanwong.oss.hipchat.v2.emoticons.GetEmoticonRequestBuilder; | ||
import io.evanwong.oss.hipchat.v2.rooms.*; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.io.IOException; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
public class HipChatClient { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(HipChatClient.class); | ||
|
||
private CloseableHttpClient httpClient; | ||
private ExecutorService executorService; | ||
private String defaultAccessToken; | ||
//TODO move this out | ||
private int maxConnections = 20; | ||
//TODO move this out | ||
private int maxConnectionsPerRoute = 4; | ||
|
||
|
||
public HipChatClient() { | ||
init(); | ||
} | ||
|
||
public HipChatClient(String defaultAccessToken) { | ||
this.defaultAccessToken = defaultAccessToken; | ||
init(); | ||
} | ||
|
||
private void init() { | ||
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager(); | ||
cm.setMaxTotal(maxConnections); | ||
log.debug("Max pool size: {}", maxConnections); | ||
cm.setDefaultMaxPerRoute(maxConnectionsPerRoute); | ||
log.debug("Max per route: {}", maxConnectionsPerRoute); | ||
|
||
httpClient = HttpClients.custom().setConnectionManager(cm).build(); | ||
//setting the thread pool size equal to the max connections size | ||
executorService = Executors.newFixedThreadPool(maxConnections); | ||
} | ||
|
||
public void setDefaultAccessToken(String defaultAccessToken) { | ||
this.defaultAccessToken = defaultAccessToken; | ||
} | ||
|
||
public GetAllRoomsRequestBuilder prepareGetAllRoomsRequestBuilder(String accessToken) { | ||
return new GetAllRoomsRequestBuilder(accessToken, httpClient, executorService); | ||
} | ||
|
||
public GetAllRoomsRequestBuilder prepareGetAllRoomsRequestBuilder() { | ||
return prepareGetAllRoomsRequestBuilder(defaultAccessToken); | ||
} | ||
|
||
public SendRoomNotificationRequestBuilder prepareSendRoomNotificationRequestBuilder(String idOrName, String message, String accessToken) { | ||
return new SendRoomNotificationRequestBuilder(idOrName, message, accessToken, httpClient, executorService); | ||
} | ||
|
||
public SendRoomNotificationRequestBuilder prepareSendRoomNotificationRequestBuilder(String idOrName, String message) { | ||
return prepareSendRoomNotificationRequestBuilder(idOrName, message, defaultAccessToken); | ||
} | ||
|
||
public CreateRoomRequestBuilder prepareCreateRoomRequestBuilder(String name, String accessToken) { | ||
return new CreateRoomRequestBuilder(name, accessToken, httpClient, executorService); | ||
} | ||
|
||
public CreateRoomRequestBuilder prepareCreateRoomRequestBuilder(String name) { | ||
return prepareCreateRoomRequestBuilder(name, defaultAccessToken); | ||
} | ||
|
||
public GetRoomRequestBuilder prepareGetRoomRequestBuilder(String idOrName, String accessToken) { | ||
return new GetRoomRequestBuilder(idOrName, accessToken, httpClient, executorService); | ||
} | ||
|
||
public GetRoomRequestBuilder prepareGetRoomRequestBuilder(String idOrName) { | ||
return prepareGetRoomRequestBuilder(idOrName, defaultAccessToken); | ||
} | ||
|
||
public GetEmoticonRequestBuilder prepareGetEmoticonRequestBuilder(String idOrShortcut) { | ||
return prepareGetEmoticonRequestBuilder(idOrShortcut); | ||
} | ||
|
||
public GetEmoticonRequestBuilder prepareGetEmoticonRequestBuilder(String idOrShortcut, String accessToken) { | ||
return new GetEmoticonRequestBuilder(idOrShortcut, accessToken, httpClient, executorService); | ||
} | ||
|
||
public GetAllEmoticonsRequestBuilder prepareGetAllEmoticonsRequestBuilder() { | ||
return prepareGetAllEmoticonsRequestBuilder(defaultAccessToken); | ||
} | ||
|
||
public GetAllEmoticonsRequestBuilder prepareGetAllEmoticonsRequestBuilder(String accessToken) { | ||
return new GetAllEmoticonsRequestBuilder(accessToken, httpClient, executorService); | ||
} | ||
|
||
public DeleteRoomRequestBuilder prepareDeleteRoomRequestBuilder(String roomIdOrName) { | ||
return prepareDeleteRoomRequestBuilder(roomIdOrName, defaultAccessToken); | ||
} | ||
|
||
public DeleteRoomRequestBuilder prepareDeleteRoomRequestBuilder(String roomIdOrName, String accessToken) { | ||
return new DeleteRoomRequestBuilder(roomIdOrName, accessToken, httpClient, executorService); | ||
} | ||
|
||
public void close() { | ||
log.info("Shutting down..."); | ||
try { | ||
httpClient.close(); | ||
} catch (IOException e) { | ||
log.error("Failed to close the HttpClient.", e); | ||
} | ||
executorService.shutdown(); | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/io/evanwong/oss/hipchat/v2/commons/Created.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,23 @@ | ||
package io.evanwong.oss.hipchat.v2.commons; | ||
|
||
public class Created { | ||
|
||
private Long id; | ||
private Links links; | ||
|
||
public Long getId() { | ||
return id; | ||
} | ||
|
||
public void setId(Long id) { | ||
this.id = id; | ||
} | ||
|
||
public Links getLinks() { | ||
return links; | ||
} | ||
|
||
public void setLinks(Links links) { | ||
this.links = links; | ||
} | ||
} |
Oops, something went wrong.