Skip to content

Commit 3397ef8

Browse files
author
Evan Wong
committed
Merge pull request #9 from evanwong/release/0.2
Release/0.2
2 parents 1f3e6d6 + e090cb1 commit 3397ef8

43 files changed

Lines changed: 1975 additions & 4 deletions

Some content is hidden

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

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: java
2+
3+
jdk:
4+
- oraclejdk8
5+
6+
branches:
7+
only:
8+
- master
9+
- develop

README.md

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,114 @@
1+
[![Build Status](https://snap-ci.com/evanwong/hipchat-java/branch/develop/build_image)](https://snap-ci.com/evanwong/hipchat-java/branch/develop)
2+
13
hipchat-java
24
============
5+
Java client for the HipChat V2 API. The implementation is base on [this doc](https://www.hipchat.com/docs/apiv2).
6+
7+
8+
### Requirements:
9+
Java 8
10+
11+
### Quick Start:
12+
To add this client into your project:
13+
14+
* maven
15+
```xml
16+
<dependency>
17+
<groupId>io.evanwong.oss</groupId>
18+
<artifactId>hipchat-java</artifactId>
19+
<version>0.2.0</version>
20+
</dependency>
21+
```
22+
* gradle
23+
```gradle
24+
compile 'io.evanwong.oss:hipchat-java:0.2.0'
25+
```
26+
27+
To send a notification
28+
```java
29+
String defaultAccessToken = "abcd1234";
30+
HipChatClient client = new HipChatClient(defaultAccessToken);
31+
SendRoomNotificationRequestBuilder builder = client.prepareSendRoomNotificationRequestBuilder("myRoom", "hello world!");
32+
Future<NoContent> future = builder.setColor(Color.YELLOW).setNotify(true).build().execute();
33+
//optional... if you want/need to inspect the result:
34+
NoContent noContent = future.get();
35+
```
36+
37+
### Methods
38+
39+
##### CAPABILITIES
40+
- [ ] Get capabilities
41+
42+
##### EMOTICONS
43+
- [x] Get emoticon
44+
- [x] Get all emoticons
45+
46+
##### OAUTH SESSIONS
47+
- [ ] Generate token
48+
- [ ] Get session
49+
- [ ] Delete session
50+
51+
##### ROOMS
52+
- [x] Get all rooms
53+
- [x] Create room
54+
- [x] Get room
55+
- [ ] Update room
56+
- [x] Delete room
57+
- [ ] View room history
58+
- [ ] Get room message
59+
- [ ] View recent room history
60+
- [ ] Invite user
61+
- [ ] Add member
62+
- [ ] Remove member
63+
- [ ] Get all members
64+
- [ ] Send room notification redirect
65+
- [x] Send room notification
66+
- [ ] Get all participants
67+
- [ ] Reply to message
68+
- [ ] Share file with room
69+
- [ ] Share link with room
70+
- [ ] Get room statistics
71+
- [ ] Set topic
72+
- [ ] Get all webhooks
73+
- [ ] Create webhook
74+
- [ ] Get webhook
75+
- [ ] Delete webhook
76+
77+
##### USERS
78+
- [ ] Get all users
79+
- [ ] Create user
80+
- [ ] View user
81+
- [ ] Update user
82+
- [ ] Delete user
83+
- [ ] Get privatechat message
84+
- [ ] View recent privatechat history
85+
- [ ] Private message user
86+
- [ ] Update photo
87+
- [ ] Delete photo
88+
- [ ] Get auto join rooms
89+
- [ ] Share file with user
90+
- [ ] Share link with user
91+
92+
### License
93+
94+
The MIT License (MIT)
95+
96+
Copyright (c) 2014 Evan Wong
97+
98+
Permission is hereby granted, free of charge, to any person obtaining a copy
99+
of this software and associated documentation files (the "Software"), to deal
100+
in the Software without restriction, including without limitation the rights
101+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
102+
copies of the Software, and to permit persons to whom the Software is
103+
furnished to do so, subject to the following conditions:
104+
105+
The above copyright notice and this permission notice shall be included in all
106+
copies or substantial portions of the Software.
107+
108+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
109+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
110+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
111+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
112+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
113+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
114+
SOFTWARE.

build.gradle

Lines changed: 40 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,46 @@
1-
apply plugin: 'java'
1+
apply plugin: 'groovy'
2+
apply plugin: 'maven'
3+
apply plugin: 'signing'
24

35
repositories {
4-
mavenCentral()
6+
mavenCentral()
7+
maven { url "http://oss.sonatype.org/content/repositories/snapshots/" }
58
}
69

7-
task wrapper(type: Wrapper) {
8-
gradleVersion = '2.1'
10+
sourceCompatibility = 1.8
11+
12+
group = 'io.evanwong.oss'
13+
version = "0.2.0"
14+
15+
dependencies {
16+
compile 'org.apache.httpcomponents:httpclient:4.3.5'
17+
compile 'org.slf4j:slf4j-api:1.7.7'
18+
compile 'com.fasterxml.jackson.core:jackson-databind:2.4.2'
19+
testCompile "org.codehaus.groovy:groovy-all:2.3.7"
20+
testCompile "org.spockframework:spock-core:1.0-groovy-2.3-SNAPSHOT"
21+
runtime 'org.slf4j:slf4j-simple:1.7.7'
22+
}
23+
24+
test {
25+
systemProperty 'hipchat.token', System.properties['hipchat.token']
26+
}
27+
28+
task javadocJar(type: Jar) {
29+
classifier = 'javadoc'
30+
from javadoc
931
}
1032

33+
task sourcesJar(type: Jar) {
34+
classifier = 'sources'
35+
from sourceSets.main.allSource
36+
}
37+
38+
artifacts {
39+
archives javadocJar, sourcesJar
40+
}
41+
42+
apply from: 'sonatype.gradle'
43+
44+
task wrapper(type: Wrapper) {
45+
gradleVersion = '2.2.1'
46+
}

sonatype.gradle

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
signing {
2+
sign configurations.archives
3+
}
4+
5+
uploadArchives {
6+
repositories {
7+
mavenDeployer {
8+
beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }
9+
10+
repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
11+
authentication(userName: ossrhUsername, password: ossrhPassword)
12+
}
13+
14+
snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
15+
authentication(userName: ossrhUsername, password: ossrhPassword)
16+
}
17+
18+
pom.project {
19+
name 'hipchat-java'
20+
packaging 'jar'
21+
description 'The Java client for HipChat v2 API.'
22+
url 'https://github.com/evanwong/hipchat-java'
23+
24+
scm {
25+
connection 'scm:git:git@github.com:evanwong/hipchat-java.git'
26+
developerConnection 'scm:git:git@github.com:evanwong/hipchat-java.git'
27+
url 'git@github.com:evanwong/hipchat-java.git'
28+
}
29+
30+
licenses {
31+
license {
32+
name 'MIT License'
33+
url 'http://www.opensource.org/licenses/mit-license.php'
34+
}
35+
}
36+
37+
developers {
38+
developer {
39+
id 'evanwong'
40+
name 'Evan Wong'
41+
email 'evan@evanwong.io'
42+
}
43+
}
44+
}
45+
}
46+
}
47+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
package io.evanwong.oss.hipchat.v2;
2+
3+
import io.evanwong.oss.hipchat.v2.emoticons.GetAllEmoticonsRequestBuilder;
4+
import io.evanwong.oss.hipchat.v2.emoticons.GetEmoticonRequestBuilder;
5+
import io.evanwong.oss.hipchat.v2.rooms.*;
6+
import org.apache.http.impl.client.CloseableHttpClient;
7+
import org.apache.http.impl.client.HttpClients;
8+
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
9+
import org.slf4j.Logger;
10+
import org.slf4j.LoggerFactory;
11+
12+
import java.io.IOException;
13+
import java.util.concurrent.ExecutorService;
14+
import java.util.concurrent.Executors;
15+
16+
public class HipChatClient {
17+
18+
private static final Logger log = LoggerFactory.getLogger(HipChatClient.class);
19+
20+
private CloseableHttpClient httpClient;
21+
private ExecutorService executorService;
22+
private String defaultAccessToken;
23+
//TODO move this out
24+
private int maxConnections = 20;
25+
//TODO move this out
26+
private int maxConnectionsPerRoute = 4;
27+
28+
29+
public HipChatClient() {
30+
init();
31+
}
32+
33+
public HipChatClient(String defaultAccessToken) {
34+
this.defaultAccessToken = defaultAccessToken;
35+
init();
36+
}
37+
38+
private void init() {
39+
PoolingHttpClientConnectionManager cm = new PoolingHttpClientConnectionManager();
40+
cm.setMaxTotal(maxConnections);
41+
log.debug("Max pool size: {}", maxConnections);
42+
cm.setDefaultMaxPerRoute(maxConnectionsPerRoute);
43+
log.debug("Max per route: {}", maxConnectionsPerRoute);
44+
45+
httpClient = HttpClients.custom().setConnectionManager(cm).build();
46+
//setting the thread pool size equal to the max connections size
47+
executorService = Executors.newFixedThreadPool(maxConnections);
48+
}
49+
50+
public void setDefaultAccessToken(String defaultAccessToken) {
51+
this.defaultAccessToken = defaultAccessToken;
52+
}
53+
54+
public GetAllRoomsRequestBuilder prepareGetAllRoomsRequestBuilder(String accessToken) {
55+
return new GetAllRoomsRequestBuilder(accessToken, httpClient, executorService);
56+
}
57+
58+
public GetAllRoomsRequestBuilder prepareGetAllRoomsRequestBuilder() {
59+
return prepareGetAllRoomsRequestBuilder(defaultAccessToken);
60+
}
61+
62+
public SendRoomNotificationRequestBuilder prepareSendRoomNotificationRequestBuilder(String idOrName, String message, String accessToken) {
63+
return new SendRoomNotificationRequestBuilder(idOrName, message, accessToken, httpClient, executorService);
64+
}
65+
66+
public SendRoomNotificationRequestBuilder prepareSendRoomNotificationRequestBuilder(String idOrName, String message) {
67+
return prepareSendRoomNotificationRequestBuilder(idOrName, message, defaultAccessToken);
68+
}
69+
70+
public CreateRoomRequestBuilder prepareCreateRoomRequestBuilder(String name, String accessToken) {
71+
return new CreateRoomRequestBuilder(name, accessToken, httpClient, executorService);
72+
}
73+
74+
public CreateRoomRequestBuilder prepareCreateRoomRequestBuilder(String name) {
75+
return prepareCreateRoomRequestBuilder(name, defaultAccessToken);
76+
}
77+
78+
public GetRoomRequestBuilder prepareGetRoomRequestBuilder(String idOrName, String accessToken) {
79+
return new GetRoomRequestBuilder(idOrName, accessToken, httpClient, executorService);
80+
}
81+
82+
public GetRoomRequestBuilder prepareGetRoomRequestBuilder(String idOrName) {
83+
return prepareGetRoomRequestBuilder(idOrName, defaultAccessToken);
84+
}
85+
86+
public GetEmoticonRequestBuilder prepareGetEmoticonRequestBuilder(String idOrShortcut) {
87+
return prepareGetEmoticonRequestBuilder(idOrShortcut);
88+
}
89+
90+
public GetEmoticonRequestBuilder prepareGetEmoticonRequestBuilder(String idOrShortcut, String accessToken) {
91+
return new GetEmoticonRequestBuilder(idOrShortcut, accessToken, httpClient, executorService);
92+
}
93+
94+
public GetAllEmoticonsRequestBuilder prepareGetAllEmoticonsRequestBuilder() {
95+
return prepareGetAllEmoticonsRequestBuilder(defaultAccessToken);
96+
}
97+
98+
public GetAllEmoticonsRequestBuilder prepareGetAllEmoticonsRequestBuilder(String accessToken) {
99+
return new GetAllEmoticonsRequestBuilder(accessToken, httpClient, executorService);
100+
}
101+
102+
public DeleteRoomRequestBuilder prepareDeleteRoomRequestBuilder(String roomIdOrName) {
103+
return prepareDeleteRoomRequestBuilder(roomIdOrName, defaultAccessToken);
104+
}
105+
106+
public DeleteRoomRequestBuilder prepareDeleteRoomRequestBuilder(String roomIdOrName, String accessToken) {
107+
return new DeleteRoomRequestBuilder(roomIdOrName, accessToken, httpClient, executorService);
108+
}
109+
110+
public void close() {
111+
log.info("Shutting down...");
112+
try {
113+
httpClient.close();
114+
} catch (IOException e) {
115+
log.error("Failed to close the HttpClient.", e);
116+
}
117+
executorService.shutdown();
118+
}
119+
120+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package io.evanwong.oss.hipchat.v2.commons;
2+
3+
public class Created {
4+
5+
private Long id;
6+
private Links links;
7+
8+
public Long getId() {
9+
return id;
10+
}
11+
12+
public void setId(Long id) {
13+
this.id = id;
14+
}
15+
16+
public Links getLinks() {
17+
return links;
18+
}
19+
20+
public void setLinks(Links links) {
21+
this.links = links;
22+
}
23+
}

0 commit comments

Comments
 (0)