Skip to content

Commit

Permalink
Merge pull request #7 from simongsr/master
Browse files Browse the repository at this point in the history
Added support for the 'search' endpoint
  • Loading branch information
skoka-anx authored Jan 29, 2018
2 parents 575aa05 + 3256547 commit de515ae
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/main/java/com/appnexus/grafana/client/GrafanaClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.appnexus.grafana.client.models.DashboardSuccessfulDelete;
import com.appnexus.grafana.client.models.GrafanaDashboard;
import com.appnexus.grafana.client.models.GrafanaMessage;
import com.appnexus.grafana.client.models.GrafanaSearchResult;
import com.appnexus.grafana.configuration.GrafanaConfiguration;
import com.appnexus.grafana.exceptions.GrafanaDashboardCouldNotDeleteException;
import com.appnexus.grafana.exceptions.GrafanaDashboardDoesNotExistException;
Expand Down Expand Up @@ -274,4 +275,18 @@ public DashboardPanelAlert getAlert(Integer id) throws GrafanaException, IOExcep
throw GrafanaException.withErrorBody(response.errorBody());
}
}

public List<GrafanaSearchResult> search(
String query, String tag, Boolean starred, Boolean tagcloud)
throws GrafanaException, IOException {

Response<List<GrafanaSearchResult>> response =
service.search(apiKey, query, tag, starred, tagcloud).execute();

if (response.isSuccessful()) {
return response.body();
} else {
throw GrafanaException.withErrorBody(response.errorBody());
}
}
}
12 changes: 12 additions & 0 deletions src/main/java/com/appnexus/grafana/client/GrafanaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.appnexus.grafana.client.models.DashboardSuccessfulDelete;
import com.appnexus.grafana.client.models.GrafanaDashboard;
import com.appnexus.grafana.client.models.GrafanaMessage;
import com.appnexus.grafana.client.models.GrafanaSearchResult;
import java.util.List;
import retrofit2.Call;
import retrofit2.http.Body;
Expand All @@ -16,11 +17,13 @@
import retrofit2.http.POST;
import retrofit2.http.PUT;
import retrofit2.http.Path;
import retrofit2.http.Query;

public interface GrafanaService {
String GRAFANA_DASHBOARDS = "api/dashboards/db/";
String GRAFANA_NOTIFICATIONS = "api/alert-notifications/";
String GRAFANA_ALERTS = "api/alerts/";
String GRAFANA_SEARCH = "api/search/";

String AUTHORIZATION = "Authorization";

Expand Down Expand Up @@ -63,4 +66,13 @@ Call<GrafanaMessage> deleteNotification(
@GET(GRAFANA_ALERTS + "{id}")
Call<DashboardPanelAlert> getAlert(
@Header(AUTHORIZATION) String authorization, @Path("id") Integer id);

// Search
@GET(GRAFANA_SEARCH)
Call<List<GrafanaSearchResult>> search(
@Header(AUTHORIZATION) String authorization,
@Query("query") String query,
@Query("tag") String tag,
@Query("starred") Boolean starred,
@Query("tagcloud") Boolean tagcloud);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/* Licensed under Apache-2.0 */
package com.appnexus.grafana.client.models;

import java.util.List;
import lombok.Data;
import lombok.experimental.Accessors;

@Data
@Accessors(fluent = true)
public class GrafanaSearchResult {
Long id;
String title;
String uri;
String type;
List<String> tags;
Boolean isStarred;
}

0 comments on commit de515ae

Please sign in to comment.