-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMPAPIResponse.cs
88 lines (74 loc) · 2.56 KB
/
MPAPIResponse.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
// Decompiled with JetBrains decompiler
// Type: MercadoPago.MPAPIResponse
// Assembly: MercadoPago, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: 0C24A3BA-51C0-4EAB-8180-D4EA12994FDF
// Assembly location: C:\Users\Laucha\source\repos\WindowsFormsApp1\WindowsFormsApp1\bin\Debug\MercadoPago.dll
using Newtonsoft.Json.Linq;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Text;
namespace MercadoPago
{
public class MPAPIResponse
{
public bool IsFromCache;
public string HttpMethod { get; protected set; }
public string Url { get; protected set; }
public HttpWebRequest Request { get; protected set; }
public string Payload { get; protected set; }
public HttpWebResponse Response { get; protected set; }
public int StatusCode { get; protected set; }
public string StatusDescription { get; protected set; }
public string StringResponse { get; protected set; }
public JObject JsonObjectResponse { get; protected set; }
public MPAPIResponse(
MercadoPago.HttpMethod httpMethod,
HttpWebRequest request,
JObject payload,
HttpWebResponse response)
{
this.Request = request;
this.Response = response;
this.ParseRequest(httpMethod, request, payload);
this.ParseResponse(response);
Trace.WriteLine("Server response: " + this.StringResponse);
}
private void ParseRequest(MercadoPago.HttpMethod httpMethod, HttpWebRequest request, JObject payload)
{
this.HttpMethod = httpMethod.ToString();
this.Url = request.RequestUri.ToString();
if (payload == null)
return;
this.Payload = payload.ToString();
}
private void ParseResponse(HttpWebResponse response)
{
this.StatusCode = (int) response.StatusCode;
this.StatusDescription = response.StatusDescription;
if (response.GetResponseStream() == null)
return;
try
{
Stream responseStream = response.GetResponseStream();
StreamReader streamReader = new StreamReader(responseStream, Encoding.UTF8);
this.StringResponse = streamReader.ReadToEnd();
streamReader.Close();
responseStream.Close();
}
catch (Exception ex)
{
throw new MPException(ex.Message);
}
try
{
this.JsonObjectResponse = JObject.Parse(this.StringResponse);
}
catch (Exception ex)
{
Console.WriteLine("Error parsing jsonObect");
}
}
}
}