public TResult GetResult <T, TResult>(T command) where T : VimeoCommand { if (this.AccessToken == null) { throw new OAuthAuthenticateException("", "AccessToken does not set."); } OAuth2Client cl = this; Dictionary <String, String> d = new Dictionary <string, string>(); var url = "https://api.vimeo.com/" + command.GetApiEndpointUrl(); var methodName = command.GetHttpMethodName(); if (command != null) { d = command.Map(new Dictionary <String, String>()); var keys = d.Where(el => String.IsNullOrEmpty(el.Value)).Select(el => el.Key).ToList(); foreach (var key in keys) { d.Remove(key); } } d["access_token"] = this.AccessToken.Value; if (methodName == HttpMethodName.Get) { var cv = new QueryStringConverter(); url = String.Format("{0}?{1}", url, cv.Write(d)); } var cm = new HttpRequestCommand(url); cm.Accept = "application/vnd.vimeo.*+json;version=3.2"; cm.MethodName = methodName; if (methodName != HttpMethodName.Get) { cm.SetBodyStream(new HttpBodyFormUrlEncodedData(d)); } var res = cl.GetResponse(cm); if (res.StatusCode != HttpStatusCode.OK && res.StatusCode != HttpStatusCode.Created && res.StatusCode != HttpStatusCode.Accepted) { throw new HttpResponseException(res); } var json = res.BodyText; try { return(JsonConvert.DeserializeObject <TResult>(json, new JsonSerializerSettings() { MissingMemberHandling = MissingMemberHandling.Ignore })); } catch (JsonReaderException) { throw new HttpResponseException(res); } }
private String CallApi(VimeoApiEndpointInfo apiInfo, Dictionary <String, String> parameters) { var cl = new HttpClient(); var methodName = apiInfo.HttpMethodName.ToEnum <HttpMethodName>().Value; var qs = new QueryStringConverter(); var url = String.Format("https://api.vimeo.com/{0}?{1}", apiInfo.ApiPath, qs.Write(parameters)); foreach (var key in _IDParameterValues.Keys) { url = url.Replace("{" + key + "}", _IDParameterValues[key]); } var cm = new HttpRequestCommand(url); cm.MethodName = methodName; if (cm.MethodName != HttpMethodName.Get) { cm.SetBodyStream(new HttpBodyFormUrlEncodedData(parameters)); } var json = cl.GetBodyText(cm); return(json); }