-
Notifications
You must be signed in to change notification settings - Fork 1
/
GameClient.cs
54 lines (47 loc) · 2.12 KB
/
GameClient.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
using RestSharp;
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
namespace ReversiSharpClient
{
internal class GameClient
{
private readonly RestClient _restClient;
public GameClient(string baseUrl)
{
_restClient = new RestClient {BaseUrl = baseUrl};
}
//~ ----------------------------------------------------------------------------------------------------------------
public GameStatus Cancel(string cancellationCode)
{
var request = new RestRequest(Method.DELETE) {Resource = "/cancel/{cancellationCode}"};
request.AddParameter("cancellationCode", cancellationCode, ParameterType.UrlSegment);
var response = _restClient.Execute<GameStatus>(request);
return response.Data;
}
//~ ----------------------------------------------------------------------------------------------------------------
public GameStatus Move(string authCode, string piece)
{
var request = new RestRequest(Method.PUT) {Resource = "/move/{authCode}/{piece}"};
request.AddParameter("authCode", authCode, ParameterType.UrlSegment);
request.AddParameter("piece", piece, ParameterType.UrlSegment);
var response = _restClient.Execute<GameStatus>(request);
return response.Data;
}
//~ ----------------------------------------------------------------------------------------------------------------
public Authorization Start()
{
var request = new RestRequest(Method.POST) {Resource = "/start"};
var response = _restClient.Execute<Authorization>(request);
return response.Data;
}
//~ ----------------------------------------------------------------------------------------------------------------
public GameStatus GetStatus()
{
var request = new RestRequest(Method.GET) {Resource = "/status"};
var response = _restClient.Execute<GameStatus>(request);
return response.Data;
}
}
}