001/* 002 * Copyright (c) 2011-2019 Nexmo Inc 003 * 004 * Permission is hereby granted, free of charge, to any person obtaining a copy 005 * of this software and associated documentation files (the "Software"), to deal 006 * in the Software without restriction, including without limitation the rights 007 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 008 * copies of the Software, and to permit persons to whom the Software is 009 * furnished to do so, subject to the following conditions: 010 * 011 * The above copyright notice and this permission notice shall be included in 012 * all copies or substantial portions of the Software. 013 * 014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 015 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 016 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 017 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 018 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 019 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 020 * THE SOFTWARE. 021 */ 022package com.nexmo.client.application; 023 024import com.nexmo.client.*; 025 026/** 027 * A client for talking to the Nexmo Application API. The standard way to obtain an instance of this class is to use 028 * {@link NexmoClient#getApplicationClient()} 029 */ 030public class ApplicationClient extends AbstractClient { 031 private ApplicationEndpoint applicationEndpoint; 032 033 public ApplicationClient(HttpWrapper httpWrapper) { 034 super(httpWrapper); 035 this.applicationEndpoint = new ApplicationEndpoint(httpWrapper); 036 } 037 038 /** 039 * Create a new application. 040 * 041 * @param application The application properties for the application to be created with. 042 * 043 * @return The application which has been created. 044 * 045 * @throws NexmoResponseParseException if the response from the API could not be parsed. 046 * @throws NexmoClientException if there was a problem with the Nexmo request. 047 */ 048 public Application createApplication(Application application) throws NexmoResponseParseException, NexmoClientException { 049 return this.applicationEndpoint.create(application); 050 } 051 052 /** 053 * Update an existing application. 054 * 055 * @param application The application properties for the application to be updated with. 056 * 057 * @return The application which has been updated. 058 * 059 * @throws NexmoResponseParseException if the response from the API could not be parsed. 060 * @throws NexmoClientException if there was a problem with the Nexmo request. 061 */ 062 public Application updateApplication(Application application) throws NexmoResponseParseException, NexmoClientException { 063 return this.applicationEndpoint.update(application); 064 } 065 066 /** 067 * Retrieve an application. 068 * 069 * @param id The id of the application to retrieve. 070 * 071 * @return The corresponding application. 072 * 073 * @throws NexmoResponseParseException if the response from the API could not be parsed. 074 * @throws NexmoClientException if there was a problem with the Nexmo request. 075 */ 076 public Application getApplication(String id) throws NexmoResponseParseException, NexmoClientException { 077 return this.applicationEndpoint.get(id); 078 } 079 080 /** 081 * Delete an application. 082 * 083 * @param id The id of the application to delete. 084 * 085 * @throws NexmoResponseParseException if the response from the API could not be parsed. 086 * @throws NexmoClientException if there was a problem with the Nexmo request. 087 */ 088 public void deleteApplication(String id) throws NexmoResponseParseException, NexmoClientException { 089 this.applicationEndpoint.delete(id); 090 } 091 092 /** 093 * List the first page of available applications. 094 * 095 * @return The list of available applications. 096 * 097 * @throws NexmoResponseParseException if the response from the API could not be parsed. 098 * @throws NexmoClientException if there was a problem with the Nexmo request. 099 */ 100 public ApplicationList listApplications() throws NexmoResponseParseException, NexmoClientException { 101 return listApplications(null); 102 } 103 104 /** 105 * List the available applications. 106 * 107 * @param listApplicationRequest The page and number of applications per page to list. 108 * 109 * @return The list of available applications. 110 * 111 * @throws NexmoResponseParseException if the response from the API could not be parsed. 112 * @throws NexmoClientException if there was a problem with the Nexmo request. 113 */ 114 public ApplicationList listApplications(ListApplicationRequest listApplicationRequest) throws NexmoResponseParseException, NexmoClientException { 115 return this.applicationEndpoint.list(listApplicationRequest); 116 } 117}