Skip to content
This repository was archived by the owner on Feb 9, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ hipChat.roomsAPI().sendRoomNotification(new Notification("Hello World", MessageC
- [ ] Get room web panel
- [ ] Create room web panel
- [ ] Delete room web panel
- [ ] Get room webhook
- [ ] Create room webhook
- [ ] Delete room webhook
- [x] Get room webhook
- [x] Create room webhook
- [x] Delete room webhook
- [ ] Get room message
- [ ] View room history
- [ ] View recent room history
Expand All @@ -71,10 +71,10 @@ hipChat.roomsAPI().sendRoomNotification(new Notification("Hello World", MessageC
- [ ] Share link with room
- [ ] Get room statistics
- [x] Set topic
- [ ] Get all webhooks
- [ ] Create webhook
- [ ] Get webhook
- [ ] Delete webhook
- [x] Get all webhooks
- [ ] *Create webhook* -> Deprecated
- [ ] *Get webhook* -> Deprecated
- [ ] *Delete webhook* -> Deprecated

##### Users API (0/15)
- [ ] Get all users
Expand Down
73 changes: 62 additions & 11 deletions src/main/java/ch/viascom/hipchat/api/api/RoomsAPI.java
Original file line number Diff line number Diff line change
Expand Up @@ -236,16 +236,55 @@ public void deleteRoomWebPanel() {

}

public void getRoomWebhook() {

/**
* Retrieve a webhook.
* <p>
* Method: GET
* Url: /v2/room/{room_id_or_name}/extension/webhook/{key}
* Access: group clients, room clients
*
* @param getRoomWebhook
* @return
* @throws APIException
*/
public GetRoomWebhookResponse getRoomWebhook(GetRoomWebhook getRoomWebhook) throws APIException {
GetRoomWebhookRequest getRoomWebhookRequest = new GetRoomWebhookRequest(getRoomWebhook, accessToken, baseUrl, httpClient, executorService);
return getRoomWebhookRequest.execute();
}

public void createRoomWebhook() {

/**
* Create a webhook.
* Dynamically created webhooks have the following restrictions:
* - You can only create 10 webhooks in a room
* - You cannot modify a webhook that was declared in the descriptor
* <p>
* Method: PUT
* Url: /v2/room/{room_id_or_name}/extension/webhook/{key}
* Access: group clients, room clients
*
* @param createRoomWebhook
* @return
* @throws APIException
*/
public CreateRoomWebhookResponse createRoomWebhook(CreateRoomWebhook createRoomWebhook) throws APIException {
CreateRoomWebhookRequest createRoomWebhookRequest = new CreateRoomWebhookRequest(createRoomWebhook,accessToken, baseUrl, httpClient, executorService);
return createRoomWebhookRequest.execute();
}

public void deleteRoomWebhook() {

/**
* Delete a webhook. You cannot delete a webhook that was declared in the descriptor.
* <p>
* Method: DELETE
* Url: /v2/room/{room_id_or_name}/extension/webhook/{key}
* Access: group clients, room clients
*
* @param deleteRoomWebhook
* @return
* @throws APIException
*/
public NoContentResponse deleteRoomWebhook(DeleteRoomWebhook deleteRoomWebhook) throws APIException {
DeleteRoomWebhookRequest deleteRoomWebhookRequest = new DeleteRoomWebhookRequest(deleteRoomWebhook, accessToken, baseUrl, httpClient, executorService);
return deleteRoomWebhookRequest.execute();
}

public void getRoomMessage() {
Expand Down Expand Up @@ -316,19 +355,31 @@ public void getRoomStatistics() {

}

public void getAllWebhooks() {

/**
* Gets all webhooks for this room.
* <p>
* Method: GET
* Url: /v2/room/{room_id_or_name}/webhook
* Access: group clients, room clients, users
*
* @param getAllWebhooks
* @return
* @throws APIException
*/
public GetAllWebhooksResponse getAllWebhooks(GetAllWebhooks getAllWebhooks) throws APIException {
GetAllWebhooksRequest getAllWebhooksRequest = new GetAllWebhooksRequest(getAllWebhooks, accessToken, baseUrl, httpClient, executorService);
return getAllWebhooksRequest.execute();
}

@Deprecated
public void createWebhook() {

}

@Deprecated
public void getWebhook() {

}

@Deprecated
public void deleteWebhook() {

}
}
3 changes: 3 additions & 0 deletions src/main/java/ch/viascom/hipchat/api/models/Room.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,7 @@ public class Room {
private String topic;
private String owner_user_id;
private boolean guest_access = false;
private boolean is_archived;
private String version;
private int id;
}
21 changes: 21 additions & 0 deletions src/main/java/ch/viascom/hipchat/api/models/Webhook.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ch.viascom.hipchat.api.models;

import ch.viascom.hipchat.api.models.webhook.WebhookAuthentication;
import ch.viascom.hipchat.api.models.webhook.WebhookEvent;
import lombok.Data;

/**
* Created by patrickboesch on 18.04.16.
*/
@Data
public class Webhook {
private String name;
private String url;
private String pattern;
private WebhookEvent event;
private WebhookAuthentication authentication = WebhookAuthentication.NONE;
private String key;
private int id;
private String created;
private Room room;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package ch.viascom.hipchat.api.models.webhook;

import com.google.gson.annotations.SerializedName;

/**
* Created by patrickboesch on 18.04.16.
*/
public enum WebhookAuthentication {
@SerializedName("jwt")
JWT,
@SerializedName("none")
NONE
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ch.viascom.hipchat.api.models.webhook;

import com.google.gson.annotations.SerializedName;

/**
* Created by patrickboesch on 18.04.16.
*/
public enum WebhookEvent {
@SerializedName("room_archived")
ROOM_ARCHIVED,
@SerializedName("room_created")
ROOM_CREATED,
@SerializedName("room_deleted")
ROOM_DELETED,
@SerializedName("room_enter")
ROOM_ENTER,
@SerializedName("room_exit")
ROOM_EXIT,
@SerializedName("room_file_upload")
ROOM_FILE_UPLOAD,
@SerializedName("room_message")
ROOM_MESSAGE,
@SerializedName("room_notification")
ROOM_NOTIFICATION,
@SerializedName("room_topic_change")
ROOM_TOPIC_CHANGE,
@SerializedName("room_unarchived")
ROOM_UNARCHIVED
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package ch.viascom.hipchat.api.request;

import ch.viascom.hipchat.api.request.generic.PutRequest;
import ch.viascom.hipchat.api.request.models.CreateRoomWebhook;
import ch.viascom.hipchat.api.response.CreateRoomWebhookResponse;
import ch.viascom.hipchat.api.util.JsonUtil;
import org.apache.http.client.HttpClient;

import java.util.concurrent.ExecutorService;

/**
* Created by patrickboesch on 18.04.16.
*/
public class CreateRoomWebhookRequest extends PutRequest<CreateRoomWebhookResponse> {
private CreateRoomWebhook createRoomWebhook;

public CreateRoomWebhookRequest(CreateRoomWebhook createRoomWebhook, String accessToken, String baseUrl, HttpClient httpClient, ExecutorService executorService) {
super(accessToken, baseUrl, httpClient, executorService);
this.createRoomWebhook = createRoomWebhook;
}

@Override
protected String getJsonBody() {
return JsonUtil.getJsonBody(createRoomWebhook);
}

@Override
protected String getPath() {
return "/room/" + createRoomWebhook.getRoomId() + "/extension/webhook/" + createRoomWebhook.getKey();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package ch.viascom.hipchat.api.request;

import ch.viascom.hipchat.api.request.generic.DeleteRequest;
import ch.viascom.hipchat.api.request.models.DeleteRoomWebhook;
import ch.viascom.hipchat.api.response.NoContentResponse;
import org.apache.http.client.HttpClient;

import java.util.concurrent.ExecutorService;

/**
* Created by patrickboesch on 18.04.16.
*/
public class DeleteRoomWebhookRequest extends DeleteRequest<NoContentResponse> {
private DeleteRoomWebhook deleteRoomWebhook;

public DeleteRoomWebhookRequest(DeleteRoomWebhook deleteRoomWebhook, String accessToken, String baseUrl, HttpClient httpClient, ExecutorService executorService) {
super(accessToken, baseUrl, httpClient, executorService);
this.deleteRoomWebhook = deleteRoomWebhook;
}

@Override
protected String getPath() {
return "/room/" + deleteRoomWebhook.getRoomId() + "/extension/webhook/" + deleteRoomWebhook.getWebhookId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package ch.viascom.hipchat.api.request;

import ch.viascom.hipchat.api.request.generic.GetRequest;
import ch.viascom.hipchat.api.request.models.GetAllWebhooks;
import ch.viascom.hipchat.api.response.GetAllWebhooksResponse;
import org.apache.http.client.HttpClient;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;

/**
* Created by patrickboesch on 18.04.16.
*/
public class GetAllWebhooksRequest extends GetRequest<GetAllWebhooksResponse> {

private GetAllWebhooks getAllWebhooks;

public GetAllWebhooksRequest(GetAllWebhooks getAllWebhooks, String accessToken, String baseUrl, HttpClient httpClient, ExecutorService executorService) {
super(accessToken, baseUrl, httpClient, executorService);
this.getAllWebhooks = getAllWebhooks;
}

@Override
protected String getPath() {
return "/room/" + getAllWebhooks.getRoomId() + "/webhook";
}

@Override
protected HashMap<String, String> getQueryParam() {
HashMap<String, String> param = new HashMap<>();
param.put("start-index", String.valueOf(getAllWebhooks.getStart_index()));
param.put("max-results", String.valueOf(getAllWebhooks.getMax_results()));
return param;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
* Created by patrickboesch on 13.04.16.
*/
public class GetRoomRequet extends GetRequest<GetRoomResponse> {


private String roomId;

public GetRoomRequet(String roomId, String accessToken, String baseUrl, HttpClient httpClient, ExecutorService executorService) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package ch.viascom.hipchat.api.request;

import ch.viascom.hipchat.api.request.generic.GetRequest;
import ch.viascom.hipchat.api.request.models.GetRoomWebhook;
import ch.viascom.hipchat.api.response.GetRoomWebhookResponse;
import org.apache.http.client.HttpClient;

import java.util.HashMap;
import java.util.concurrent.ExecutorService;

/**
* Created by patrickboesch on 18.04.16.
*/
public class GetRoomWebhookRequest extends GetRequest<GetRoomWebhookResponse> {
private GetRoomWebhook getRoomWebhook;

public GetRoomWebhookRequest(GetRoomWebhook getRoomWebhook, String accessToken, String baseUrl, HttpClient httpClient, ExecutorService executorService) {
super(accessToken, baseUrl, httpClient, executorService);
this.getRoomWebhook = getRoomWebhook;
}

@Override
protected String getPath() {
return "/room/" + getRoomWebhook.getRoomId() + "/extension/webhook/" + getRoomWebhook.getWebhookId();
}

@Override
protected HashMap<String, String> getQueryParam() {
HashMap<String, String> param = new HashMap<>();
return param;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ch.viascom.hipchat.api.request.models;

import ch.viascom.hipchat.api.models.webhook.WebhookAuthentication;
import ch.viascom.hipchat.api.models.webhook.WebhookEvent;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Created by patrickboesch on 18.04.16.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class CreateRoomWebhook {
private String roomId;
private String key;
private String name;
private String url;
private String pattern;
private WebhookEvent event;
private WebhookAuthentication authentication = WebhookAuthentication.NONE;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package ch.viascom.hipchat.api.request.models;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Created by patrickboesch on 18.04.16.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DeleteRoomWebhook {
private String roomId;
private String webhookId;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package ch.viascom.hipchat.api.request.models;

import com.google.gson.annotations.SerializedName;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
* Created by patrickboesch on 18.04.16.
*/
@Data
@AllArgsConstructor
@NoArgsConstructor
public class GetAllWebhooks {
private String roomId;
@SerializedName("start-index")
private int start_index = 0;
@SerializedName("max-results")
private int max_results = 100;
}
Loading