本文整理汇总了C#中ApiResponse类的典型用法代码示例。如果您正苦于以下问题:C# ApiResponse类的具体用法?C# ApiResponse怎么用?C# ApiResponse使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ApiResponse类属于命名空间,在下文中一共展示了ApiResponse类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例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);
}
示例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;
}
示例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;
}
}
}
示例5: HasDefaultMessage
public void HasDefaultMessage()
{
var response = new ApiResponse<object> { StatusCode = HttpStatusCode.Forbidden };
var forbiddenException = new ForbiddenException(response);
Assert.Equal("Request Forbidden", forbiddenException.Message);
}
示例6: DeleteTrace
public ApiResponse<string> DeleteTrace(string id)
{
ApiTraceManager.Inst.DeleteTrace(id);
ApiResponse<string> res = new ApiResponse<string>();
res.Success = true;
return res;
}
示例7: DeleteError
public ApiResponse<string> DeleteError(string id)
{
ApiErrorManager.Inst.DeleteError(id);
ApiResponse<string> res = new ApiResponse<string>();
res.Success = true;
return res;
}
示例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;
}
示例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;
}
示例10: SignOut
public static ApiResponse SignOut(String appKey)
{
ApiResponse apiResponse = new ApiResponse();
apiResponse.status = "ok";
System.Web.Security.FormsAuthentication.SignOut();
return apiResponse;
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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"]);
}