[locale] Refactor geoip handling

- Configuration **must** be a complete URL. The implementation no
   longer appends /json to the URL.
This commit is contained in:
Adriaan de Groot 2018-04-12 10:11:48 -04:00
parent c0d5a153d4
commit d5623af8ef
5 changed files with 9 additions and 27 deletions

View File

@ -21,9 +21,3 @@
GeoIP::~GeoIP()
{
}
QUrl
GeoIP::fullUrl(const QString& configUrl)
{
return QUrl::fromUserInput( configUrl );
}

View File

@ -36,16 +36,6 @@ struct GeoIP
{
using RegionZonePair = QPair<QString, QString>;
/** @brief Convert configured URL to a complete URL.
*
* Some GeoIP providers are configured with one URL, but actually
* do retrieval with another (e.g. when using the original
* implementation of FreeGeoIP, or when adding an API key).
*
* The default implementation uses the @p configUrl unchanged.
*/
virtual QUrl fullUrl( const QString& configUrl );
/** @brief Handle a (successful) request by interpreting the data.
*
* Should return a ( <zone>, <region> ) pair, e.g.

View File

@ -26,15 +26,6 @@
#include <yaml-cpp/yaml.h>
QUrl
FreeGeoIP::fullUrl( const QString& configUrl )
{
// FIXME: derpy way to append "/json" to the user-specified config URL
QString requestUrl = QString( "%1/json" )
.arg( QUrl::fromUserInput( configUrl ).toString() );
return QUrl( requestUrl );
}
GeoIP::RegionZonePair
FreeGeoIP::processReply( QNetworkReply* reply )
{

View File

@ -21,9 +21,16 @@
#include "GeoIP.h"
/** @brief GeoIP lookup via freegeoip.com
*
* This is the original implementation of GeoIP lookup,
* using the FreeGeoIP service, or similar which returns
* data in the same format.
*
* The data is assumed to be in JSON format with a time_zone attribute.
*/
struct FreeGeoIP : public GeoIP
{
virtual QUrl fullUrl( const QString& configUrl );
virtual RegionZonePair processReply( QNetworkReply* );
} ;

View File

@ -133,7 +133,7 @@ LocaleViewStep::fetchGeoIpTimezone()
} );
QNetworkRequest request;
request.setUrl( handler->fullUrl( m_geoipUrl ) );
request.setUrl( QUrl::fromUserInput( m_geoipUrl ) );
request.setAttribute( QNetworkRequest::FollowRedirectsAttribute, true );
manager->get( request );
}