mirror of
https://github.com/AskDavis/Casinotest.git
synced 2026-01-03 12:29:46 -08:00
Adverts widget supports population from web and from local files.
This commit is contained in:
@@ -5,6 +5,8 @@
|
||||
#include <QJsonValue>
|
||||
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
||||
CasinoCoinWebAPIParser::CasinoCoinWebAPIParser( QObject* a_pParent )
|
||||
: QObject(a_pParent)
|
||||
@@ -23,24 +25,37 @@ void CasinoCoinWebAPIParser::slotParseAnswer( const QByteArray& a_rJsonFile )
|
||||
QJsonObject jsonObjectResult = docAsObject.find( "Result" ).value().toObject();
|
||||
if ( jsonObjectResult.find( "ActivePromotions" ).value().isArray() )
|
||||
{
|
||||
StoreFile( "ActivePromotions", a_rJsonFile );
|
||||
ParsePromotions( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveNewsItems" ).value().isArray() )
|
||||
{
|
||||
StoreFile( "ActiveNewsItems", a_rJsonFile );
|
||||
ParseNewsItems( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveCasinos" ).value().isArray() )
|
||||
{
|
||||
StoreFile( "ActiveCasinos", a_rJsonFile );
|
||||
ParseCasinos( docAsObject );
|
||||
}
|
||||
else if ( jsonObjectResult.find( "ActiveExchanges" ).value().isArray() )
|
||||
{
|
||||
StoreFile( "ActiveExchanges", a_rJsonFile );
|
||||
ParseExchanges( docAsObject );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::slotNetworkError( QNetworkReply::NetworkError a_eError
|
||||
, const QUrl a_rFailedUrl
|
||||
)
|
||||
{
|
||||
qDebug() << "network error: " << a_eError;
|
||||
QString strAccessedUrl = a_rFailedUrl.toString().split("/").last();
|
||||
slotParseAnswer( ReadFile( strAccessedUrl ) );
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::ParsePromotions( const QJsonObject& a_rJsonPromotions )
|
||||
{
|
||||
qDebug() << "ParsePromotions";
|
||||
@@ -64,3 +79,41 @@ void CasinoCoinWebAPIParser::ParseNewsItems( const QJsonObject& a_rJsonNewsItems
|
||||
qDebug() << "Coming soon - ParseNewsItems";
|
||||
qDebug() << a_rJsonNewsItems;
|
||||
}
|
||||
|
||||
QByteArray CasinoCoinWebAPIParser::ReadFile( QString a_strSourcePath )
|
||||
{
|
||||
QByteArray strAnswer;
|
||||
if ( !QDir( "offlineData" ).exists() )
|
||||
{
|
||||
QDir().mkdir( "offlineData" );
|
||||
}
|
||||
QFile fileOutput( QDir( "offlineData" ).absoluteFilePath( a_strSourcePath ) );
|
||||
if ( !fileOutput.open( QIODevice::ReadOnly ) )
|
||||
{
|
||||
qWarning() << "cannot open file to read: " << QDir::current().relativeFilePath( a_strSourcePath );
|
||||
}
|
||||
else
|
||||
{
|
||||
strAnswer = fileOutput.readAll();
|
||||
fileOutput.close();
|
||||
}
|
||||
return strAnswer;
|
||||
}
|
||||
|
||||
void CasinoCoinWebAPIParser::StoreFile( QString a_strDestinationPath, const QByteArray& a_rJsonFile )
|
||||
{
|
||||
if ( !QDir( "offlineData" ).exists() )
|
||||
{
|
||||
QDir().mkdir( "offlineData" );
|
||||
}
|
||||
QFile fileOutput( QDir( "offlineData" ).absoluteFilePath( a_strDestinationPath ) );
|
||||
if ( !fileOutput.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
|
||||
{
|
||||
qWarning() << "cannot open file to write: " << QDir::current().relativeFilePath( a_strDestinationPath );
|
||||
}
|
||||
else
|
||||
{
|
||||
fileOutput.write( a_rJsonFile );
|
||||
fileOutput.close();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user