protected static BunqResponse <T> FromJson <T>(BunqResponseRaw responseRaw) { var responseItemObject = GetResponseItemObject(responseRaw); var responseValue = BunqJsonConvert.DeserializeObject <T>(responseItemObject.ToString()); return(new BunqResponse <T>(responseValue, responseRaw.Headers)); }
private static JObject GetResponseItemObject(BunqResponseRaw responseRaw) { var json = Encoding.UTF8.GetString(responseRaw.BodyBytes); var responseWithWrapper = BunqJsonConvert.DeserializeObject <JObject>(json); return(responseWithWrapper.GetValue(FIELD_RESPONSE).ToObject <JArray>().Value <JObject>(INDEX_FIRST)); }
/// <summary> /// De-serializes an ID object and returns its integer value. /// </summary> protected static BunqResponse <int> ProcessForId(BunqResponseRaw responseRaw) { var responseItemObject = GetResponseItemObject(responseRaw); var unwrappedItemJsonString = GetUnwrappedItemJsonString(responseItemObject, FIELD_ID); var responseValue = BunqJsonConvert.DeserializeObject <Id>(unwrappedItemJsonString).IdInt; return(new BunqResponse <int>(responseValue, responseRaw.Headers)); }
/// <summary> /// De-serialize an object from JSON. /// </summary> protected static BunqResponse <T> FromJson <T>(BunqResponseRaw responseRaw, string wrapper) { var responseItemObject = GetResponseItemObject(responseRaw); var unwrappedItemJsonString = GetUnwrappedItemJsonString(responseItemObject, wrapper); var responseValue = BunqJsonConvert.DeserializeObject <T>(unwrappedItemJsonString); return(new BunqResponse <T>(responseValue, responseRaw.Headers)); }
/// <summary> /// De-serializes an UUID object and returns its string value. /// </summary> protected static BunqResponse <string> ProcessForUuid(BunqResponseRaw responseRaw) { var responseItemObject = GetResponseItemObject(responseRaw); var unwrappedItemJsonString = GetUnwrappedItemJsonString(responseItemObject, FIELD_UUID); var responseValue = BunqJsonConvert.DeserializeObject <Uuid>(unwrappedItemJsonString).UuidString; return(new BunqResponse <string>(responseValue, responseRaw.Headers)); }
/// <summary> /// De-serializes an object from a JSON format specific to Installation and SessionServer. /// </summary> protected static BunqResponse <T> FromJsonArrayNested <T>(BunqResponseRaw responseRaw) { var json = Encoding.UTF8.GetString(responseRaw.BodyBytes); var jObject = BunqJsonConvert.DeserializeObject <JObject>(json); var jsonArrayString = jObject.GetValue(FIELD_RESPONSE).ToString(); var responseValue = BunqJsonConvert.DeserializeObject <T>(jsonArrayString); return(new BunqResponse <T>(responseValue, responseRaw.Headers)); }
private static Pagination DeserializePagination(JObject responseObject) { if (responseObject.TryGetValue(FIELD_PAGINATION, out var paginationBodyToken)) { return(BunqJsonConvert.DeserializeObject <Pagination>(paginationBodyToken.ToString())); } return(null); }
private static IList <string> FetchErrorDescriptions(string responseBody) { var responseBodyObject = BunqJsonConvert.DeserializeObject <JObject>(responseBody); return(responseBodyObject[FIELD_ERROR] == null ? new List <string> { responseBody } : FetchErrorDescriptions(responseBodyObject)); }
protected static BunqResponse <List <T> > FromJsonList <T>(BunqResponseRaw responseRaw) { var responseObject = DeserializeResponseObject(responseRaw); var responseValue = responseObject .GetValue(FIELD_RESPONSE).ToObject <JArray>() .Select(itemObject => BunqJsonConvert.DeserializeObject <T>(itemObject.ToString())) .ToList(); var pagination = DeserializePagination(responseObject); return(new BunqResponse <List <T> >(responseValue, responseRaw.Headers, pagination)); }
public static async Task <BunqStore> Load() { var file = new FileInfo(FILENAME); if (!file.Exists) { return(new BunqStore()); } var data = await File.ReadAllTextAsync(file.FullName); return(BunqJsonConvert.DeserializeObject <BunqStore>(data)); }
/// <summary> /// Create access token /// </summary> public static OauthAccessToken Create( OauthGrantType grantType, string authCode, string redirectUri, OauthClient client ) { HttpClient apiClient = new HttpClient(); HttpResponseMessage responseRaw = apiClient.PostAsync( CreateTokenUri(grantType, authCode, redirectUri, client), null ).Result; return(BunqJsonConvert.DeserializeObject <OauthAccessToken>(responseRaw.Content.ReadAsStringAsync().Result)); }
private SandboxUser GenerateNewSandboxUser() { var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("X-Bunq-Client-Request-Id", "unique"); httpClient.DefaultRequestHeaders.Add("Cache-Control", "no"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Geolocation", "0 0 0 0 NL"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Language", "en_US"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Region", "en_US"); httpClient.DefaultRequestHeaders.Add("User-Agent", "hoi"); var requestTask = httpClient.PostAsync("https://sandbox.public.api.bunq.com/v1/sandbox-user", null); requestTask.Wait(); var responseString = requestTask.Result.Content.ReadAsStringAsync().Result; var responseJson = BunqJsonConvert.DeserializeObject <JObject>(responseString); return(BunqJsonConvert.DeserializeObject <SandboxUser>(responseJson.First.First.First.First.First.ToString())); }
private static SandboxUser GenerateNewSandboxUser() { var httpClient = new HttpClient(); httpClient.DefaultRequestHeaders.Add("X-Bunq-Client-Request-Id", "unique"); httpClient.DefaultRequestHeaders.Add("Cache-Control", "no"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Geolocation", "0 0 0 0 NL"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Language", "en_US"); httpClient.DefaultRequestHeaders.Add("X-Bunq-Region", "en_US"); httpClient.DefaultRequestHeaders.Add("User-Agent", "sdk_csharp_test_case"); var requestTask = httpClient.PostAsync(ApiEnvironmentType.SANDBOX.BaseUri + "sandbox-user", null); requestTask.Wait(); var responseString = requestTask.Result.Content.ReadAsStringAsync().Result; var responseJson = BunqJsonConvert.DeserializeObject <JObject>(responseString); return(BunqJsonConvert.DeserializeObject <SandboxUser>(responseJson.First.First.First.First.First .ToString())); }
public async Task <BunqResponse> BunqSendAsync(HttpRequestMessage request) { //TODO check if session ready if (NeedsSession(request.RequestUri)) { } SetDefaultHeaders(request); //SetHeaders(request, customHeaders); var needSigning = NeedsSigning(request.RequestUri); if (needSigning) { SetSessionHeaders(request); } //var responseMessage = client.SendAsync(requestMessage).Result; var response = await SendAsync(request); AssertResponseSuccess(response); if (needSigning) { ValidateResponse(response); } var json = await response.Content.ReadAsStringAsync(); //var json = Encoding.UTF8.GetString(responseRaw.BodyBytes); var jObject = BunqJsonConvert.DeserializeObject <JObject>(json); var responseArray = (JArray)jObject.GetValue(FIELD_RESPONSE); //TODO: response.Headers; return(new BunqResponse(responseArray)); }
public static T CreateFromJsonString <T>(string json) { var modelValue = BunqJsonConvert.DeserializeObject <T>(json); return(modelValue); }
/// <summary> /// De-serializes a context from JSON. /// </summary> public static ApiContext FromJson(string json) { return(BunqJsonConvert.DeserializeObject <ApiContext>(json)); }
private static Pagination DeserializePagination(JObject responseObject) { var paginationBody = responseObject.GetValue(FIELD_PAGINATION).ToString(); return(BunqJsonConvert.DeserializeObject <Pagination>(paginationBody)); }
private static JObject DeserializeResponseObject(BunqResponseRaw responseRaw) { var json = Encoding.UTF8.GetString(responseRaw.BodyBytes); return(BunqJsonConvert.DeserializeObject <JObject>(json)); }