当前位置: 首页>>代码示例>>C#>>正文


C# IResponse.Http方法代码示例

本文整理汇总了C#中IResponse.Http方法的典型用法代码示例。如果您正苦于以下问题:C# IResponse.Http方法的具体用法?C# IResponse.Http怎么用?C# IResponse.Http使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IResponse的用法示例。


在下文中一共展示了IResponse.Http方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: ImageMe

        private async Task ImageMe(IResponse<TextMessage> msg, string query, Action<string> cb, bool animated = false, bool faces = false )
        {
            var res = await msg.Http("http://ajax.googleapis.com/ajax/services/search/images")
                .Query(new
                {
                    v = "1.0",
                    rsz = "8",
                    q = query,
                    safe = "active",
                    imgtype = faces ? "face" : animated ? "animated" : null
                })
                .GetJson();

            dynamic images = res;
            try
            {
                images = images.responseData.results;
                if (images.Count > 0)
                {
                    var image = msg.Random(images);
                    cb(string.Format("{0}#.png", image.unescapedUrl));
                }
            }
            catch (Exception)
            {
            }
        }
开发者ID:holytshirt,项目名称:mmbot,代码行数:27,代码来源:GoogleImages.cs

示例2: FetchComic

        private static async Task FetchComic(IResponse<TextMessage> msg, string num)
        {
            var res = await msg.Http(string.Format("http://xkcd.com/{0}/info.0.json", num)).Get();
            if (res.StatusCode == HttpStatusCode.NotFound)
            {
                await msg.Send(string.Format("Comic {0} not found", num));
                return;
            }

            var body = await res.Json();
            await msg.Send((string) body.title, (string) body.img, (string) body.alt);
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:12,代码来源:Xkcd.cs

示例3: AsciiMeCore

 private static async Task AsciiMeCore(IResponse<TextMessage> msg, string query)
 {
     var res = await msg.Http(String.Format(Url, query))
         .Get();
     
     try
     {
         res.Content.ReadAsStringAsync().ContinueWith(async readTask =>
         {
             await msg.Send(readTask.Result);
         });
     }
     catch (Exception)
     {
         msg.Send("erm....issues, move along");
     }
 }
开发者ID:nardin,项目名称:mmbot,代码行数:17,代码来源:Ascii.cs

示例4: CatMeGifCore

        private static async Task CatMeGifCore(IResponse<TextMessage> msg, int number)
        {
            var xDoc = await msg.Http(string.Format(Url, number)).GetXml();

            try
            {
                var urls = xDoc.SelectNodes("//url");
                foreach (XmlNode url in urls)
                {
                    msg.Send(url.InnerText);
                }
            }
            catch (Exception)
            {
                msg.Send("erm....issues, move along");
            }
        }
开发者ID:holytshirt,项目名称:mmbot,代码行数:17,代码来源:Cats.cs

示例5: GifMeCore

        private static async Task GifMeCore(IResponse<TextMessage> msg, string query, string apiKey)
        {
            var res = await msg.Http(_baseUri + "/gifs/search")
                .Query(new
                {
                    q = query,
                    api_key = apiKey
                })
                .GetJson();

            try
            {
                var images = res.data;
                if (images.Count > 0)
                {
                    dynamic image = msg.Random(images);
                    await msg.Send((string)image.images.original.url);
                }
            }
            catch (Exception)
            {
                msg.Send("erm....issues, move along");
            }
        }
开发者ID:dcr25568,项目名称:mmbot,代码行数:24,代码来源:Giphy.cs

示例6: MapBuildToNameList

 private void MapBuildToNameList(IResponse<TextMessage> msg, JToken build)
 {
     var id = (string)build["buildTypeId"];
     var url = string.Format("{0}/httpAuth/app/rest/buildTypes/id:{1}", _baseUrl, id);
     msg.Http(url)
         .Headers(GetHeaders())
         .GetJson((err, res, body) =>
         {
             if (err != null || res.StatusCode != HttpStatusCode.OK)
             {
                 return;
             }
             var buildName = body["name"].ToString();
             var baseMessage = string.Format("#{0} of {1} {2}", build["number"].ToString(), buildName,
                 build["webUrl"].ToString());
             string message;
             if (build["running"] != null && build["running"].Value<bool>())
             {
                 message = string.Format("{0} {1}% Complete :: {2}",
                     build["status"].Value<string>() == "SUCCESS" ? "***Winning***" : "__FAILING__",
                     build["percentageComplete"].Value<int>(), baseMessage);
             }
             else
             {
                 message = string.Format("{0} :: {1}",
                     build["status"].Value<string>() == "SUCCESS" ? "OK!" : "__FAILED__", baseMessage);
             }
             msg.Send(message);
         });
 }
开发者ID:holytshirt,项目名称:mmbot,代码行数:30,代码来源:TeamCity.cs

示例7: MapAndKillBuilds

 private void MapAndKillBuilds(Robot robot, IResponse<TextMessage> msg, string name, string id, string project)
 {
     var comment = string.Format("killed by {0}", robot.Alias);
     GetCurrentBuilds(robot, msg, null, (exception, res, body) =>
     {
         if (body["count"].Value<int>() == 0)
         {
             msg.Send("No builds are currently running");
             return;
         }
         MapNameToIdForBuildType(robot, msg, name, project, (response, buildType) =>
         {
             foreach (var build in body["build"])
             {
                 int parsedId;
                 if (name == "all" ||
                     (!string.IsNullOrWhiteSpace(id) && int.TryParse(id, out parsedId) &&
                      build["id"].Value<int>() == parsedId) ||
                     (buildType != null && string.IsNullOrWhiteSpace(id) &&
                      build["buildTypeId"].Value<string>() == buildType.Value<string>()))
                 {
                     msg.Http(string.Format("{0}/ajax.html?comment={1}&submit=Stop&buildId={2}&kill", _baseUrl,
                         comment, build["id"]))
                         .Get((err, res1) =>
                         {
                             if (err != null || res1.StatusCode != HttpStatusCode.OK)
                             {
                                 msg.Send("Fail! Something went wrong. Cou;dn't stop the build for some reason");
                             }
                             else
                             {
                                 msg.Send("The requested builds have been killed");
                             }
                         });
                 }
             }
         });
     });
 }
开发者ID:holytshirt,项目名称:mmbot,代码行数:39,代码来源:TeamCity.cs

示例8: InvokeApiCallWithCallback

 private void InvokeApiCallWithCallback(IResponse<TextMessage> msg, Action<Exception, HttpResponseMessage, JObject> callback, string url, object query = null)
 {
     msg.Http(url).Headers(GetHeaders())
         .Query(query)
         .GetJson((err, res, body) =>
         {
             if (err == null && res.StatusCode != HttpStatusCode.OK)
             {
                 err = new Exception(res.Content.ReadAsStringAsync().Result);
             }
             callback(err, res, body);
         });
 }
开发者ID:holytshirt,项目名称:mmbot,代码行数:13,代码来源:TeamCity.cs


注:本文中的IResponse.Http方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。