Interface TerraClientV2


  • public interface TerraClientV2
    Interface for facilities to make requests to the Terra API.
    • Method Detail

      • userFromId

        PartialUser userFromId​(String userId)
        Create a new temporary PartialUser object, without making an API call, that can be passed in to the user parameter of the data request methods of this class.
        This allows you to fetch data without having to make an extra unnecessary API request to the /userInfo endpoint.
        Parameters:
        userId - the ID of the user to be created
        Returns:
        the created PartialUser object
        Throws:
        NullPointerException - if the userId passed is null
      • getAllUsers

        Future<? extends TerraApiResponse<? extends User>> getAllUsers()
        Makes a request to the /subscriptions endpoint to fetch all users registered with your developer ID.
        Returns:
        future that will contain the API response upon completion
      • getUser

        Future<? extends TerraApiResponse<? extends User>> getUser​(String userId)
        Makes a request to the /userInfo endpoint to fetch the details for the user with the given ID. This User object can then subsequently be used to fetch data through the other available methods.
        Note that the fetched user will both be available through TerraApiResponse.getUser(), and will also be the single item in the TerraApiResponse.getParsedData() list.
        Parameters:
        userId - ID of the user to get information for
        Returns:
        future that will contain the fetched User object upon completion
      • generateAuthenticationURL

        Future<TerraApiResponse<AuthenticationResponse>> generateAuthenticationURL​(String resource)
        Asynchronously makes a request to the /auth/authenticateUser endpoint to authenticate a user for the specified resource
        If successful, the response will have a 200 status code with the authentication URL. Note that no data will be returned with the API response.
        Parameters:
        resource - the resource to authenticate a user for
        Returns:
        future that will contain the API response upon completion
      • generateAuthenticationURL

        Future<TerraApiResponse<AuthenticationResponse>> generateAuthenticationURL​(String resource,
                                                                                   String reference_id)
        Asynchronously makes a request to the /auth/authenticateUser endpoint to authenticate a user for the specified resource
        If successful, the response will have a 200 status code with the authentication URL. Note that no data will be returned with the API response.
        Parameters:
        resource - the resource to authenticate a user for
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        Returns:
        future that will contain the API response upon completion
      • generateAuthenticationURL

        Future<TerraApiResponse<AuthenticationResponse>> generateAuthenticationURL​(String resource,
                                                                                   String reference_id,
                                                                                   String auth_success_redirect_url)
        Asynchronously makes a request to the /auth/authenticateUser endpoint to authenticate a user for the specified resource
        If successful, the response will have a 200 status code with the authentication URL. Note that no data will be returned with the API response.
        Parameters:
        resource - the resource to authenticate a user for
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        Returns:
        future that will contain the API response upon completion
      • generateAuthenticationURL

        Future<TerraApiResponse<AuthenticationResponse>> generateAuthenticationURL​(String resource,
                                                                                   String reference_id,
                                                                                   String auth_success_redirect_url,
                                                                                   String auth_failure_redirect_url)
        Asynchronously makes a request to the /auth/authenticateUser endpoint to authenticate a user for the specified resource
        If successful, the response will have a 200 status code with the authentication URL. Note that no data will be returned with the API response.
        Parameters:
        resource - the resource to authenticate a user for
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        auth_failure_redirect_url - is the URL for user redirection upon unsuccessful auth (supports deeplinks)
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers,
                                                                               String reference_id)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers,
                                                                               String reference_id,
                                                                               String auth_success_redirect_url)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers,
                                                                               String reference_id,
                                                                               String auth_success_redirect_url,
                                                                               String auth_failure_redirect_url)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        auth_failure_redirect_url - is the URL for user redirection upon unsuccessful auth (supports deeplinks)
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers,
                                                                               String reference_id,
                                                                               String auth_success_redirect_url,
                                                                               String auth_failure_redirect_url,
                                                                               String language)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        auth_failure_redirect_url - is the URL for user redirection upon unsuccessful auth (supports deeplinks)
        language - is the language you would like the widget to be displayed in
        Returns:
        future that will contain the API response upon completion
      • generateWidgetSession

        Future<TerraApiResponse<GenerateWidgetResponse>> generateWidgetSession​(String providers,
                                                                               String reference_id,
                                                                               String auth_success_redirect_url,
                                                                               String auth_failure_redirect_url,
                                                                               String language,
                                                                               boolean show_disconnect)
        Asynchronously makes a request to the /auth/generateWidgetSession endpoint to generate a widget session for user authentication
        If successful, the response will have a 200 status code with the widget session link.
        Parameters:
        providers - the resources on widget for a user connect to
        reference_id - the identifier to associate with the user being authenticated. This can be used to reconcile the user with your internal systems.
        auth_success_redirect_url - is the URL for user redirection upon successful auth (supports deeplinks)
        auth_failure_redirect_url - is the URL for user redirection upon unsuccessful auth (supports deeplinks)
        language - is the language you would like the widget to be displayed in
        show_disconnect - is whether to show the disconnect button once the user is connected
        Returns:
        future that will contain the API response upon completion
      • deauthenticateUser

        Future<TerraApiResponse<Void>> deauthenticateUser​(PartialUser user)
        Asynchronously makes a request to the /auth/deauthenticateUser endpoint to deauthenticate the given user with Terra, terminating the connection.
        If successful, the response will have a 200 status code. Note that no data will be returned with the API response.
        Parameters:
        user - the user to deauthenticate
        Returns:
        future that will contain the API response upon completion
      • getAthleteForUser

        Future<TerraApiResponse<Athlete>> getAthleteForUser​(PartialUser user)
        Asynchronously makes a request to the /athlete endpoint to fetch the athlete data for the given user.
        Note that if athlete data is available for the given user, it will be available as the single item in the list returned by TerraApiResponse.getParsedData().
        Parameters:
        user - the user to fetch the athlete data for
        Returns:
        future that will contain the API response upon completion
      • getAthleteForUser

        Future<TerraApiResponse<Athlete>> getAthleteForUser​(PartialUser user,
                                                            RequestConfig requestConfig)
        Asynchronously makes a request to the /athlete endpoint to fetch the athlete data for the given user. Note that only the toWebhook configuration property of RequestConfig will be considered in this case.
        Note that if athlete data is available for the given user, it will be available as the single item in the list returned by TerraApiResponse.getParsedData().
        Parameters:
        user - the user to fetch the athlete data for
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getActivityForUser

        Future<TerraApiResponse<Activity>> getActivityForUser​(PartialUser user,
                                                              Instant startTime,
                                                              @Nullable
                                                              @Nullable Instant endTime)
        Asynchronously makes a request to the /activity endpoint to fetch the activity data for the given user.
        Parameters:
        user - the user to fetch the activity data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getActivityForUser

        Future<TerraApiResponse<Activity>> getActivityForUser​(PartialUser user,
                                                              Instant startTime,
                                                              @Nullable
                                                              @Nullable Instant endTime,
                                                              RequestConfig requestConfig)
        Asynchronously makes a request to the /activity endpoint to fetch the activity data for the given user.
        Parameters:
        user - the user to fetch the activity data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getBodyForUser

        Future<TerraApiResponse<Body>> getBodyForUser​(PartialUser user,
                                                      Instant startTime,
                                                      @Nullable
                                                      @Nullable Instant endTime)
        Asynchronously makes a request to the /body endpoint to fetch the body data for the given user.
        Parameters:
        user - the user to fetch the body data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getBodyForUser

        Future<TerraApiResponse<Body>> getBodyForUser​(PartialUser user,
                                                      Instant startTime,
                                                      @Nullable
                                                      @Nullable Instant endTime,
                                                      RequestConfig requestConfig)
        Asynchronously makes a request to the /body endpoint to fetch the body data for the given user.
        Parameters:
        user - the user to fetch the body data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getDailyForUser

        Future<TerraApiResponse<Daily>> getDailyForUser​(PartialUser user,
                                                        Instant startTime,
                                                        @Nullable
                                                        @Nullable Instant endTime)
        Asynchronously makes a request to the /daily endpoint to fetch the daily data for the given user.
        Parameters:
        user - the user to fetch the daily data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getDailyForUser

        Future<TerraApiResponse<Daily>> getDailyForUser​(PartialUser user,
                                                        Instant startTime,
                                                        @Nullable
                                                        @Nullable Instant endTime,
                                                        RequestConfig requestConfig)
        Asynchronously makes a request to the /daily endpoint to fetch the daily data for the given user.
        Parameters:
        user - the user to fetch the daily data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getMenstruationForUser

        Future<TerraApiResponse<Menstruation>> getMenstruationForUser​(PartialUser user,
                                                                      Instant startTime,
                                                                      @Nullable
                                                                      @Nullable Instant endTime)
        Asynchronously makes a request to the /menstruation endpoint to fetch the menstruation data for the given user.
        Parameters:
        user - the user to fetch the menstruation data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getMenstruationForUser

        Future<TerraApiResponse<Menstruation>> getMenstruationForUser​(PartialUser user,
                                                                      Instant startTime,
                                                                      @Nullable
                                                                      @Nullable Instant endTime,
                                                                      RequestConfig requestConfig)
        Asynchronously makes a request to the /menstruation endpoint to fetch the menstruation data for the given user.
        Parameters:
        user - the user to fetch the menstruation data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getNutritionForUser

        Future<TerraApiResponse<Nutrition>> getNutritionForUser​(PartialUser user,
                                                                Instant startTime,
                                                                @Nullable
                                                                @Nullable Instant endTime)
        Asynchronously makes a request to the /nutrition endpoint to fetch the nutrition data for the given user.
        Parameters:
        user - the user to fetch the nutrition data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getNutritionForUser

        Future<TerraApiResponse<Nutrition>> getNutritionForUser​(PartialUser user,
                                                                Instant startTime,
                                                                @Nullable
                                                                @Nullable Instant endTime,
                                                                RequestConfig requestConfig)
        Asynchronously makes a request to the /nutrition endpoint to fetch the nutrition data for the given user.
        Parameters:
        user - the user to fetch the nutrition data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion
      • getSleepForUser

        Future<TerraApiResponse<Sleep>> getSleepForUser​(PartialUser user,
                                                        Instant startTime,
                                                        @Nullable
                                                        @Nullable Instant endTime)
        Asynchronously makes a request to the /sleep endpoint to fetch the sleep data for the given user.
        Parameters:
        user - the user to fetch the sleep data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        Returns:
        future that will contain the API response upon completion
      • getSleepForUser

        Future<TerraApiResponse<Sleep>> getSleepForUser​(PartialUser user,
                                                        Instant startTime,
                                                        @Nullable
                                                        @Nullable Instant endTime,
                                                        RequestConfig requestConfig)
        Asynchronously makes a request to the /sleep endpoint to fetch the sleep data for the given user.
        Parameters:
        user - the user to fetch the sleep data for
        startTime - the start time to fetch data since
        endTime - then end time to fetch data before
        requestConfig - the config to use for this request
        Returns:
        future that will contain the API response upon completion