Class PushServerClient

java.lang.Object
io.getlime.push.client.PushServerClient

public class PushServerClient
extends Object
Simple class for interacting with the push server RESTful API.
Author:
Petr Dvorak, petr@wultra.com, Martin Tupy, martin.tupy.work@gmail.com
  • Constructor Details

    • PushServerClient

      public PushServerClient​(String serviceBaseUrl) throws PushServerClientException
      Main constructor with the push server base URL.
      Parameters:
      serviceBaseUrl - Push server instance base URL.
      Throws:
      PushServerClientException - Thrown in case REST client initialization fails.
  • Method Details

    • getServiceStatus

      public io.getlime.core.rest.model.base.response.ObjectResponse<ServiceStatusResponse> getServiceStatus() throws PushServerClientException
      Returns service information
      Returns:
      True if service is running.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • createDevice

      public boolean createDevice​(Long appId, String token, MobilePlatform platform) throws PushServerClientException
      Register anonymous device to the push server.
      Parameters:
      appId - PowerAuth application app ID.
      token - Token received from the push service provider (APNs, FCM).
      platform - Mobile platform (iOS, Android).
      Returns:
      True if device registration was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • createDevice

      public boolean createDevice​(Long appId, String token, MobilePlatform platform, String activationId) throws PushServerClientException
      Register device associated with activation ID to the push server.
      Parameters:
      appId - PowerAuth application app ID.
      token - Token received from the push service provider (APNs, FCM).
      platform - Mobile platform (iOS, Android).
      activationId - PowerAuth activation ID.
      Returns:
      True if device registration was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • createDeviceForActivations

      public boolean createDeviceForActivations​(Long appId, String token, MobilePlatform platform, List<String> activationIds) throws PushServerClientException
      Register device associated with multiple activation IDs to the push server.
      Parameters:
      appId - PowerAuth application app ID.
      token - Token received from the push service provider (APNs, FCM).
      platform - Mobile platform (iOS, Android).
      activationIds - PowerAuth activation IDs.
      Returns:
      True if device registration was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • deleteDevice

      public boolean deleteDevice​(Long appId, String token) throws PushServerClientException
      Remove device from the push server
      Parameters:
      appId - PowerAuth application app ID.
      token - Token received from the push service provider.
      Returns:
      True if device removal was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • updateDeviceStatus

      public boolean updateDeviceStatus​(String activationId) throws PushServerClientException
      Update activation status for given device registration.
      Parameters:
      activationId - Identifier of activation
      Returns:
      True if updating went successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • sendPushMessage

      public io.getlime.core.rest.model.base.response.ObjectResponse<PushMessageSendResult> sendPushMessage​(Long appId, PushMessage pushMessage) throws PushServerClientException
      Send a single push message to application with given ID.
      Parameters:
      appId - PowerAuth application app ID.
      pushMessage - Push message to be sent.
      Returns:
      SendMessageResponse in case everything went OK, ErrorResponse in case of an error.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • sendPushMessageBatch

      public io.getlime.core.rest.model.base.response.ObjectResponse<PushMessageSendResult> sendPushMessageBatch​(Long appId, List<PushMessage> batch) throws PushServerClientException
      Send a push message batch to application with given ID.
      Parameters:
      appId - PowerAuth application app ID.
      batch - Push message batch to be sent.
      Returns:
      SendMessageResponse in case everything went OK, ErrorResponse in case of an error.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • createCampaign

      public io.getlime.core.rest.model.base.response.ObjectResponse<CreateCampaignResponse> createCampaign​(Long appId, PushMessageBody message) throws PushServerClientException
      Create a campaign.
      Parameters:
      appId - Application ID.
      message - Message which attributes are defined in PushMessageBody.
      Returns:
      ID of new created campaign.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • deleteCampaign

      public boolean deleteCampaign​(Long campaignId) throws PushServerClientException
      Delete a campaign specified with campaignId.
      Parameters:
      campaignId - Campaign ID.
      Returns:
      True if campaign is removed, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • getListOfCampaigns

      public io.getlime.core.rest.model.base.response.ObjectResponse<ListOfCampaignsResponse> getListOfCampaigns​(boolean all) throws PushServerClientException
      Get list of campaigns, dependent on all param
      Parameters:
      all - true to get whole list, false to get campaigns that are only sent
      Returns:
      List of campaigns.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • getCampaign

      public io.getlime.core.rest.model.base.response.ObjectResponse<CampaignResponse> getCampaign​(Long campaignId) throws PushServerClientException
      Get a campaign specified with campaignID.
      Parameters:
      campaignId - ID of campaign to get.
      Returns:
      Details of campaign, defined in CampaignResponse
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • addUsersToCampaign

      public boolean addUsersToCampaign​(Long campaignId, List<String> users) throws PushServerClientException
      Add a list of users to a specific campaign
      Parameters:
      campaignId - Identifier of campaign.
      users - List of users to add.
      Returns:
      True if adding was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • getListOfUsersFromCampaign

      public PagedResponse<ListOfUsersFromCampaignResponse> getListOfUsersFromCampaign​(Long campaignId, int page, int size) throws PushServerClientException
      Get a list of users in paged format from specific campaign
      Parameters:
      campaignId - Identifier of campaign.
      page - Page number.
      size - Size of elements per page.
      Returns:
      Page of users specified with params.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • deleteUsersFromCampaign

      public boolean deleteUsersFromCampaign​(Long campaignId, List<String> users) throws PushServerClientException
      Delete a list of users from specific campaign.
      Parameters:
      campaignId - Identifier of campaign.
      users - List of users' Identifiers to delete.
      Returns:
      True if deletion was successful, false otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • sendTestCampaign

      public boolean sendTestCampaign​(Long campaignId, String userId) throws PushServerClientException
      Send a campaign on test user for trying its correctness.
      Parameters:
      campaignId - Identifier of campaign.
      userId - Identifier of test user.
      Returns:
      True if sent, else otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • sendCampaign

      public boolean sendCampaign​(Long campaignId) throws PushServerClientException
      Send a specific campaign to users carrying this campaignID in PushCampaignUser model, but only once per device identified by token.
      Parameters:
      campaignId - Identifier of campaign.
      Returns:
      True if sent, else otherwise.
      Throws:
      PushServerClientException - In case of network, response / JSON processing, or other IO error.
    • getApplicationList

      public io.getlime.core.rest.model.base.response.ObjectResponse<GetApplicationListResponse> getApplicationList() throws PushServerClientException
      Get list of application credentials entities.
      Returns:
      Application credentials entity list.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • getUnconfiguredApplicationList

      public io.getlime.core.rest.model.base.response.ObjectResponse<GetApplicationListResponse> getUnconfiguredApplicationList() throws PushServerClientException
      Get list of applications which are not yet configured in Push Server but exist in PowerAuth server.
      Returns:
      List of applications which are not configured.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • getApplicationDetail

      public io.getlime.core.rest.model.base.response.ObjectResponse<GetApplicationDetailResponse> getApplicationDetail​(Long id, boolean includeIos, boolean includeAndroid) throws PushServerClientException
      Get detail for an application credentials entity.
      Parameters:
      id - Application credentials entity ID.
      includeIos - Whether to include iOS details.
      includeAndroid - Whether to include Android details.
      Returns:
      Application credentials entity detail.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • createApplication

      public io.getlime.core.rest.model.base.response.ObjectResponse<CreateApplicationResponse> createApplication​(Long appId) throws PushServerClientException
      Create application credentials entity.
      Parameters:
      appId - PowerAuth application ID.
      Returns:
      Response with ID of created application credentials entity.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • updateIos

      public io.getlime.core.rest.model.base.response.Response updateIos​(Long id, String bundle, String keyId, String teamId, String environment, byte[] privateKey) throws PushServerClientException
      Update iOS details for an application credentials entity.
      Parameters:
      id - ID of application credentials entity.
      bundle - The iOS bundle record.
      keyId - The iOS key record.
      teamId - The iOS team ID record.
      environment - The APNs environment.
      privateKey - The iOS private key bytes.
      Returns:
      Response from server.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • removeIos

      public io.getlime.core.rest.model.base.response.Response removeIos​(Long id) throws PushServerClientException
      Remove iOS record from an application credentials entity.
      Parameters:
      id - Application credentials entity ID.
      Returns:
      Response from server.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • updateAndroid

      public io.getlime.core.rest.model.base.response.Response updateAndroid​(Long id, String projectId, byte[] privateKey) throws PushServerClientException
      Update Android details for an application credentials entity.
      Parameters:
      id - Application credentials entity ID.
      projectId - The Android project ID record.
      privateKey - The Android private key bytes.
      Returns:
      Response from server.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.
    • removeAndroid

      public io.getlime.core.rest.model.base.response.Response removeAndroid​(Long id) throws PushServerClientException
      Remove Android record from an application credentials entity.
      Parameters:
      id - Application credentials entity ID.
      Returns:
      Response from server.
      Throws:
      PushServerClientException - Thrown when communication with Push Server fails.