-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathJsonResponse.cs
43 lines (40 loc) · 1.47 KB
/
JsonResponse.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
using System;
using System.Collections.Generic;
using System.Net.Http;
using System.Text;
using FaceitAPI.Interfaces;
using FaceitAPI.Types;
namespace FaceitAPI.Samples.Samples
{
public class JsonResponse
{
//
// this way, we create IResponse interface implementation.
// put this to GetObject<>(IResponse) method, or after you GetObject<>() set value Response.
//
public void FirstMethod()
{
Faceit faceit = new Faceit(new Authorization("YOUR API KEY"));
faceit.GetObject<Search>(new ResponseImplementation());
}
//
// here we use FaceitAPI.Types.Response type.
// he implementing IResponse, and in constructor put parameter Action<string, HttpResponseMessage>
// Action is invoked like IResponse.ReadResponse method.
//
public void SecondMethod()
{
Faceit faceit = new Faceit(new Authorization("YOUR API KEY"));
faceit.GetObject<Search>(new Response((json, responsemsg) => Console.WriteLine("json response is " + json)));
}
}
class ResponseImplementation : IResponse
{
void IResponse.ReadResponse(string response, HttpResponseMessage message)
{
Console.WriteLine("json response is:: " + response);
Console.WriteLine("Status code is:: " + message.StatusCode);
Console.WriteLine("ContentType is:: " + message.Headers.GetValues("ContentType"));
}
}
}