Esempio n. 1
0
 /// <summary>
 /// Creates URL used to receive book details.
 /// </summary>
 /// <param name="identifierKind">kind of identifier</param>
 /// <param name="identifierValue">value of identifier</param>
 /// <returns>URL used to receive book details</returns>
 private string CreateBookURL(BookIdentifier identifierKind, string identifierValue)
 {
     return string.Format("http://{0}/api/books?{1}={2}",
         ServerAddress,
         BookIdentifierToStringDictionary[identifierKind],
         identifierValue);
 }
Esempio n. 2
0
        /// <summary>
        /// Sends request to receive book according its identifier.
        /// </summary>
        /// <param name="identifierKind">kind of identifier</param>
        /// <param name="identifierValue">value of identifier</param>
        /// <returns>book with specified identifier</returns>
        public async Task<Book> GetBookBy(BookIdentifier identifierKind, string identifierValue)
        {
            if (identifierValue == null)
                throw new ArgumentNullException("identifierValue");
            if (string.IsNullOrWhiteSpace(identifierValue))
                throw new ArgumentException("identifierValue");

            if (!BookIdentifierToStringDictionary.ContainsKey(identifierKind))
                throw new ArgumentException("identifierKind");

            string url = CreateBookURL(identifierKind, identifierValue);

            var book = await RequestManager.DownloadDataAsync<Book>(url);
            return book;
        }