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

org.aoju.bus.gitlab.LicenseTemplatesApi Maven / Gradle / Ivy

/*********************************************************************************
 *                                                                               *
 * The MIT License (MIT)                                                         *
 *                                                                               *
 * Copyright (c) 2015-2022 aoju.org Greg Messner and other contributors.         *
 *                                                                               *
 * Permission is hereby granted, free of charge, to any person obtaining a copy  *
 * of this software and associated documentation files (the "Software"), to deal *
 * in the Software without restriction, including without limitation the rights  *
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell     *
 * copies of the Software, and to permit persons to whom the Software is         *
 * furnished to do so, subject to the following conditions:                      *
 *                                                                               *
 * The above copyright notice and this permission notice shall be included in    *
 * all copies or substantial portions of the Software.                           *
 *                                                                               *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR    *
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,      *
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE   *
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER        *
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN     *
 * THE SOFTWARE.                                                                 *
 *                                                                               *
 ********************************************************************************/
package org.aoju.bus.gitlab;

import org.aoju.bus.gitlab.models.LicenseTemplate;

import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

/**
 * This class provides an entry point to all the GitLab API licenses calls.
 *
 * @see Licenses API
 */
public class LicenseTemplatesApi extends AbstractApi {

    public LicenseTemplatesApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    }

    /**
     * Get a List of all license templates.
     *
     * 
GitLab Endpoint: GET /templates/licenses
* * @return a List of LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public List getLicenseTemplates() throws GitLabApiException { return (getLicenseTemplates(false, getDefaultPerPage()).all()); } /** * Get a Stream of all license templates. * *
GitLab Endpoint: GET /templates/licenses
* * @return a Stream of LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public Stream getLicenseTemplatesStream() throws GitLabApiException { return (getLicenseTemplates(false, getDefaultPerPage()).stream()); } /** * Get a Pager of all license templates. * *
GitLab Endpoint: GET /templates/licenses
* * @param itemsPerPage the number of LicenseTemplate instances that will be fetched per page * @return a Pager of LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public Pager getLicenseTemplates(int itemsPerPage) throws GitLabApiException { return (getLicenseTemplates(false, itemsPerPage)); } /** * Get a List of popular license templates. * *
GitLab Endpoint: GET /templates/licenses?popular=true
* * @return a List of popular LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public List getPopularLicenseTemplates() throws GitLabApiException { return (getLicenseTemplates(true, getDefaultPerPage()).all()); } /** * Get a Stream of popular license templates. * *
GitLab Endpoint: GET /templates/licenses?popular=true
* * @return a Stream of popular LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public Stream getPopularLicenseTemplatesStream() throws GitLabApiException { return (getLicenseTemplates(true, getDefaultPerPage()).stream()); } /** * Get a Pager of license templates. * *
GitLab Endpoint: GET /templates/licenses
* * @param popular if true, returns only popular licenses. * @param itemsPerPage the number of LicenseTemplate instances that will be fetched per page * @return a Pager of LicenseTemplate instances * @throws GitLabApiException if any exception occurs */ public Pager getLicenseTemplates(Boolean popular, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm().withParam("popular", popular); return (new Pager(this, LicenseTemplate.class, itemsPerPage, formData.asMap(), "templates", "licenses")); } /** * Get a single license template. * *
GitLab Endpoint: GET /templates/licenses/:key
* * @param key The key of the license template * @return a LicenseTemplate instance * @throws GitLabApiException if any exception occurs */ public LicenseTemplate getLicenseTemplate(String key) throws GitLabApiException { Response response = get(Response.Status.OK, null, "licenses", key); return (response.readEntity(LicenseTemplate.class)); } /** * Get a single license template as the value of an Optional. * *
GitLab Endpoint: GET /templates/licenses/:key
* * @param key The key of the license template * @return a single license template as the value of an Optional. */ public Optional getOptionalLicenseTemplate(String key) { try { return (Optional.ofNullable(getLicenseTemplate(key))); } catch (GitLabApiException glae) { return (GitLabApi.createOptionalFromException(glae)); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy