Advertisement
Guest User

Untitled

a guest
Jan 31st, 2015
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*function loadJSON()
  2. {
  3.     //Damit der jQuerry auf das API zugreifen kann muss CORS auf dem server den zugang gewährleisten, für Wordpress gibt
  4.     //es wp-cors. https://wordpress.org/plugins/wp-cors/
  5.    $.getJSON('http://diego.graphics/api/info/', function(data) {
  6.     console.log(data);
  7.     console.log(data["json_api_version"]);
  8. });
  9. }*/
  10.  
  11. var wordpress_api = new function() {
  12.     this.api_url = "http://example.de/api";
  13.     this.api_key = "";
  14.     this.api_version = "";
  15.     this.api_status = "";
  16.     this.api_controllers = array();
  17.     this.username = "";
  18.     this.password = "";
  19.     this.cookie = "";
  20.     this.nonce = "";
  21.    
  22.     //Setzt die API daten.
  23.     this.setAPI = function (api_url, api_key) {
  24.         this.api_url = api_url;
  25.         this.apu_key = api_key;
  26.         return true;
  27.     };
  28.    
  29.     //Setzt den Logincookie des Benutzers
  30.     this.setCookie = function (cookie) {
  31.         this.cookie = cookie;
  32.         return true;
  33.     }
  34.    
  35.     //Setzt den aktuellen nonce.
  36.     this.setNonce = function (nonce) {
  37.         this.nonce = nonce;
  38.         return true;
  39.     }
  40.    
  41.     //Setzt die API Infos
  42.     this.setInfo = function () {
  43.         $.getJSON('http://diego.graphics/api/info/', function(data) {
  44.             this.api_version = data["json_api_version"];
  45.             this.api_controllers = data["controllers"];
  46.             if(data["status"] == "ok"){
  47.                 this.api_status = true;
  48.             } else {
  49.                 this.api_status = false;
  50.             }
  51.         });
  52.         return true;   
  53.     }
  54.    
  55.     this.getInfo = function (index) {
  56.             switch (index) {
  57.                 case "version":
  58.                     return this.api_version;
  59.                     break;
  60.                 case "controllers":
  61.                     return this.api_controllers;
  62.                     break;
  63.                 case "status":
  64.                     return this.api_status;
  65.                     break;
  66.             }
  67.     }
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement