/// <summary> /// returns a <see cref="CoinTicker"/>object encapsulating dynamic server data /// corresponding to coin with <paramref name="coinId"/>. /// </summary> /// <exception cref="InvalidCoinIdException">thrown if <paramref name="coinId"/>was invalid.</exception> /// <exception cref="DataRequestFailedException"><see cref="sendDataRequest(string)"/></exception> /// <exception cref="DataRequestUnsuccessfulStatusCodeException"><see cref="sendDataRequest(string)"/> /// </exception> /// <exception cref="InvalidServerResponse">thrown if a <see cref="CoinTicker"/>object could not /// be parsed from server response string.</exception> /// <param name="coinId"></param> /// <returns> /// <see cref="CoinTicker"/>object corresponding to coin with <paramref name="coinId"/>. /// </returns> public static CoinTicker RequestCoinTicker(int coinId) { CoinTicker CoinTicker; if (coinId <= 0) { throw new InvalidCoinIdException(); } string uri = TICKER_REQUEST_URL + coinId; string serverResponse = sendDataRequest(uri); try { CoinTicker = CoinTicker.Parse(serverResponse, coinId); return(CoinTicker); } catch (CoinIndexNotFoundException coinIndexNotFoundException) { throw new CoinIdDoesNotExistException(coinId, coinIndexNotFoundException); } catch (CoinTickerJsonParseException coinTickerJsonParseException) { throw new ServerResponseParseException(coinTickerJsonParseException); } }
/// <summary> /// requests from server <see cref="CoinTickers"/> with indices in range /// [<paramref name="startIndex"/>, (<paramref name="startIndex"/> + <paramref name="numberOfCoins"/>)]. /// </summary> /// <param name="startIndex"></param> /// <param name="numberOfCoins"></param> /// <param name="sortType"></param> /// <returns> /// <see cref="CoinTicker"/> array of length <paramref name="numberOfCoins"/> containing /// <see cref="CoinTicker"/>s of indices in range /// [[<paramref name="startIndex"/>, (<paramref name="startIndex"/> + <paramref name="numberOfCoins"/>)] /// </returns> /// <exception cref="CoinTickerRequestInvalidStartIndexException"> /// thrown if <paramref name="startIndex"/> < 0 /// </exception> /// <exception cref="CoinTickerRequestInvalidNumberOfCoinsException"> /// thrown if <paramref name="numberOfCoins"/> <= 0 || /// <paramref name="numberOfCoins"/> > COIN_TICKER_REQUEST_MAX_NUMBER_OF_COINS /// </exception> /// <exception cref="CoinTickerRequestInvalidStartIndexException"> /// thrown if <paramref name="startIndex"/> does not exist in server. /// </exception> /// <exception cref="ServerResponseParseException"> /// thrown if server response was invalid. /// </exception> public static CoinTicker[] RequestCoinTicker( int startIndex, int numberOfCoins, eSortType sortType = eSortType.Id) { if (startIndex < 0) // invalid start index { throw new CoinTickerRequestInvalidStartIndexException(startIndex); } // invalid number of coins if (numberOfCoins <= 0 || numberOfCoins > COIN_TICKER_REQUEST_MAX_NUMBER_OF_COINS) { throw new CoinTickerRequestInvalidNumberOfCoinsException(1, 100); } // prepare request string uri = TICKER_REQUEST_URL; GetRequestParameter[] requestParameters = new GetRequestParameter[] { new GetRequestParameter("start", startIndex.ToString()), new GetRequestParameter("limit", numberOfCoins.ToString()), new GetRequestParameter("sort", sortTypeToString[sortType].ToString()), new GetRequestParameter("structure", COIN_TICKER_REQUEST_STRUCTURE_TYPE) }; string serverResponseJson = sendDataRequest(uri, requestParameters); try { CoinTicker[] coinDataArray = CoinTicker.ParseArray(serverResponseJson, startIndex, numberOfCoins); return(coinDataArray); } catch (CoinIndexNotFoundException coinIndexNotFoundException) { throw new CoinTickerRequestInvalidStartIndexException(startIndex, coinIndexNotFoundException); } catch (CoinTickerJsonParseException coinTickerJsonParseException) { throw new ServerResponseParseException(coinTickerJsonParseException); } }