• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# ApiResponse类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C#中ApiResponse的典型用法代码示例。如果您正苦于以下问题:C# ApiResponse类的具体用法?C# ApiResponse怎么用?C# ApiResponse使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



ApiResponse类属于命名空间,在下文中一共展示了ApiResponse类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。

示例1: CanPopulateObjectFromSerializedData

            public void CanPopulateObjectFromSerializedData()
            {
                var response = new ApiResponse<object> { StatusCode = HttpStatusCode.Forbidden };
                response.Headers.Add("X-RateLimit-Limit", "100");
                response.Headers.Add("X-RateLimit-Remaining", "42");
                response.Headers.Add("X-RateLimit-Reset", "1372700873");
                response.ApiInfo = CreateApiInfo(response);

                var exception = new RateLimitExceededException(response);

                using (var stream = new MemoryStream())
                {
                    var formatter = new BinaryFormatter();
                    formatter.Serialize(stream, exception);
                    stream.Position = 0;
                    var deserialized = (RateLimitExceededException)formatter.Deserialize(stream);

                    Assert.Equal(HttpStatusCode.Forbidden, deserialized.StatusCode);
                    Assert.Equal(100, deserialized.Limit);
                    Assert.Equal(42, deserialized.Remaining);
                    var expectedReset = DateTimeOffset.ParseExact(
                        "Mon 01 Jul 2013 5:47:53 PM -00:00",
                        "ddd dd MMM yyyy h:mm:ss tt zzz",
                        CultureInfo.InvariantCulture);
                    Assert.Equal(expectedReset, deserialized.Reset);
                }
            }
开发者ID:harunpehlivan,项目名称:octokit.net,代码行数:27,代码来源:RateLimitExceededExceptionTests.cs


示例2: RequestsCorrectUrlWithApiOptions

            public async Task RequestsCorrectUrlWithApiOptions()
            {
                var result = new List<EventInfo> { new EventInfo() };

                var connection = Substitute.For<IConnection>();
                var gitHubClient = new GitHubClient(connection);
                var client = new ObservableIssuesEventsClient(gitHubClient);
                
                var options = new ApiOptions
                {
                    StartPage = 1,
                    PageCount = 1,
                    PageSize = 1
                };

                IApiResponse<List<EventInfo>> response = new ApiResponse<List<EventInfo>>(
                    new Response
                    {
                        ApiInfo = new ApiInfo(new Dictionary<string, Uri>(), new List<string>(), new List<string>(), "etag", new RateLimit()),
                    }, result);
                gitHubClient.Connection.Get<List<EventInfo>>(Args.Uri, Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null)
                    .Returns(Task.FromResult(response));

                var eventInfos = await client.GetAllForIssue("fake", "repo", 42, options).ToList();

                connection.Received().Get<List<EventInfo>>(Arg.Is<Uri>(u => u.ToString() == "repos/fake/repo/issues/42/events"), Arg.Is<Dictionary<string, string>>(d => d.Count == 2), null);
                Assert.Equal(1, eventInfos.Count);
            }
开发者ID:jrusbatch,项目名称:octokit.net,代码行数:28,代码来源:ObservableIssuesEventsClientTests.cs


示例3: RetrieveOrCreateIndexAsync

        public static async Task<IApiResponse<Index>> RetrieveOrCreateIndexAsync()
        {
            var managementClient = GetIndexManagementClient();

            IApiResponse<Index> index = new ApiResponse<Index>();
            try
            {
                index = await managementClient.GetIndexAsync(Keys.ListingsServiceIndexName);
            }
            catch (Exception e)
            {
                Console.WriteLine("Index doesn't yet exist, create it");
            }

            if (index.Body == null)
            {
                var newIndex = new Index(Keys.ListingsServiceIndexName)
                   .WithStringField("Id", opt => opt.IsKey().IsRetrievable())
                   .WithStringField("Color", opt => opt.IsSearchable().IsSortable().IsFilterable().IsRetrievable())
                   .WithStringField("Package", opt => opt.IsSearchable().IsFilterable().IsRetrievable())
                   .WithStringField("Options", opt => opt.IsSearchable().IsFilterable().IsRetrievable())
                   .WithStringField("Type", opt => opt.IsSearchable().IsFilterable().IsRetrievable())
                   .WithStringField("Image", opt => opt.IsRetrievable());
                index = await managementClient.CreateIndexAsync(newIndex);

                if (!index.IsSuccess)
                {
                    Console.WriteLine("Error when making index");
                }
            }

            return index;
        }
开发者ID:asiemer,项目名称:AzureAustin-20140917,代码行数:33,代码来源:SearchOperations.cs


示例4: ParseResponse

		private void ParseResponse(ref ApiResponse apiResponse, string respString)
		{
			try
			{
				JObject jObj = JObject.Parse(respString);

				apiResponse.ResponseObject = jObj;
			}
			catch (Exception ex)
			{
				// Parse failed.
				apiResponse.ResponseObject = null;
				apiResponse.Status = ApiResponse.ResponseStatus.ApiError;
				apiResponse.StatusText = ex.Message;
			}

			if (apiResponse.ResponseObject != null)
			{
				try
				{
					int apiStatus = apiResponse.ResponseObject["status"].ToObject<int>();
					apiResponse.ApiStatusCode = apiStatus;
					if (apiStatus != StatusOk && apiStatus < StatusCustomBase)
					{
						apiResponse.Status = ApiResponse.ResponseStatus.ApiError;
						apiResponse.StatusText = apiResponse.ResponseObject["error"].ToObject<string>();
					}
				}
				catch (Exception ex)
				{
					apiResponse.Status = ApiResponse.ResponseStatus.ApiError;
					apiResponse.StatusText = ex.Message;                    
				}
			}            
		}
开发者ID:pavlob0910,项目名称:my-start-stable,代码行数:35,代码来源:APIRequest.cs


示例5: HasDefaultMessage

            public void HasDefaultMessage()
            {
                var response = new ApiResponse<object> { StatusCode = HttpStatusCode.Forbidden };
                var forbiddenException = new ForbiddenException(response);

                Assert.Equal("Request Forbidden", forbiddenException.Message);
            }
开发者ID:KimCM,项目名称:octokit.net,代码行数:7,代码来源:ForbiddenExceptionTests.cs


示例6: DeleteTrace

 public ApiResponse<string> DeleteTrace(string id)
 {
     ApiTraceManager.Inst.DeleteTrace(id);
     ApiResponse<string> res = new ApiResponse<string>();
     res.Success = true;
     return res;
 }
开发者ID:mgerasika,项目名称:gam-gam,代码行数:7,代码来源:TraceApiController.cs


示例7: DeleteError

 public ApiResponse<string> DeleteError(string id)
 {
     ApiErrorManager.Inst.DeleteError(id);
     ApiResponse<string> res = new ApiResponse<string>();
     res.Success = true;
     return res;
 }
开发者ID:mgerasika,项目名称:gam-gam,代码行数:7,代码来源:ErrorApiController.cs


示例8: GetAction

        // List or Find Single
        public override string GetAction(string parameters, System.Collections.Specialized.NameValueCollection querystring)
        {
            string data = string.Empty;


            // Find One Specific Category
            ApiResponse<CategoryProductAssociationDTO> response = new ApiResponse<CategoryProductAssociationDTO>();
            string ids = FirstParameter(parameters);
            long id = 0;
            long.TryParse(ids, out id);

            var item = MTApp.CatalogServices.CategoriesXProducts.Find(id);
            if (item == null)
            {
                response.Errors.Add(new ApiError("NULL", "Could not locate that item. Check bvin and try again."));
            }
            else
            {
                response.Content = item.ToDto();
            }
            data = MerchantTribe.Web.Json.ObjectToJson(response);


            return data;
        }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:26,代码来源:CategoryProductAssociationsHandler.cs


