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

io.github.jfermat.strava.api.SegmentsApi Maven / Gradle / Ivy

package io.github.jfermat.strava.api;

import io.github.jfermat.strava.invoker.ApiClient;

import io.github.jfermat.strava.model.DetailedSegment;
import io.github.jfermat.strava.model.ExplorerResponse;
import io.github.jfermat.strava.model.Fault;
import io.github.jfermat.strava.model.SummarySegment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.HttpClientErrorException;
import org.springframework.web.util.UriComponentsBuilder;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.core.io.FileSystemResource;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;

@Component("io.github.jfermat.strava.api.SegmentsApi")
public class SegmentsApi {
    private ApiClient apiClient;

    public SegmentsApi() {
        this(new ApiClient());
    }

    @Autowired
    public SegmentsApi(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    public ApiClient getApiClient() {
        return apiClient;
    }

    public void setApiClient(ApiClient apiClient) {
        this.apiClient = apiClient;
    }

    /**
     * Explore segments
     * Returns the top 10 segments matching a specified query.
     * 

200 - List of matching segments. *

0 - Unexpected error. * @param bounds The latitude and longitude for two points describing a rectangular boundary for the search: [southwest corner latitutde, southwest corner longitude, northeast corner latitude, northeast corner longitude] * @param activityType Desired activity type. * @param minCat The minimum climbing category. * @param maxCat The maximum climbing category. * @return ExplorerResponse * @throws RestClientException if an error occurs while attempting to invoke the API */ public ExplorerResponse exploreSegments(List bounds, String activityType, Integer minCat, Integer maxCat) throws RestClientException { Object postBody = null; // verify the required parameter 'bounds' is set if (bounds == null) { throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'bounds' when calling exploreSegments"); } String path = UriComponentsBuilder.fromPath("/segments/explore").build().toUriString(); final MultiValueMap queryParams = new LinkedMultiValueMap(); final HttpHeaders headerParams = new HttpHeaders(); final MultiValueMap formParams = new LinkedMultiValueMap(); queryParams.putAll(apiClient.parameterToMultiValueMap(ApiClient.CollectionFormat.valueOf("csv".toUpperCase()), "bounds", bounds)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "activity_type", activityType)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "min_cat", minCat)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "max_cat", maxCat)); final String[] accepts = { "application/json" }; final List accept = apiClient.selectHeaderAccept(accepts); final String[] contentTypes = { }; final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "strava_oauth" }; ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); } /** * List Starred Segments * List of the authenticated athlete's starred segments. Private segments are filtered out unless requested by a token with read_all scope. *

200 - List of the authenticated athlete's starred segments. *

0 - Unexpected error. * @param page Page number. Defaults to 1. * @param perPage Number of items per page. Defaults to 30. * @return List<SummarySegment> * @throws RestClientException if an error occurs while attempting to invoke the API */ public List getLoggedInAthleteStarredSegments(Integer page, Integer perPage) throws RestClientException { Object postBody = null; String path = UriComponentsBuilder.fromPath("/segments/starred").build().toUriString(); final MultiValueMap queryParams = new LinkedMultiValueMap(); final HttpHeaders headerParams = new HttpHeaders(); final MultiValueMap formParams = new LinkedMultiValueMap(); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "page", page)); queryParams.putAll(apiClient.parameterToMultiValueMap(null, "per_page", perPage)); final String[] accepts = { "application/json" }; final List accept = apiClient.selectHeaderAccept(accepts); final String[] contentTypes = { }; final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "strava_oauth" }; ParameterizedTypeReference> returnType = new ParameterizedTypeReference>() {}; return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); } /** * Get Segment * Returns the specified segment. read_all scope required in order to retrieve athlete-specific segment information, or to retrieve private segments. *

200 - Representation of a segment. *

0 - Unexpected error. * @param id The identifier of the segment. * @return DetailedSegment * @throws RestClientException if an error occurs while attempting to invoke the API */ public DetailedSegment getSegmentById(Long id) throws RestClientException { Object postBody = null; // verify the required parameter 'id' is set if (id == null) { throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling getSegmentById"); } // create path and map variables final Map uriVariables = new HashMap(); uriVariables.put("id", id); String path = UriComponentsBuilder.fromPath("/segments/{id}").buildAndExpand(uriVariables).toUriString(); final MultiValueMap queryParams = new LinkedMultiValueMap(); final HttpHeaders headerParams = new HttpHeaders(); final MultiValueMap formParams = new LinkedMultiValueMap(); final String[] accepts = { "application/json" }; final List accept = apiClient.selectHeaderAccept(accepts); final String[] contentTypes = { }; final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "strava_oauth" }; ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; return apiClient.invokeAPI(path, HttpMethod.GET, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); } /** * Star Segment * Stars/Unstars the given segment for the authenticated athlete. Requires profile:write scope. *

200 - Representation of a segment. *

0 - Unexpected error. * @param starred The starred parameter * @param id The identifier of the segment to star. * @return DetailedSegment * @throws RestClientException if an error occurs while attempting to invoke the API */ public DetailedSegment starSegment(Boolean starred, Long id) throws RestClientException { Object postBody = null; // verify the required parameter 'starred' is set if (starred == null) { throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'starred' when calling starSegment"); } // verify the required parameter 'id' is set if (id == null) { throw new HttpClientErrorException(HttpStatus.BAD_REQUEST, "Missing the required parameter 'id' when calling starSegment"); } // create path and map variables final Map uriVariables = new HashMap(); uriVariables.put("id", id); String path = UriComponentsBuilder.fromPath("/segments/{id}/starred").buildAndExpand(uriVariables).toUriString(); final MultiValueMap queryParams = new LinkedMultiValueMap(); final HttpHeaders headerParams = new HttpHeaders(); final MultiValueMap formParams = new LinkedMultiValueMap(); if (starred != null) formParams.add("starred", starred); final String[] accepts = { "application/json" }; final List accept = apiClient.selectHeaderAccept(accepts); final String[] contentTypes = { "multipart/form-data" }; final MediaType contentType = apiClient.selectHeaderContentType(contentTypes); String[] authNames = new String[] { "strava_oauth" }; ParameterizedTypeReference returnType = new ParameterizedTypeReference() {}; return apiClient.invokeAPI(path, HttpMethod.PUT, queryParams, postBody, headerParams, formParams, accept, contentType, authNames, returnType); } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy