Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
        /// <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));
        }
Ejemplo n.º 4
0
        /// <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));
        }
Ejemplo n.º 5
0
        /// <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));
        }
Ejemplo n.º 6
0
        /// <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));
        }
Ejemplo n.º 7
0
        private static Pagination DeserializePagination(JObject responseObject)
        {
            if (responseObject.TryGetValue(FIELD_PAGINATION, out var paginationBodyToken))
            {
                return(BunqJsonConvert.DeserializeObject <Pagination>(paginationBodyToken.ToString()));
            }

            return(null);
        }
Ejemplo n.º 8
0
        private static IList <string> FetchErrorDescriptions(string responseBody)
        {
            var responseBodyObject = BunqJsonConvert.DeserializeObject <JObject>(responseBody);

            return(responseBodyObject[FIELD_ERROR] == null
                ? new List <string> {
                responseBody
            }
                : FetchErrorDescriptions(responseBodyObject));
        }
Ejemplo n.º 9
0
        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));
        }
Ejemplo n.º 10
0
        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));
        }
Ejemplo n.º 11
0
        /// <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));
        }
Ejemplo n.º 12
0
        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()));
        }
Ejemplo n.º 13
0
        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()));
        }
Ejemplo n.º 14
0
        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));
        }
Ejemplo n.º 15
0
        public static T CreateFromJsonString <T>(string json)
        {
            var modelValue = BunqJsonConvert.DeserializeObject <T>(json);

            return(modelValue);
        }
Ejemplo n.º 16
0
 /// <summary>
 /// De-serializes a context from JSON.
 /// </summary>
 public static ApiContext FromJson(string json)
 {
     return(BunqJsonConvert.DeserializeObject <ApiContext>(json));
 }
Ejemplo n.º 17
0
        private static Pagination DeserializePagination(JObject responseObject)
        {
            var paginationBody = responseObject.GetValue(FIELD_PAGINATION).ToString();

            return(BunqJsonConvert.DeserializeObject <Pagination>(paginationBody));
        }
Ejemplo n.º 18
0
        private static JObject DeserializeResponseObject(BunqResponseRaw responseRaw)
        {
            var json = Encoding.UTF8.GetString(responseRaw.BodyBytes);

            return(BunqJsonConvert.DeserializeObject <JObject>(json));
        }