History

fixed constant names, added another URL check

Elisa Lupin-Jimenez committed 8 years ago

Commit 01c10321 parent 03f06aa3 files · +16 −15Browse files

Showing the changes to interface/src/scripting/GooglePolyScriptingInterface.cpp (1 of 3 files). Show all

Unified · Split

interface/src/scripting/GooglePolyScriptingInterface.cpp+14−13
@@ -25,11 +25,11 @@ · 24 unmodified lines
2525 #include "GooglePolyScriptingInterface.h"
2626 #include "ScriptEngineLogging.h"
2727
28−const QString listPolyUrl = "https://poly.googleapis.com/v1/assets?";
29−const QString getPolyUrl = "https://poly.googleapis.com/v1/assets/model?";
28+const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?";
29+const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?";
3030
31−const QStringList validFormats = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
32−const QStringList validCategories = QStringList() << "animals" << "architecture" << "art" << "food" <<
31+const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
32+const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" <<
3333 "nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";
3434
3535 GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
@@ -75,22 +75,24 @@ QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category · 39 unmodified lines
7575 QUrl url = formatURLQuery(keyword, category, "GLTF2");
7676 return getModelURL(url);
7777 }
78−
79−/*
80−// This method will not work until we support Tilt models
78+
79+// This method will not be useful until we support Tilt models
8180 QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
8281 QUrl url = formatURLQuery(keyword, category, "TILT");
8382 return getModelURL(url);
8483 }
85−*/
8684
8785 // Can provide asset name or full URL to model
8886 QString GooglePolyScriptingInterface::getModelInfo(QString name) {
8987 if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
9088 QStringList list = name.split("/");
91− name = list[4];
89+ if (name.contains("poly.googleapis")) {
90+ name = list[4];
91+ } else {
92+ name = list.last();
93+ }
9294 }
93− QString urlString = QString(getPolyUrl);
95+ QString urlString(GET_POLY_URL);
9496 urlString = urlString.replace("model", name) + "key=" + authCode;
9597 qCDebug(scriptengine) << "Google URL request: " << urlString;
9698 QUrl url(urlString);
@@ -106,7 +108,7 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) { · 9 unmodified lines
106108
107109 QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
108110 QString queries;
109− if (!validFormats.contains(format, Qt::CaseInsensitive) || !validCategories.contains(category, Qt::CaseInsensitive)) {
111+ if (!VALID_FORMATS.contains(format, Qt::CaseInsensitive) || !VALID_CATEGORIES.contains(category, Qt::CaseInsensitive)) {
110112 return QUrl("");
111113 } else {
112114 if (!keyword.isEmpty()) {
@@ -119,7 +121,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 6 unmodified lines
119121 if (!format.isEmpty()) {
120122 queries.append("&format=" + format);
121123 }
122− QString urlString = QString(listPolyUrl + "key=" + authCode + queries);
124+ QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);
123125 return QUrl(urlString);
124126 }
125127 }
@@ -147,7 +149,6 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) { · 21 unmodified lines
147149
148150 // 0 = asset list, 1 = model from asset list, 2 = specific model
149151 QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
150− //QString firstItem = QString::fromUtf8(response->readAll());
151152 QByteArray jsonString = getHTTPRequest(url);
152153 QJsonDocument doc = QJsonDocument::fromJson(jsonString);
153154 QJsonObject obj = doc.object();