示例9: GetItems

 public ApiResponse<List<FootballItem>> GetItems() {
     List<FootballItem> items = FootballManager.Inst.GetItems();
     ApiResponse<List<FootballItem>> res = new ApiResponse<List<FootballItem>>();
     res.Success = true;
     res.Model = items;
     return res;
 }
开发者ID:mgerasika,项目名称:football-site-parser,代码行数:7,代码来源:FootballController.cs


示例10: SignOut

 public static ApiResponse SignOut(String appKey)
 {
     ApiResponse apiResponse = new ApiResponse();
     apiResponse.status = "ok";
     System.Web.Security.FormsAuthentication.SignOut();
     return apiResponse;
 }
开发者ID:oyvindkinsey,项目名称:JsApiToolkit,代码行数:7,代码来源:Api.aspx.cs


示例11: ReturnsReadmeWithRepositoryId

            public async Task ReturnsReadmeWithRepositoryId()
            {
                string encodedContent = Convert.ToBase64String(Encoding.UTF8.GetBytes("Hello world"));
                var readmeInfo = new ReadmeResponse(
                    encodedContent,
                    "README.md",
                    "https://github.example.com/readme",
                    "https://github.example.com/readme.md",
                    "base64");

                var gitHubClient = Substitute.For<IGitHubClient>();
                var apiConnection = Substitute.For<IApiConnection>();
                apiConnection.GetHtml(new Uri(readmeInfo.Url)).Returns(Task.FromResult("<html>README</html>"));
                var readmeFake = new Readme(readmeInfo, apiConnection);
                var contentsClient = new ObservableRepositoryContentsClient(gitHubClient);

                gitHubClient.Repository.Content.GetReadme(1).Returns(Task.FromResult(readmeFake));

                IApiResponse<string> apiResponse = new ApiResponse<string>(new Response(), "<html>README</html>");
                gitHubClient.Connection.GetHtml(Args.Uri, null)
                    .Returns(Task.FromResult(apiResponse));

                var readme = await contentsClient.GetReadme(1);

                Assert.Equal("README.md", readme.Name);

                gitHubClient.Repository.Content.Received(1).GetReadme(1);
                gitHubClient.Connection.DidNotReceive().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme"),
                    Args.EmptyDictionary);

                var htmlReadme = await readme.GetHtmlContent();
                Assert.Equal("<html>README</html>", htmlReadme);
                apiConnection.Received().GetHtml(Arg.Is<Uri>(u => u.ToString() == "https://github.example.com/readme.md"), null);
            }
开发者ID:RadicalLove,项目名称:octokit.net,代码行数:34,代码来源:ObservableRepositoryContentsClientTests.cs


示例12: CallCompleted

        public void CallCompleted(ApiResponse result)
        {
            RadioGroup radioGrupo = new RadioGroup();
            List<GetSurveyQuestionsResponse> response = result.GetTypedResponse<List<GetSurveyQuestionsResponse>>();

            foreach (GetSurveyQuestionsResponse item in response)
            {

                radioGrupo = new RadioGroup();
                radioGrupo.Text(item.des);
                radioGrupo.IdPregunta = item.qid;
                foreach (var itemAnswers in item.answers)
                {
                    RadioButton radio = new RadioButton();
                    radio.Style = App.Current.Resources["RadioBridgstone"] as Style; ;
                    radio.Content = itemAnswers.des;
                    radio.Name = itemAnswers.aid.ToString();
                    radio.Margin = new Thickness(10, 0, 0, 0);
                    radio.Foreground = new SolidColorBrush(Color.FromArgb(0xFF, 0x47, 0x44, 0x44));
                    radio.BorderBrush = new SolidColorBrush(Color.FromArgb(0xFF, 0x8C, 0x8A, 0x8B));
                    radioGrupo.addChildren(radio);
                }
                stackBody.Children.Add(radioGrupo);
            }
        }
开发者ID:amasolini,项目名称:brid-wp,代码行数:25,代码来源:Encuesta.xaml.cs


示例13: PostAction

 // Create or Update
 public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
 {
     string data = string.Empty;
     string objecttype = FirstParameter(parameters);
     string objectid = GetParameterByIndex(1, parameters);
     ApiResponse<bool> response = new ApiResponse<bool>();
     
     try
     {
         if (objecttype.Trim().ToLowerInvariant() == "products")
         {
             SearchManager m = new SearchManager();
             Product p = MTApp.CatalogServices.Products.Find(objectid);
             if (p != null)
             {
                 if (p.Bvin.Length > 0)
                 {
                     m.IndexSingleProduct(p);
                     response.Content = true;
                 }
             }                    
         }                                
     }
     catch(Exception ex)
     {
         response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
         return MerchantTribe.Web.Json.ObjectToJson(response);                
     }
                 
     data = MerchantTribe.Web.Json.ObjectToJson(response);            
     return data;
 }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:33,代码来源:SearchManagerHandler.cs


示例14: DeleteAction

        public override string DeleteAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);

            if (bvin == string.Empty)
            {
                string howManyString = querystring["howmany"];
                int howMany = 0;
                int.TryParse(howManyString, out howMany);

                // Clear All Products Requested
                ApiResponse<ClearProductsData> response = new ApiResponse<ClearProductsData>();
                response.Content = MTApp.ClearProducts(howMany);
                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }
            else
            {
                // Single Item Delete
                ApiResponse<bool> response = new ApiResponse<bool>();
                response.Content = MTApp.DestroyProduct(bvin);
                data = MerchantTribe.Web.Json.ObjectToJson(response);
            }

            return data;
        }
开发者ID:NightOwl888,项目名称:MerchantTribe,代码行数:26,代码来源:ProductsHandler.cs


示例15: ParsesLinkHeader

            public void ParsesLinkHeader()
            {
                var response = new ApiResponse<string>
                {
                    Headers =
                    {
                        {
                            "Link",
                            "<https://api.github.com/repos/rails/rails/issues?page=4&per_page=5>; rel=\"next\", " +
                            "<https://api.github.com/repos/rails/rails/issues?page=131&per_page=5>; rel=\"last\", " +
                            "<https://api.github.com/repos/rails/rails/issues?page=1&per_page=5>; rel=\"first\", " +
                            "<https://api.github.com/repos/rails/rails/issues?page=2&per_page=5>; rel=\"prev\""
                        }
                    }
                };

                ApiInfoParser.ParseApiHttpHeaders(response);

                var apiInfo = response.ApiInfo;
                Assert.NotNull(apiInfo);
                Assert.Equal(4, apiInfo.Links.Count);
                Assert.Contains("next", apiInfo.Links.Keys);
                Assert.Equal(new Uri("https://api.github.com/repos/rails/rails/issues?page=4&per_page=5"),
                    apiInfo.Links["next"]);
                Assert.Contains("prev", apiInfo.Links.Keys);
                Assert.Equal(new Uri("https://api.github.com/repos/rails/rails/issues?page=2&per_page=5"),
                    apiInfo.Links["prev"]);
                Assert.Contains("first", apiInfo.Links.Keys);
                Assert.Equal(new Uri("https://api.github.com/repos/rails/rails/issues?page=1&per_page=5"),
                    apiInfo.Links["first"]);
                Assert.Contains("last", apiInfo.Links.Keys);
                Assert.Equal(new Uri("https://api.github.com/repos/rails/rails/issues?page=131&per_page=5"),
                    apiInfo.Links["last"]);
            }
开发者ID:harunpehlivan,项目名称:octokit.net,代码行数:34,代码来源:ApiInfoParserTests.cs


示例16: GetAction

 // List or Find Single
 public override string GetAction(string parameters, System.Collections.Specialized.NameValueCollection querystring)
 {            
     string data = string.Empty;                        
     ApiResponse<string> response = new ApiResponse<string>();                        
     data = MerchantTribe.Web.Json.ObjectToJson(response);
     return data;
 }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:8,代码来源:UtilitiesHandler.cs


