Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Newtonsoft.Json;
- using Newtonsoft.Json.Serialization;
- using RestSharp;
- using System.Net.Http;
- using System.Net.Http.Headers;
- namespace ConsoleApp5
- {
- class Program
- {
- static void Main(string[] args)
- {
- var client = new XtraLifeClient();
- var response = client.Login("harriehh@gmail.com", "harrie");
- }
- }
- public class Credentials
- {
- public string Network { get; set; }
- public string Id { get; set; }
- public string Secret { get; set; }
- }
- public class XtraLifeClient
- {
- private const string Url = @"https://sandbox-api01.clanofthecloud.mobi/v1/";
- private const string ContentType = "application/json";
- private RestClient _client;
- public XtraLifeClient()
- {
- _client = new RestClient(Url);
- }
- public IRestResponse Login(string username, string password)
- {
- var credentials = new Credentials { Network = "email", Id = "jan@gmail.com", Secret = "jan" };
- var loginRequest = PostRequest("login", credentials);
- return ExecuteRequest(loginRequest);
- }
- private RestRequest PostRequest(string resource, object body)
- {
- var request = new RestRequest(resource, Method.POST);
- request.AddParameter(
- new Parameter(
- ContentType,
- JsonConvert.SerializeObject(
- body,
- new JsonSerializerSettings
- {
- ContractResolver = new CamelCasePropertyNamesContractResolver()
- }),
- ParameterType.RequestBody));
- return request;
- }
- private IRestResponse ExecuteRequest(RestRequest request)
- {
- request.AddHeader("x-apikey", "");
- request.AddHeader("x-apisecret", "");
- return _client.Execute(request);
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement