All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.synedge.oss.client.status.JerseyStatusClient.groovy Maven / Gradle / Ivy

Go to download

This client allows you to easily connect to the Synedge API with any language running on the JDK

The newest version!
package com.synedge.oss.client.status

import com.synedge.oss.client.StatusClient
import com.synedge.oss.client.SynedgeClient
import com.synedge.oss.client.authentication.AuthenticatedClient
import groovy.transform.CompileStatic
import groovy.transform.PackageScope

/**
 *
 * @author Paul van Assen
 *
 */
class JerseyStatusClient extends AuthenticatedClient implements StatusClient {
    @PackageScope
    JerseyStatusClient(String username, String password, String endpoint = SynedgeClient.DEFAULT_ENDPOINT) {
        super(username, password, endpoint)
    }

    @Override
    List getSystems() {
        def json = signAndGet(client.target(endpoint).path('status').path('systems').request())
        return json.collect { system ->
            new StatusSystem(name: system.name, code: system.code, region: system.region)
        }
    }

    @CompileStatic
    @Override
    List getCurrentIncidents() {
        def json = signAndGet(client.target(endpoint).path('status').path('current').request())
        return parseIncidents(json)
    }

    @CompileStatic
    @Override
    List getHistoricIncidents(String start, String end) {
        def json = signAndGet(client.target(endpoint).path('status').path('history').queryParam('start', start).queryParam('end', end).request())
        return parseIncidents(json)
    }

    private final List parseIncidents(def json) {
        json.collect {incident ->
            new Incident(actions: incident.actions.collect { action ->
                new IncidentAction(action: action.action, message: action.message, date: new Date(action.date as long))
            }, date: new Date(incident.date as long),
                    id: incident.incidentId,
                    title: incident.title,
                    status: incident.status,
                    systemsAffectedCodes: incident.systemsAffectedCodes as Set)
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy