示例#1
0
        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);
            }
        }
示例#2
0
        public HttpResponse SendMessage <T>(T message)
            where T : PushMessage
        {
            var json = message.CreateJson();

            var cl  = this;
            var url = "https://graph.facebook.com/v4.0/me/messages?access_token=" + this.GetAccessToken();
            var cm  = new HttpRequestCommand(url);

            cm.MethodName  = HttpMethodName.Post;
            cm.ContentType = "application/json";
            cm.SetBodyStream(Encoding.UTF8.GetBytes(json));
            var res = cl.GetResponse(cm);

            return(res);
        }
        public HttpResponse SendReplyMessage <T>(T message)
            where T : ReplyMessage
        {
            var json = message.CreateJson();

            var cl  = this;
            var url = "https://api.line.me/v2/bot/message/reply";
            var cm  = new HttpRequestCommand(url);

            cm.Headers.Add("Authorization", "Bearer " + this.GetAccessToken());
            cm.MethodName  = HttpMethodName.Post;
            cm.ContentType = "application/json";
            cm.SetBodyStream(Encoding.UTF8.GetBytes(json));
            var res = cl.GetResponse(cm);

            return(res);
        }
示例#4
0
        protected override HttpRequestCommand CreateGetAccessTokenCommand(string code)
        {
            var url = "https://api.dailymotion.com/oauth/token";
            var cm  = new HttpRequestCommand(url);

            cm.MethodName = HttpMethodName.Post;
            var cv = new Base64Converter(256);

            cv.InsertNewline = false;
            var authValue = "basic " + cv.Encode(this.ClientID + ":" + this.ClientSecret, Encoding.UTF8);

            cm.Headers.Add("Authorization", authValue);
            var d = new Dictionary <String, String>();

            d["grant_type"]   = "authorization_code";
            d["code"]         = code;
            d["redirect_uri"] = this.RedirectUrl;
            var data = new HttpBodyFormUrlEncodedData(d);

            cm.SetBodyStream(data);

            return(cm);
        }
        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);
        }
 public HttpRequestHttpApiCommand(HttpRequestCommand <T> requestCommand)
 {
     this.requestCommand = requestCommand;
 }