AlexaClientSDK  3.0.0
A cross-platform, modular SDK for interacting with the Alexa Voice Service
Classes | Public Types | Public Member Functions | Static Public Member Functions | List of all members
alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface Class Referenceabstract

#include <HTTPContentFetcherInterface.h>

Inheritance diagram for alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface:
Inheritance graph
[legend]

Classes

struct  Header
 

Public Types

enum  FetchOptions { FetchOptions::CONTENT_TYPE, FetchOptions::ENTIRE_BODY }
 Represents what HTTP content to fetch. More...
 
enum  State {
  State::INITIALIZED, State::FETCHING_HEADER, State::HEADER_DONE, State::FETCHING_BODY,
  State::BODY_DONE, State::ERROR
}
 The state of payload fetching. More...
 

Public Member Functions

virtual ~HTTPContentFetcherInterface ()=default
 
virtual State getState ()=0
 
virtual std::string getUrl () const =0
 
virtual std::string getEffectiveUrl () const =0
 
virtual Header getHeader (std::atomic< bool > *shouldShutdown)=0
 
virtual bool getBody (std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter > writer)=0
 
virtual void shutdown ()=0
 
virtual std::unique_ptr< avsCommon::utils::HTTPContentgetContent (FetchOptions option, std::unique_ptr< avsCommon::avs::attachment::AttachmentWriter > writer=nullptr, const std::vector< std::string > &customHeaders=std::vector< std::string >())=0
 

Static Public Member Functions

static std::string getUserAgent ()
 
static std::string stateToString (State state)
 

Detailed Description

This class allows users to fetch content from remote location using HTTP(S).

Member Enumeration Documentation

◆ FetchOptions

Represents what HTTP content to fetch.

Enumerator
CONTENT_TYPE 

Retrieves the content type part of the HTTP header.

ENTIRE_BODY 

Retrieves the entire body of the remote location.

◆ State

The state of payload fetching.

Enumerator
INITIALIZED 

Initialized but nothing was downloaded yet.

FETCHING_HEADER 

Currently fetching the header.

HEADER_DONE 

Done fetching the header. Ready to start fetching the body.

FETCHING_BODY 

Currently fetching the body.

BODY_DONE 

Done fetching the body. At this point the content fetcher can only be used to read the headers.

ERROR 

Some error happened at any stage and the content fetcher cannot be used anymore.

Constructor & Destructor Documentation

◆ ~HTTPContentFetcherInterface()

virtual alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::~HTTPContentFetcherInterface ( )
virtualdefault

Destructor.

Member Function Documentation

◆ getBody()

virtual bool alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getBody ( std::shared_ptr< avsCommon::avs::attachment::AttachmentWriter writer)
pure virtual

Retrieves the body after the header was received. This method is asynchronous and the caller can monitor the download progress using the getState method.

Parameters
writerThe writer to write the payload.
Returns
true if the call is successful.

◆ getContent()

virtual std::unique_ptr<avsCommon::utils::HTTPContent> alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getContent ( FetchOptions  option,
std::unique_ptr< avsCommon::avs::attachment::AttachmentWriter writer = nullptr,
const std::vector< std::string > &  customHeaders = std::vector< std::string >() 
)
pure virtual

This function retrieves content from a remote location. No thread safety is guaranteed.

Parameters
optionFlag indicating desired content.
writerAn optional writer parameter to be used when writing to an external stream.
customHeadersAn optional list of headers to be attached to the request.
Returns
A new HTTPContent object or nullptr if a failure occurred.

◆ getEffectiveUrl()

virtual std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getEffectiveUrl ( ) const
pure virtual

Gets the effective URL associated with this content fetcher.

Note
This is useful in the case of redirects where the first URL used redirects to a different URL to fetch the content.
Returns
The content fetcher's effective URL.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getHeader()

virtual Header alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getHeader ( std::atomic< bool > *  shouldShutdown)
pure virtual

Waits until the header was fetched successfully. If any problem happened during header, returns false. After the header was already fetched, this method can be called multiple times and will return immediately.

Parameters
shouldShutdownA pointer to allow for the caller to asynchronously cancel the wait, if needed. this argument is optional. If it is a null pointer, the function will ignore it.
Returns
The header struct. It is the caller's responsibility to check the struct to see if the header was retrieved successfully.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getState()

virtual State alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getState ( )
pure virtual

The current content fetching state. In particular, a caller of getBody, an asynchronous function, can use this method to monitor the download progress.

Returns
The current content fetching state.

Implemented in alexaClientSDK::playlistParser::test::MockContentFetcher, alexaClientSDK::mediaPlayer::test::MockContentFetcher, and alexaClientSDK::avsCommon::utils::libcurlUtils::LibCurlHttpContentFetcher.

◆ getUrl()

virtual std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getUrl ( ) const
pure virtual

◆ getUserAgent()

std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::getUserAgent ( )
inlinestatic

Returns a string that represents the User-Agent to be used in HTTP requests.

Returns
User-Agent string to be used in HTTP requests.

◆ shutdown()

virtual void alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::shutdown ( )
pure virtual

◆ stateToString()

std::string alexaClientSDK::avsCommon::sdkInterfaces::HTTPContentFetcherInterface::stateToString ( HTTPContentFetcherInterface::State  state)
inlinestatic

Produces the string representation of the state enum values.

Parameters
stateThe state enum value.
Returns
Its string representation.

The documentation for this class was generated from the following file:

AlexaClientSDK 3.0.0 - Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. Licensed under the Apache License, Version 2.0