Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrating to Hipchat API v2; fixes #270 #294

Merged
merged 1 commit into from May 6, 2015
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -42,19 +42,16 @@

private final SeyrenConfig seyrenConfig;
private final String baseUrl;
private final String apiVersion;

@Inject
public HipChatNotificationService(SeyrenConfig seyrenConfig) {
this.seyrenConfig = seyrenConfig;
this.baseUrl = seyrenConfig.getHipChatBaseUrl();
this.apiVersion = seyrenConfig.getHipChatApiVersion();
}

protected HipChatNotificationService(SeyrenConfig seyrenConfig, String baseUrl) {
this.seyrenConfig = seyrenConfig;
this.baseUrl = baseUrl;
this.apiVersion = seyrenConfig.getHipChatApiVersion();
}

@Override
@@ -89,18 +86,16 @@ private void sendMessage(String message, MessageColor color, String[] roomIds, S
for (String roomId : roomIds) {
LOGGER.info("Posting: {} to {}: {} {}", from, roomId, message, color);
HttpClient client = HttpClientBuilder.create().build();
String url = baseUrl + "/v" + apiVersion + "/rooms/message";
String url = baseUrl + "/v2/room/" + roomId + "/notification?auth_token=" + authToken;
HttpPost post = new HttpPost(url);

try {
List<BasicNameValuePair> parameters = new ArrayList<BasicNameValuePair>();
parameters.add(new BasicNameValuePair("auth_token", authToken));
parameters.add(new BasicNameValuePair("from", from));
parameters.add(new BasicNameValuePair("room_id", roomId));
parameters.add(new BasicNameValuePair("message", message));
parameters.add(new BasicNameValuePair("color", color.name().toLowerCase()));
parameters.add(new BasicNameValuePair("message_format", "html"));
if (notify) {
parameters.add(new BasicNameValuePair("notify", "1"));
parameters.add(new BasicNameValuePair("notify", "true"));
}
post.setEntity(new UrlEncodedFormEntity(parameters));
client.execute(post);
@@ -53,7 +53,6 @@
private final String twilioAuthToken;
private final String twilioPhoneNumber;
private final String hipChatBaseUrl;
private final String hipChatApiVersion;
private final String hipChatAuthToken;
private final String hipChatUsername;
private final String hubotUrl;
@@ -116,7 +115,6 @@ public SeyrenConfig() {

// HipChat
this.hipChatBaseUrl = configOrDefault(list("HIPCHAT_BASEURL", "HIPCHAT_BASE_URL"), "https://api.hipchat.com");
this.hipChatApiVersion = configOrDefault(list("HIPCHAT_APIVERSION", "HIPCHAT_API_VERSION"), "1");
this.hipChatAuthToken = configOrDefault(list("HIPCHAT_AUTHTOKEN", "HIPCHAT_AUTH_TOKEN"), "");
this.hipChatUsername = configOrDefault(list("HIPCHAT_USERNAME", "HIPCHAT_USER_NAME"), "Seyren Alert");

@@ -208,11 +206,6 @@ public String getHipChatBaseUrl() {
return hipChatBaseUrl;
}

@JsonIgnore
public String getHipChatApiVersion() {
return hipChatApiVersion;
}

@JsonIgnore
public String getHipChatAuthToken() {
return hipChatAuthToken;
@@ -70,14 +70,13 @@ public void basicHappyPathTest() throws Exception {

String seyrenUrl = URLEncoder.encode(seyrenConfig.getBaseUrl(), "UTF-8");
clientDriver.addExpectation(
onRequestTo("/v1/rooms/message")
onRequestTo("/v2/room/target/notification")
.withMethod(Method.POST)
.withBody(is("auth_token="
+ "&from=Seyren+Alert"
+ "&room_id=target"
+ "&message=Check+%3Ca+href%3D" + seyrenUrl + "%2F%23%2Fchecks%2Fnull%3Etest-check%3C%2Fa%3E+has+entered+its+ERROR+state."
.withParam("auth_token",seyrenConfig.getHipChatAuthToken())
.withBody(is("message=Check+%3Ca+href%3D" + seyrenUrl + "%2F%23%2Fchecks%2Fnull%3Etest-check%3C%2Fa%3E+has+entered+its+ERROR+state."
+ "&color=red"
+ "&notify=1"), "application/x-www-form-urlencoded"),
+ "&message_format=html"
+ "&notify=true"), "application/x-www-form-urlencoded"),
giveEmptyResponse());

notificationService.sendNotification(check, subscription, alerts);
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.