Exemplo n.º 1
0
        protected XmlDocument CallApi(string callString, Dictionary <string, string> values)
        {
            BotRAPI api = new BotRAPI(_botrApiKey, _botrApiSecret);
            string  returnString;

            if (values == null)
            {
                returnString = api.Call(callString);
            }
            else
            {
                System.Collections.Specialized.NameValueCollection nameValues = new System.Collections.Specialized.NameValueCollection();
                foreach (var value in values)
                {
                    nameValues.Add(value.Key, value.Value);
                }
                returnString = api.Call(callString, nameValues);
            }
            if (string.IsNullOrEmpty(returnString))
            {
                throw new Exception("Bits on the Run returned empty result. Check API key configuration.");
            }
            XmlDocument result = new XmlDocument();

            result.LoadXml(returnString);
            return(result);
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            try {
                IApplicationContext ctx = ContextRegistry.GetContext();
                BotRAPI             api = ctx.GetObject("BotRAPI") as BotRAPI;

                //test video listing
                Console.WriteLine(api.Call("/videos/list"));

                //params to store with a new video
                NameValueCollection col = new NameValueCollection()
                {
                    { "title", "New test video" },
                    { "tags", "new, test, video, upload" },
                    { "description", "New video2" },
                    { "link", "http://www.bitsontherun.com" },
                    { "author", "Bits on the Run" }
                };

                //create the new video
                string xml = api.Call("/videos/create", col);

                Console.WriteLine(xml);

                XDocument doc    = XDocument.Parse(xml);
                var       result = (from d in doc.Descendants("status")
                                    select new {
                    Status = d.Value
                }).FirstOrDefault();

                //make sure the status was "ok" before trying to upload
                if (result.Status.Equals("ok", StringComparison.CurrentCultureIgnoreCase))
                {
                    var    response = doc.Descendants("link").FirstOrDefault();
                    string url      = string.Format("{0}://{1}{2}", response.Element("protocol").Value, response.Element("address").Value, response.Element("path").Value);

                    string filePath = Path.Combine(Environment.CurrentDirectory, "test.mp4");

                    col = new NameValueCollection();
                    FileStream fs = new FileStream(filePath, FileMode.Open);

                    col["file_size"] = fs.Length.ToString();
                    col["file_md5"]  = BitConverter.ToString(HashAlgorithm.Create("MD5").ComputeHash(fs)).Replace("-", "").ToLower();
                    col["key"]       = response.Element("query").Element("key").Value;
                    col["token"]     = response.Element("query").Element("token").Value;

                    fs.Dispose();
                    string uploadResponse = api.Upload(url, col, filePath);

                    Console.WriteLine(uploadResponse);
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.GetBaseException().Message);
            }
        }