001/*
002 * Copyright (c) 2011-2017 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.applications;
023
024import com.nexmo.client.HttpWrapper;
025import com.nexmo.client.NexmoClient;
026import com.nexmo.client.NexmoClientException;
027import com.nexmo.client.applications.endpoints.ApplicationsEndpoint;
028
029import java.io.IOException;
030
031/**
032 * A client for talking to the Nexmo Number Applications API.
033 * The standard way to obtain an instance of this class is to
034 * use
035 * {@link NexmoClient#getApplicationClient()}.
036 */
037public class ApplicationClient {
038    protected ApplicationsEndpoint applications;
039
040    /**
041     * Constructor.
042     *
043     * @param httpWrapper (required) shared HTTP wrapper object used for making REST calls.
044     */
045    public ApplicationClient(HttpWrapper httpWrapper) {
046        this.applications = new ApplicationsEndpoint(httpWrapper);
047    }
048
049    /**
050     * Create a new Application.
051     *
052     * @param request A CreateApplicationRequest describing the application to be created.
053     * @return An ApplicationDetails object describing the newly created application, including generated private and
054     * public keys.
055     */
056    public ApplicationDetails createApplication(CreateApplicationRequest request)
057            throws IOException, NexmoClientException {
058        return this.applications.post(request);
059    }
060
061    /**
062     * Update an existing application with the provided details.
063     *
064     * @param request An UpdateApplicationRequest describing the new application details.
065     * @return An ApplicationDetails object describing the newly modified application.
066     */
067    public ApplicationDetails updateApplication(UpdateApplicationRequest request)
068            throws IOException, NexmoClientException {
069        return this.applications.put(request);
070    }
071
072    /**
073     * List the applications associated with the authenticated account. By default returns the first page of
074     * application objects.
075     *
076     * @param request A ListApplicationsRequest object containing the required paging information.
077     * @return A ListApplicationsResponse, which is an Iterator of ApplicationDetails objects.
078     */
079    public ListApplicationsResponse listApplications(ListApplicationsRequest request)
080            throws IOException, NexmoClientException {
081        return this.applications.get(request);
082    }
083
084    /**
085     * Obtain the details of an existing application.
086     *
087     * @param applicationId The id of the application
088     * @return An ApplicationDetails object describing the requested application.
089     */
090    public ApplicationDetails getApplication(String applicationId)
091            throws IOException, NexmoClientException {
092        return this.applications.get(applicationId);
093    }
094
095    /**
096     * Delete an application.
097     *
098     * @param applicationId The ID of the application to be deleted.
099     */
100    public void deleteApplication(String applicationId)
101            throws IOException, NexmoClientException {
102        this.applications.delete(applicationId);
103    }
104}