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
25#include "GooglePolyScriptingInterface.h"25#include "GooglePolyScriptingInterface.h"
26#include "ScriptEngineLogging.h"26#include "ScriptEngineLogging.h"
27 27
28const QString listPolyUrl = "https://poly.googleapis.com/v1/assets?";28const QString LIST_POLY_URL = "https://poly.googleapis.com/v1/assets?";
29const QString getPolyUrl = "https://poly.googleapis.com/v1/assets/model?";29const QString GET_POLY_URL = "https://poly.googleapis.com/v1/assets/model?";
30 30
31const QStringList validFormats = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";31const QStringList VALID_FORMATS = QStringList() << "BLOCKS" << "FBX" << "GLTF" << "GLTF2" << "OBJ" << "TILT" << "";
32const QStringList validCategories = QStringList() << "animals" << "architecture" << "art" << "food" << 32const QStringList VALID_CATEGORIES = QStringList() << "animals" << "architecture" << "art" << "food" <<
33 "nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";33 "nature" << "objects" << "people" << "scenes" << "technology" << "transport" << "";
34 34
35GooglePolyScriptingInterface::GooglePolyScriptingInterface() {35GooglePolyScriptingInterface::GooglePolyScriptingInterface() {
@@ -75,22 +75,24 @@ QString GooglePolyScriptingInterface::getGLTF2(QString keyword, QString category · 39 unmodified lines
75 QUrl url = formatURLQuery(keyword, category, "GLTF2");75 QUrl url = formatURLQuery(keyword, category, "GLTF2");
76 return getModelURL(url);76 return getModelURL(url);
77}77}
78 78
79/* 79// This method will not be useful until we support Tilt models
80// This method will not work until we support Tilt models
81QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {80QString GooglePolyScriptingInterface::getTilt(QString keyword, QString category) {
82 QUrl url = formatURLQuery(keyword, category, "TILT");81 QUrl url = formatURLQuery(keyword, category, "TILT");
83 return getModelURL(url);82 return getModelURL(url);
84}83}
85*/
86 84
87// Can provide asset name or full URL to model85// Can provide asset name or full URL to model
88QString GooglePolyScriptingInterface::getModelInfo(QString name) {86QString GooglePolyScriptingInterface::getModelInfo(QString name) {
89 if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {87 if (name.contains("poly.googleapis") || name.contains("poly.google.com")) {
90 QStringList list = name.split("/");88 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 }
92 }94 }
93 QString urlString = QString(getPolyUrl);95 QString urlString(GET_POLY_URL);
94 urlString = urlString.replace("model", name) + "key=" + authCode;96 urlString = urlString.replace("model", name) + "key=" + authCode;
95 qCDebug(scriptengine) << "Google URL request: " << urlString;97 qCDebug(scriptengine) << "Google URL request: " << urlString;
96 QUrl url(urlString);98 QUrl url(urlString);
@@ -106,7 +108,7 @@ int GooglePolyScriptingInterface::getRandIntInRange(int length) { · 9 unmodified lines
106 108
107QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {109QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString category, QString format) {
108 QString queries;110 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)) {
110 return QUrl("");112 return QUrl("");
111 } else {113 } else {
112 if (!keyword.isEmpty()) {114 if (!keyword.isEmpty()) {
@@ -119,7 +121,7 @@ QUrl GooglePolyScriptingInterface::formatURLQuery(QString keyword, QString categ · 6 unmodified lines
119 if (!format.isEmpty()) {121 if (!format.isEmpty()) {
120 queries.append("&format=" + format);122 queries.append("&format=" + format);
121 }123 }
122 QString urlString = QString(listPolyUrl + "key=" + authCode + queries);124 QString urlString = QString(LIST_POLY_URL + "key=" + authCode + queries);
123 return QUrl(urlString);125 return QUrl(urlString);
124 }126 }
125}127}
@@ -147,7 +149,6 @@ QByteArray GooglePolyScriptingInterface::getHTTPRequest(QUrl url) { · 21 unmodified lines
147 149
148// 0 = asset list, 1 = model from asset list, 2 = specific model150// 0 = asset list, 1 = model from asset list, 2 = specific model
149QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {151QVariant GooglePolyScriptingInterface::parseJSON(QUrl url, int fileType) {
150 //QString firstItem = QString::fromUtf8(response->readAll());
151 QByteArray jsonString = getHTTPRequest(url);152 QByteArray jsonString = getHTTPRequest(url);
152 QJsonDocument doc = QJsonDocument::fromJson(jsonString);153 QJsonDocument doc = QJsonDocument::fromJson(jsonString);
153 QJsonObject obj = doc.object();154 QJsonObject obj = doc.object();