001/*
002 * SonarQube
003 * Copyright (C) 2009-2016 SonarSource SA
004 * mailto:contact AT sonarsource DOT com
005 *
006 * This program is free software; you can redistribute it and/or
007 * modify it under the terms of the GNU Lesser General Public
008 * License as published by the Free Software Foundation; either
009 * version 3 of the License, or (at your option) any later version.
010 *
011 * This program is distributed in the hope that it will be useful,
012 * but WITHOUT ANY WARRANTY; without even the implied warranty of
013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014 * Lesser General Public License for more details.
015 *
016 * You should have received a copy of the GNU Lesser General Public License
017 * along with this program; if not, write to the Free Software Foundation,
018 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
019 */
020package org.sonarqube.ws.client.usertoken;
021
022import org.sonarqube.ws.WsUserTokens.GenerateWsResponse;
023import org.sonarqube.ws.WsUserTokens.SearchWsResponse;
024import org.sonarqube.ws.client.BaseService;
025import org.sonarqube.ws.client.GetRequest;
026import org.sonarqube.ws.client.PostRequest;
027import org.sonarqube.ws.client.WsConnector;
028
029import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_GENERATE;
030import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_REVOKE;
031import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.ACTION_SEARCH;
032import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.CONTROLLER;
033import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_LOGIN;
034import static org.sonarqube.ws.client.usertoken.UserTokensWsParameters.PARAM_NAME;
035
036public class UserTokensService extends BaseService {
037
038  public UserTokensService(WsConnector wsConnector) {
039    super(wsConnector, CONTROLLER);
040  }
041
042  public GenerateWsResponse generate(GenerateWsRequest request) {
043    return call(
044      new PostRequest(path(ACTION_GENERATE))
045        .setParam(PARAM_LOGIN, request.getLogin())
046        .setParam(PARAM_NAME, request.getName()),
047      GenerateWsResponse.parser());
048  }
049
050  public SearchWsResponse search(SearchWsRequest request) {
051    return call(
052      new GetRequest(path(ACTION_SEARCH)).setParam(PARAM_LOGIN, request.getLogin()),
053      SearchWsResponse.parser());
054  }
055
056  public void revoke(RevokeWsRequest request) {
057    call(
058      new PostRequest(path(ACTION_REVOKE))
059        .setParam(PARAM_LOGIN, request.getLogin())
060        .setParam(PARAM_NAME, request.getName()));
061  }
062
063}