public static GetRequestParameter[] ToGetRequestParameterArray( string[] parameterNames, string[] parameterValues) { if (parameterNames.Length != parameterValues.Length) { throw new ParameterNameValueArrayLengthMismatchException(); } GetRequestParameter[] parameters = new GetRequestParameter[parameterNames.Length]; for (int i = 0; i < parameters.Length; i++) { parameters[i] = new GetRequestParameter(parameterNames[i], parameterValues[i]); } return(parameters); }
/// <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); } }
public IEnumerable <ChatMessage> Get([FromUri] GetRequestParameter parameter) { var utc = parameter.Start.ToUniversalTime(); return(_provider.GetMessages(parameter.StreamId, utc, parameter.Duration)); }
public HttpGetRequestHandler(string uri, string[] parameterNames, string[] parameterValues) : this(uri, GetRequestParameter.ToGetRequestParameterArray(parameterNames, parameterValues)) { }