Advertisement
diegographics

Untitled

Mar 15th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.71 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class WordpressCore : MonoBehaviour
  5. {
  6.     //JSON Seriation
  7.     public class get_nonce_structure
  8.     {
  9.         public string status { get; set; }
  10.         public string controller { get; set; }
  11.         public string method { get; set; }
  12.         public string nonce { get; set; }
  13.     }
  14.  
  15.  
  16.     public class wordpress_api
  17.     {
  18.  
  19.         //Privates
  20.         private string url;
  21.         private bool premium;
  22.         public delegate void ResponseHandler(string responseContent);
  23.         IEnumerator AskServerSomething(string request_url, ResponseHandler onSuccess, ResponseHandler onFail)
  24.         {
  25.             Debug.Log("AskServerSomething wird ausgeführt");
  26.             WWW www = new WWW(url + request_url);
  27.             Debug.Log("AskServerSomething wurde ausgeführt");
  28.             yield return www;
  29.             Debug.Log("Yield return fertig");
  30.             if (www.error == null)
  31.             {
  32.                 Debug.Log("success: " + www.text);
  33.                 onSuccess(www.text); //Hier soll der string an den erfolgsevent gegeben werden
  34.             }
  35.             else
  36.             {
  37.                 Debug.Log("something wrong: " + www.text);
  38.                 onFail(www.text); //Hier soll der string an den fail event gegeben werden
  39.             }
  40.         }
  41.  
  42.  
  43.         public enum Controller
  44.         {
  45.             Core,
  46.             Posts,
  47.             Respond,
  48.             Widgets,
  49.             UserPlus
  50.         }
  51.         public enum Method
  52.         {
  53.             __construct,
  54.             email_exists,
  55.             username_exists,
  56.             register,
  57.             get_avatar,
  58.             get_userinfo,
  59.             retrieve_password,
  60.             validate_auth_cookie,
  61.             generate_auth_cookie,
  62.             get_currentuserinfo,
  63.             get_user_meta,
  64.             update_user_meta,
  65.             delete_user_meta,
  66.             xprofile,
  67.             xprofile_update,
  68.             fb_connect,
  69.             post_comment,
  70.             profile,
  71.             friends,
  72.             threads,
  73.             thread,
  74.             new_message,
  75.             mark_thread_read,
  76.             mark_thread_unread,
  77.             messages_count,
  78.             avatar_upload,
  79.             delete_account,
  80.             get_sidebar,
  81.             submit_comment,
  82.             create_post,
  83.             update_post,
  84.             delete_post,
  85.             info,
  86.             get_recent_posts,
  87.             get_posts,
  88.             get_post,
  89.             get_page,
  90.             get_date_posts,
  91.             get_category_posts,
  92.             get_tag_posts,
  93.             get_author_posts,
  94.             get_search_results,
  95.             get_date_index,
  96.             get_category_index,
  97.             get_tag_index,
  98.             get_author_index,
  99.             get_page_index,
  100.             get_nonce
  101.         }
  102.  
  103.         public void Initialize(string set_url, bool set_premium)
  104.         {
  105.             url = set_url;
  106.             premium = set_premium;
  107.            
  108.         }
  109.        
  110.         public void GetNonce(Controller SetController, Method SetMethod)
  111.         {
  112.             Debug.Log("Ask server for nonce");
  113.             StartCoroutine(AskServerSomething("get_nonce/?controller=" + SetController.ToString() + "&method=" + SetMethod.ToString(), new ResponseHandler(GetNonce_Succes), new ResponseHandler(GetNonce_Fail)));
  114.         }
  115.         private void GetNonce_Succes(string content)
  116.         {
  117.             var myObject = JsonUtility.FromJson<get_nonce_structure>(content);
  118.             Debug.Log("Status: " + myObject.status + " Nonce: " + myObject.nonce);
  119.         }
  120.         private void GetNonce_Fail(string content)
  121.         {
  122.             Debug.Log("Something goes wrong");
  123.         }
  124.  
  125.     }
  126. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement