Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. using Newtonsoft.Json;
  2. using Newtonsoft.Json.Serialization;
  3. using RestSharp;
  4. using System.Net.Http;
  5. using System.Net.Http.Headers;
  6.  
  7. namespace ConsoleApp5
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. var client = new XtraLifeClient();
  14. var response = client.Login("harriehh@gmail.com", "harrie");
  15. }
  16. }
  17.  
  18. public class Credentials
  19. {
  20. public string Network { get; set; }
  21. public string Id { get; set; }
  22. public string Secret { get; set; }
  23. }
  24.  
  25. public class XtraLifeClient
  26. {
  27. private const string Url = @"https://sandbox-api01.clanofthecloud.mobi/v1/";
  28. private const string ContentType = "application/json";
  29. private RestClient _client;
  30.  
  31. public XtraLifeClient()
  32. {
  33. _client = new RestClient(Url);
  34. }
  35.  
  36. public IRestResponse Login(string username, string password)
  37. {
  38. var credentials = new Credentials { Network = "email", Id = "jan@gmail.com", Secret = "jan" };
  39. var loginRequest = PostRequest("login", credentials);
  40. return ExecuteRequest(loginRequest);
  41. }
  42.  
  43. private RestRequest PostRequest(string resource, object body)
  44. {
  45. var request = new RestRequest(resource, Method.POST);
  46. request.AddParameter(
  47. new Parameter(
  48. ContentType,
  49. JsonConvert.SerializeObject(
  50. body,
  51. new JsonSerializerSettings
  52. {
  53. ContractResolver = new CamelCasePropertyNamesContractResolver()
  54. }),
  55. ParameterType.RequestBody));
  56.  
  57. return request;
  58. }
  59.  
  60. private IRestResponse ExecuteRequest(RestRequest request)
  61. {
  62. request.AddHeader("x-apikey", "");
  63. request.AddHeader("x-apisecret", "");
  64. return _client.Execute(request);
  65. }
  66. }
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement