-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathAppServiceClient.cs
61 lines (50 loc) · 2.09 KB
/
AppServiceClient.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using RESTClient;
using System;
using System.Collections;
using UnityEngine;
namespace Azure.AppServices {
public sealed class AppServiceClient : ZumoClient {
public AppServiceClient(string url) : base(url) {
}
public static AppServiceClient Create(string account) {
string url = AppUrl(account);
return new AppServiceClient(url);
}
private const string URI_API = "api";
public AppServiceTable<E> GetTable<E>(string tableName) where E : class {
return new AppServiceTable<E>(tableName, this);
}
/// <summary>
/// GET custom API
/// </summary>
public IEnumerator InvokeApi<T>(string apiName, Action<IRestResponse<T>> callback = null) where T : new() {
return InvokeApi<T>(apiName, Method.GET, callback);
}
/// <summary>
/// Invokes custom API for HTTP Methods: GET, POST, PUT, PATCH, DELETE
/// </summary>
public IEnumerator InvokeApi<T>(string apiName, Method httpMethod, Action<IRestResponse<T>> callback = null) where T : new() {
string url = ApiUrl(apiName);
Debug.Log(httpMethod.ToString() + " custom API Request Url: " + url);
ZumoRequest request = new ZumoRequest(url, httpMethod, true, User);
yield return request.Request.Send();
request.ParseJson<T>(callback);
}
/// <summary>
/// Invokes custom API with body (of type B) and returning response (of type T)
/// </summary>
public IEnumerator InvokeApi<B, T>(string apiName, Method httpMethod, B body, Action<IRestResponse<T>> callback = null) where T : new() {
string url = ApiUrl(apiName);
Debug.Log(httpMethod.ToString() + " custom API Request Url: " + url);
ZumoRequest request = new ZumoRequest(url, httpMethod, true, User);
request.AddBody<B>(body);
yield return request.Request.Send();
request.ParseJson<T>(callback);
}
private string ApiUrl(string apiName) {
return string.Format("{0}/{1}/{2}", Url, URI_API, apiName);
}
}
}