Пример #1
0
        public async Task <AddressList> postAddressesAsync(AddressQueryCondition _obj, int?_page = null, int?_per_page = null)
        {
            var client      = new ServantClient();
            var queryparams = new List <string> {
                _page.HasValue ? $"_page={_page.Value}" : null,
                _per_page.HasValue ? $"_per_page={_per_page.Value}" : null,
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";

             #if DEBUG
            var jsonObj = JsonConvert.SerializeObject(_obj, Formatting.Indented);
             #else
            var jsonObj = JsonConvert.SerializeObject(_obj);
             #endif
            var res = await client.PostAsync($"{server}/addresses{qp}", new StringContent(jsonObj, Encoding.UTF8, "application/json"));

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"-----");
            Debug.WriteLine(jsonObj);
            Debug.WriteLine($"-----");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            return(JsonConvert.DeserializeObject <AddressList>(content));
        }
Пример #2
0
        public async Task deleteBookIsbnByIsbnAsync(ISBN _isbn)
        {
            var client = new ServantClient();
            var queryparams = new List <string> {
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp  = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";
            var res = await client.DeleteAsync($"{server}/book/isbn/{_isbn}{qp}");

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            JsonConvert.DeserializeObject(content);
        }
Пример #3
0
        public async Task <Book> getBookByIdAsync(BookId _id)
        {
            var client = new ServantClient();
            var queryparams = new List <string> {
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp  = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";
            var res = await client.GetAsync($"{server}/book/{_id}{qp}");

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            return(JsonConvert.DeserializeObject <Book>(content));
        }
Пример #4
0
        public async Task <BookList> getBooksAsync(int?_page = null, int?_per_page = null)
        {
            var client      = new ServantClient();
            var queryparams = new List <string> {
                _page.HasValue ? $"_page={_page.Value}" : null,
                _per_page.HasValue ? $"_per_page={_per_page.Value}" : null,
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp  = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";
            var res = await client.GetAsync($"{server}/books{qp}");

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            return(JsonConvert.DeserializeObject <BookList>(content));
        }
Пример #5
0
        public async Task putBookIsbnByIsbnAsync(ISBN _isbn, Book _obj)
        {
            var client = new ServantClient();
            var queryparams = new List <string> {
            }.Where(e => !string.IsNullOrEmpty(e));
            var qp = queryparams.Count() > 0 ? $"?{string.Join("&", queryparams)}" : "";

             #if DEBUG
            var jsonObj = JsonConvert.SerializeObject(_obj, Formatting.Indented);
             #else
            var jsonObj = JsonConvert.SerializeObject(_obj);
             #endif
            var res = await client.PutAsync($"{server}/book/isbn/{_isbn}{qp}", new StringContent(jsonObj, Encoding.UTF8, "application/json"));

            Debug.WriteLine($">>> {res.RequestMessage}");
            Debug.WriteLine($"-----");
            Debug.WriteLine(jsonObj);
            Debug.WriteLine($"-----");
            Debug.WriteLine($"<<< {(int)res.StatusCode} {res.ReasonPhrase}");
            var content = await res.Content.ReadAsStringAsync();

            Debug.WriteLine($"<<< {content}");
            JsonConvert.DeserializeObject(content);
        }