示例17: GetItems

        public ApiResponse<List<FootballItem>> GetItems() {
            ApiResponse<List<FootballItem>> res = new ApiResponse<List<FootballItem>>();
            res.Success = false;
            List<FootballItem> items = new List<FootballItem>();
            HttpWebRequest request = WebRequest.CreateHttp(c_sServerUrl);
            request.Method = "get";
            request.Accept = "application/json";
            request.Timeout = 60*30*1000;
            try {
                WebResponse webResponse = request.GetResponse();
                Stream requestStream = webResponse.GetResponseStream();
                string json;
                using (StreamReader sr = new StreamReader(requestStream)) {
                    json = sr.ReadToEnd();
                }
                if (!string.IsNullOrEmpty(json)) {
                    JsonSerializer serializer = new JsonSerializer();
                    items = serializer.Deserialize<List<FootballItem>>(new JsonTextReader(new StringReader(json)));
                }
                res.Success = true;
                res.Model = items;
            }
            catch (Exception ex) {
            }


            return res;
        }
开发者ID:mgerasika,项目名称:football-site-parser,代码行数:28,代码来源:FootballService.cs


示例18: DeleteAction

 public override string DeleteAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
 {
     string data = string.Empty;
     ApiResponse<bool> response = new ApiResponse<bool>();
     response.Content = false;            
     data = MerchantTribe.Web.Json.ObjectToJson(response);
     return data;
 }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:8,代码来源:UtilitiesHandler.cs


示例19: PostAction

        // Create or Update
        public override string PostAction(string parameters, System.Collections.Specialized.NameValueCollection querystring, string postdata)
        {
            string data = string.Empty;
            string bvin = FirstParameter(parameters);
            
            //
            // <site Url>/producttypes/<guid>/properties/<propertyid>/<sortOrder>
            //
            string isProperty = GetParameterByIndex(1, parameters);
            if (isProperty.Trim().ToLowerInvariant() == "properties")
            {
                ApiResponse<bool> response2 = new ApiResponse<bool>();

                string propertyIds = GetParameterByIndex(2, parameters);
                long propertyId = 0;
                long.TryParse(propertyIds, out propertyId);                              

                response2.Content = MTApp.CatalogServices.ProductTypeAddProperty(bvin, propertyId);
                data = MerchantTribe.Web.Json.ObjectToJson(response2);            
            }
            else
            {
                ApiResponse<ProductTypeDTO> response = new ApiResponse<ProductTypeDTO>();
                ProductTypeDTO postedItem = null;
                try
                {
                    postedItem = MerchantTribe.Web.Json.ObjectFromJson<ProductTypeDTO>(postdata);
                }
                catch (Exception ex)
                {
                    response.Errors.Add(new ApiError("EXCEPTION", ex.Message));
                    return MerchantTribe.Web.Json.ObjectToJson(response);
                }

                ProductType item = new ProductType();
                item.FromDto(postedItem);

                if (bvin == string.Empty)
                {
                    if (MTApp.CatalogServices.ProductTypes.Create(item))
                    {
                        bvin = item.Bvin;
                    }
                }
                else
                {
                    MTApp.CatalogServices.ProductTypes.Update(item);
                }
                ProductType resultItem = MTApp.CatalogServices.ProductTypes.Find(bvin);
                if (resultItem != null) response.Content = resultItem.ToDto();
                data = MerchantTribe.Web.Json.ObjectToJson(response);            
            }


            
            return data;
        }
开发者ID:appliedi,项目名称:MerchantTribe,代码行数:58,代码来源:ProductTypesHandler.cs


示例20: IsEnabled

        public virtual ApiResponse<bool> IsEnabled()
        {
            var response = new ApiResponse<bool>
                {
                    Result = true
                };

            return response.Success();
        }
开发者ID:john123951,项目名称:sweetfly.net,代码行数:9,代码来源:BaseApiController.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Aplus类代码示例发布时间:2022-05-24
下一篇:
C# ApiOptions类代码示例发布时间:2022-05-24
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap