/// <summary> /// Downloads and returns the response as a json string for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="postParameters">post parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public string Download(string action, NameValueCollection querystringParameters = null, NameValueCollection postParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { var data = DownloadData(action, querystringParameters, postParameters, isSecure, versionType); return(data != null?Encoding.UTF8.GetString(data) : null); }
/// <summary> /// Uploads json and returns the respon as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="json">Json to upload</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public string UploadJson(string action, string json, NameValueCollection querystringParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { var data = UploadJsonData(action, Encoding.UTF8.GetBytes(json), querystringParameters, isSecure, versionType); return(data != null?Encoding.UTF8.GetString(data) : null); }
private byte[] MakeRequest(string action, NameValueCollection querystringParameters, bool isSecure, ApiVersionType versionType, Func <string, WebClient, byte[]> actualRequest) { if (action == null) { throw new ArgumentNullException("action"); } byte[] data = null; WebClient client = null; try { string baseUrl; if (versionType == ApiVersionType.VersionOne) { baseUrl = isSecure ? SecureBaseUrlV1 : BaseUrlV1; } else { baseUrl = isSecure ? SecureBaseUrlV2 : BaseUrlV2; } var url = string.Concat(baseUrl, action); client = GetClient(); client.QueryString = querystringParameters ?? new NameValueCollection(); data = actualRequest(url, client); } catch (WebException webException) { if (Log.IsDebugEnabled) { Log.Debug(webException.Message, webException); } throw new ApiException(webException.Message); } finally { if (client != null) { ReleaseClient(client); } } return(data); }
/// <summary> /// Uploads json and returns the respon as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="jsonData">Json to upload</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public byte[] UploadJsonData(string action, byte[] jsonData, NameValueCollection querystringParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { return(MakeRequest(action, querystringParameters, isSecure, versionType, (url, client) => client.UploadData(url, "POST", jsonData))); }
/// <summary> /// Downloads and returns the response as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="postParameters">post parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>byte array response for the specified action</returns> public byte[] DownloadData(string action, NameValueCollection querystringParameters = null, NameValueCollection postParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { return(MakeRequest(action, querystringParameters, isSecure, versionType, (url, client) => postParameters != null ? client.UploadValues(url, postParameters) : client.DownloadData(url))); }
private byte[] MakeRequest(string action, NameValueCollection querystringParameters, bool isSecure, ApiVersionType versionType, Func<string, WebClient, byte[]> actualRequest) { if (action == null) throw new ArgumentNullException("action"); byte[] data = null; WebClient client = null; try { string baseUrl; if (versionType == ApiVersionType.VersionOne) { baseUrl = isSecure ? SecureBaseUrlV1 : BaseUrlV1; } else { baseUrl = isSecure ? SecureBaseUrlV2 : BaseUrlV2; } var url = string.Concat(baseUrl, action); client = GetClient(); client.QueryString = querystringParameters ?? new NameValueCollection(); data = actualRequest(url, client); } catch (WebException webException) { if (Log.IsDebugEnabled) Log.Debug(webException.Message, webException); throw new ApiException(webException.Message); } finally { if (client != null) ReleaseClient(client); } return data; }
/// <summary> /// Uploads json and returns the respon as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="jsonData">Json to upload</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public byte[] UploadJsonData(string action, byte[] jsonData, NameValueCollection querystringParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { return MakeRequest(action, querystringParameters, isSecure, versionType, (url, client) => client.UploadData(url, "POST", jsonData)); }
/// <summary> /// Uploads json and returns the respon as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="json">Json to upload</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public string UploadJson(string action, string json, NameValueCollection querystringParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { var data = UploadJsonData(action, Encoding.UTF8.GetBytes(json), querystringParameters, isSecure, versionType); return data != null ? Encoding.UTF8.GetString(data) : null; }
/// <summary> /// Downloads and returns the response as a byte array for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="postParameters">post parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>byte array response for the specified action</returns> public byte[] DownloadData(string action, NameValueCollection querystringParameters = null, NameValueCollection postParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { return MakeRequest(action, querystringParameters, isSecure, versionType, (url, client) => postParameters != null ? client.UploadValues(url, postParameters) : client.DownloadData(url)); }
/// <summary> /// Downloads and returns the response as a json string for the specified action and parameters /// </summary> /// <param name="action">Strava API action to download the response for</param> /// <param name="querystringParameters">querystring parameters for the specified action</param> /// <param name="postParameters">post parameters for the specified action</param> /// <param name="isSecure">Boolean indicating if the download should be over SSL</param> /// <returns>Json response for the specified action</returns> public string Download(string action, NameValueCollection querystringParameters = null, NameValueCollection postParameters = null, bool isSecure = false, ApiVersionType versionType = ApiVersionType.VersionOne) { var data = DownloadData(action, querystringParameters, postParameters, isSecure, versionType); return data != null ? Encoding.UTF8.GetString(data) : null; }