adFunctions.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. *
  3. * adFunctions.qml
  4. * © Copyrights 2012 inneractive LTD, Nokia. All rights reserved
  5. *
  6. * This file is part of inneractiveAdQML.
  7. *
  8. * inneractiveAdQML is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * inneractiveAdQML is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with inneractiveAdQML. If not, see <http://www.gnu.org/licenses/>.
  20. */
  21. // Helper functions
  22. .pragma library
  23. var __baseUrl = "http://m2m1.inner-active.mobi/simpleM2M/clientRequestAd"
  24. function createQuery(adItem)
  25. {
  26. var parameters = adItem.parameters;
  27. function buildRequestUrl()
  28. {
  29. var requestsUrl = __baseUrl;
  30. function addQuery(key, value)
  31. {
  32. if (value) { // no need to add if no string to add
  33. if (requestsUrl !== __baseUrl)
  34. requestsUrl +="&";
  35. else
  36. requestsUrl +="?";
  37. requestsUrl += key + "=" + value;
  38. }
  39. }
  40. // Required parameters
  41. addQuery("aid", parameters.applicationId);
  42. addQuery("v", parameters.version);
  43. addQuery("po", parameters.distributionId);
  44. addQuery("cid", parameters.__clientId);
  45. addQuery("hid", parameters.__imei);
  46. addQuery("w", parameters.__screenWidth);
  47. addQuery("h", parameters.__screenHeight);
  48. // Optional parameters
  49. addQuery("a", parameters.userAge);
  50. addQuery("c", parameters.category);
  51. addQuery("g", parameters.userGender);
  52. addQuery("k", parameters.keywords);
  53. addQuery("mn", parameters.mobileNumber);
  54. if (parameters.useLocation) {
  55. addQuery("l", parameters.__location);
  56. }
  57. if (parameters.usePositioning) {
  58. addQuery("lg", parameters.__gpsLoc);
  59. }
  60. return requestsUrl;
  61. }
  62. if (!parameters) {
  63. console.log("Ad parameters item is Null");
  64. Qt.quit();
  65. return;
  66. }
  67. else if (!parameters.applicationId) {
  68. console.log("ApplicationID is Null");
  69. Qt.quit();
  70. return;
  71. }
  72. else if (!parameters.distributionId) {
  73. console.log("DistributionID is Null");
  74. Qt.quit();
  75. return;
  76. }
  77. adItem.__query = buildRequestUrl();
  78. }