pianod2
multisource multiuser scriptable networked music player
Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
Pandora::Communication Class Reference

Pandora communication class. More...

#include <pandoracomm.h>

Collaboration diagram for Pandora::Communication:
Collaboration graph
[legend]

Public Member Functions

 Communication (const std::string &name, const std::string &pass, const std::string &prox, const JSONProtocolParameters &proto_params)
 Construct a new communicator given the user's name and password, and an optional proxy server. More...
 
Status execute (Request &request, bool retry_if_auth_required=true)
 Execute an HTTP request. More...
 
Status partnerAuthenticate ()
 Authenticate with Pandora. More...
 
void resetState ()
 
Parsnip::Data persist () const
 Persist communication settings. More...
 
void restore (const Parsnip::Data &data)
 Restore communication settings. More...
 
time_t retryTime () const
 
const UserFeaturesgetFeatures () const
 
const time_t offlineUntil () const
 
const time_t sessionExpires () const
 
const bool isFailed () const
 

Private Types

enum class  State { Uninitialized , Initialized , Authenticated , Failed }
 

Private Member Functions

Status performRequest (Request &request)
 Perform an API request. More...
 
Status authenticate ()
 Authenticate with Pandora. More...
 

Private Attributes

JSONProtocolParameters protocol
 
const bool automatic_protocol_parameters {false}
 
std::string username
 
std::string password
 
std::string proxy
 
std::string partner_auth_token
 Partner authorization token, for JSON protocol. More...
 
std::string partner_id
 
std::string user_auth_token
 Authorization token, retrieved during login. More...
 
std::string listener_id
 
time_t synctime_offset
 
int sequential_failures {0}
 Number of failed transactions without successes. More...
 
time_t lockout_until {0}
 Time until which communications are blocked/automatically fail. More...
 
time_t session_expiration {0}
 Time at which session expires from inactivity. More...
 
UserFeatures features
 User capabilities, retrieved from login response. More...
 
State state {State::Uninitialized}
 
HttpClient http_client
 
BlowFish encryptor
 
BlowFish decryptor
 

Detailed Description

Pandora communication class.

Provided a request, assembles a JSON request and issues it to Pandora, then decodes the response. This class manages the CSRF (cross-site request forgery) and authorization tokens, and reauthenticates if/when necessary.

Member Enumeration Documentation

◆ State

enum Pandora::Communication::State
strongprivate
Enumerator
Uninitialized 
Initialized 

Partner login not yet performed.

Authenticated 

Partner login complete, user not yet authenticated.

Failed 

Ready to go...

Bad credentials, refuse to work anymore.

Constructor & Destructor Documentation

◆ Communication()

Pandora::Communication::Communication ( const std::string &  name,
const std::string &  pass,
const std::string &  prox,
const JSONProtocolParameters proto_params 
)

Construct a new communicator given the user's name and password, and an optional proxy server.

Member Function Documentation

◆ authenticate()

Status Pandora::Communication::authenticate ( )
private

Authenticate with Pandora.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ execute()

Status Pandora::Communication::execute ( Request request,
bool  retry_if_auth_required = true 
)

Execute an HTTP request.

Acquire CSRF token and authenticate if necessary.

  • If an error indicates authentication has expired, log in again and retry request.
  • For other errors, back off for a period to prevent overloading Pandora servers.
    Parameters
    requestThe request to perform.
Parameters
retry_if_auth_requiredInternal use (for managing recursion).
Returns
Status::Ok, or an error.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getFeatures()

const UserFeatures& Pandora::Communication::getFeatures ( ) const
inline
Here is the caller graph for this function:

◆ isFailed()

const bool Pandora::Communication::isFailed ( ) const
inline
Here is the caller graph for this function:

◆ offlineUntil()

const time_t Pandora::Communication::offlineUntil ( ) const
inline
Here is the caller graph for this function:

◆ partnerAuthenticate()

Status Pandora::Communication::partnerAuthenticate ( )

Authenticate with Pandora.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ performRequest()

Status Pandora::Communication::performRequest ( Request request)
private

Perform an API request.

Parameters
requestThe request to perform.
Returns
Status::Ok or an error value.
Exceptions
Exceptionsthrown by message decoders.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ persist()

Parsnip::Data Pandora::Communication::persist ( void  ) const

Persist communication settings.

Returns
A dictionary with any settings the communicator wants saved.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ resetState()

void Pandora::Communication::resetState ( )
Here is the caller graph for this function:

◆ restore()

void Pandora::Communication::restore ( const Parsnip::Data data)

Restore communication settings.

Parameters
dataA dictionary of previous settings from which to restore.
Here is the call graph for this function:
Here is the caller graph for this function:

◆ retryTime()

time_t Pandora::Communication::retryTime ( ) const
inline
Here is the caller graph for this function:

◆ sessionExpires()

const time_t Pandora::Communication::sessionExpires ( ) const
inline

Member Data Documentation

◆ automatic_protocol_parameters

const bool Pandora::Communication::automatic_protocol_parameters {false}
private

◆ decryptor

BlowFish Pandora::Communication::decryptor
private

◆ encryptor

BlowFish Pandora::Communication::encryptor
private

◆ features

UserFeatures Pandora::Communication::features
private

User capabilities, retrieved from login response.

◆ http_client

HttpClient Pandora::Communication::http_client
private

◆ listener_id

std::string Pandora::Communication::listener_id
private

◆ lockout_until

time_t Pandora::Communication::lockout_until {0}
private

Time until which communications are blocked/automatically fail.

◆ partner_auth_token

std::string Pandora::Communication::partner_auth_token
private

Partner authorization token, for JSON protocol.

◆ partner_id

std::string Pandora::Communication::partner_id
private

◆ password

std::string Pandora::Communication::password
private

◆ protocol

JSONProtocolParameters Pandora::Communication::protocol
private

◆ proxy

std::string Pandora::Communication::proxy
private

◆ sequential_failures

int Pandora::Communication::sequential_failures {0}
private

Number of failed transactions without successes.

◆ session_expiration

time_t Pandora::Communication::session_expiration {0}
private

Time at which session expires from inactivity.

◆ state

State Pandora::Communication::state {State::Uninitialized}
private

◆ synctime_offset

time_t Pandora::Communication::synctime_offset
private

◆ user_auth_token

std::string Pandora::Communication::user_auth_token
private

Authorization token, retrieved during login.

◆ username

std::string Pandora::Communication::username
private

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