public async Task can_do_get_single_dynamic_request_tokenized() { var endpoint = "users/{userid}.json"; RestGetOptions o = new RestGetOptions(); o.PathParameters.Add("userid", "2100"); dynamic info = await Host.GetToDynamicAsync(2, endpoint, true, o); Assert.IsNotNull(info.User.Username); }
private string ProcessGetEndpoint(string endpoint, RestGetOptions options) { var processedEndpoint = endpoint; if (options.PathParameters.HasKeys()) processedEndpoint = ReplaceTokens(endpoint, options.PathParameters); if (options.QueryStringParameters.HasKeys()) processedEndpoint = BuildQueryString(processedEndpoint, options.QueryStringParameters); return processedEndpoint; }
public void can_do_get_paged_request_synchronously() { var options = new NameValueCollection(); options.Add("PageSize", "50"); options.Add("PageIndex", "0"); options.Add("SortBy", "LastPost"); options.Add("SortOrder", "Descending"); RestGetOptions o = new RestGetOptions(); o.QueryStringParameters = options; var endpoint = "forums.json"; var response = Host.GetToDynamic(2, endpoint, true, o); Assert.IsNotNull(response.Forums); Assert.AreEqual(50, response.PageSize); }
public void can_force_url_translation() { var options = new NameValueCollection(); options.Add("PageSize", "50"); options.Add("PageIndex", "0"); options.Add("SortBy", "LastPost"); options.Add("SortOrder", "Descending"); RestGetOptions o = new RestGetOptions(); o.QueryStringParameters = options; var endpoint = "forums.json"; o.AdditionalHeaders.Add("X-Remote-Redirect-Url","http://mysite.com/proxy.ashx/"); o.AdditionalHeaders.Add("X-Remote-UrlEncode-Redirects","False"); var response = Host.GetToDynamic(2, endpoint, true, o); }
public async Task<string> GetEndpointStringAsync(RestHost host, int version, string endpoint, bool enableImpersonation = true, RestGetOptions options = null) { if (options == null) options = new RestGetOptions(); var processedEndpoint = ProcessGetEndpoint(endpoint, options); var stream = await _proxy.GetAsync(host, MakeEndpointUrl(host, version, processedEndpoint), (request) => AdjustGetRequest(host, request, enableImpersonation, options)); return await ReadResponseStreamAsync(stream); }
public Stream GetEndpointStream(RestHost host, int version, string endpoint, bool enableImpersonation = true, RestGetOptions options = null) { if (options == null) options = new RestGetOptions(); var processedEndpoint = ProcessGetEndpoint(endpoint, options); return _proxy.Get(host, MakeEndpointUrl(host, version, processedEndpoint), (req) => AdjustGetRequest(host, req, enableImpersonation, options)); }
public XElement GetEndpointXml(RestHost host, int version, string endpoint, bool enableImpersonation = true, RestGetOptions options = null) { if (options == null) options = new RestGetOptions(); var processedEndpoint = ProcessGetEndpoint(endpoint, options); return XElement.Parse(ReadResponseStream(_proxy.Get(host, MakeEndpointUrl(host, version, processedEndpoint), (request) => AdjustGetRequest(host, request, enableImpersonation, options)))); }
private void AdjustGetRequest(RestHost host, HttpWebRequest request, bool enableImpersonation, RestGetOptions options) { AdjustRequestBase(host, request, enableImpersonation); if (options != null && options.AdditionalHeaders != null) SetAdditionalHeaders(request, options.AdditionalHeaders); }
/// <summary> /// REST GET Request (Async) /// </summary> /// <param name="version">The REST Api version</param> /// <param name="endpoint">The Url without aspi.ashx and ther version</param> /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param> /// <param name="options">Additional options for this request type.</param> /// <returns>Stream</returns> public Task<Stream> GetToStreamAsync(int version, string endpoint, bool enableImpersonation = true, RestGetOptions options = null) { return Rest.GetEndpointStreamAsync(this, version, endpoint, enableImpersonation, options); }
/// <summary> /// REST GET Request for JSON /// </summary> /// <param name="version">The REST Api version</param> /// <param name="endpoint">The Url without aspi.ashx and ther version</param> /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param> /// <param name="options">Additional options for this request type.</param> /// <returns>dynamic</returns> public dynamic GetToDynamic(int version, string endpoint, bool enableImpersonation = true, RestGetOptions options = null) { var json = Rest.GetEndpointString(this, version, endpoint,enableImpersonation, options); return json != null ? JsonConvert.Deserialize(json) : null; }
/// <summary> /// REST GET Request for Xml /// </summary> /// <param name="version">The REST Api version</param> /// <param name="endpoint">The Url without aspi.ashx and ther version</param> /// <param name="enableImpersonation">Use the locally authenticated user versus the default</param> /// <param name="options">Additional options for this request type.</param> /// <returns>XElement</returns> /// public XElement GetToXml(int version, string endpoint, bool enableImpersonation, RestGetOptions options = null) { return Rest.GetEndpointXml( this, version, endpoint, enableImpersonation, options); }