コード例 #1
0
    public void RequestBattle(string tileId, APIResponseHandler handler)
    {
        var path = string.Format("/api/battles");

        Post(path, new Dictionary <string, string>()
        {
            { "tile_id", tileId }
        }, handler);
    }
コード例 #2
0
    protected IEnumerator GetRequest(string path, APIResponseHandler handler)
    {
        var url = string.Format("{0}{1}", RootUrl, path);

        Debug.Log(string.Format("Headers: client={0}, access-token={1}, uid={2}", PlayerPrefs.GetString("client"), PlayerPrefs.GetString("access-token"), PlayerPrefs.GetString("uid")));
        Debug.Log("GET " + url);
        var www = new WWW(url, null, Headers());

        yield return(www);

        handler(www);
    }
コード例 #3
0
    public void LogIn(string email, string password, APIResponseHandler handler)
    {
        var path = "/auth/sign_in";
        var body = new Dictionary <string, string>()
        {
            { "email", email },
            { "password", password }
        };

        Debug.Log("Posting email: " + email + " and password: " + password);
        Post(path, body, handler);
    }
コード例 #4
0
    public void SignUp(string email, string handle, string password, APIResponseHandler handler)
    {
        var path = "/auth.json";
        var body = new Dictionary <string, string>()
        {
            { "nickname", handle },
            { "email", email },
            { "password", password },
            { "password_confirmation", password }
        };

        Debug.Log("Posting email: " + email + " and password: " + password);
        Post(path, body, handler);
    }
コード例 #5
0
    public void TestUser(APIResponseHandler successHandler, APIResponseHandler errorHandler)
    {
        var path = string.Format("/api/user");

        Get(path, (response) => {
            var status = response.responseHeaders["STATUS"];
            if (status.Contains("200"))
            {
                WriteUserInfo(JSON.Parse(response.text));
                successHandler.Invoke(response);
            }
            else
            {
                errorHandler.Invoke(response);
            }
        });
    }
コード例 #6
0
    protected IEnumerator PostRequest(string path, Dictionary <string, string> body, APIResponseHandler handler)
    {
        var url = string.Format("{0}{1}", RootUrl, path);

        Debug.Log("POST " + url);
        var form = new WWWForm();

        foreach (KeyValuePair <string, string> kv in body)
        {
            form.AddField(kv.Key, kv.Value);
        }
        var www = new WWW(url, form.data, Headers());


        yield return(www);

        handler(www);
    }
コード例 #7
0
    public void RequestTile(string id, APIResponseHandler handler)
    {
        var path = string.Format("/api/tiles/{0}", id);

        Get(path, handler);
    }
コード例 #8
0
    public void TestAuth(APIResponseHandler handler)
    {
        var path = string.Format("/auth/validate_token?uid={0}&client={1}&access-token={2}", uid, client, accessToken);

        Get(path, handler);
    }
コード例 #9
0
 protected void Post(string path, Dictionary <string, string> body, APIResponseHandler handler)
 {
     StartCoroutine(PostRequest(path, body, handler));
 }
コード例 #10
0
 protected void Get(string path, APIResponseHandler handler)
 {
     StartCoroutine(GetRequest(path, handler));
 }