本文整理汇总了C#中RestSharp.RestRequest.AddUrlSegment方法的典型用法代码示例。如果您正苦于以下问题:C# RestRequest.AddUrlSegment方法的具体用法?C# RestRequest.AddUrlSegment怎么用?C# RestRequest.AddUrlSegment使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestRequest
的用法示例。
在下文中一共展示了RestRequest.AddUrlSegment方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SearchProduct
public List<MagicHelper_Bot.Models.Product> SearchProduct (IDictionary<string,string> searchParams)
{
var req = new RestRequest ("products/{name}/{idGame}/{idLanguage}/{isExact}", Method.GET);
foreach (var param in searchParams) {
if (param.Key.Equals ("subject")) {
req.AddUrlSegment ("name", param.Value);
}
}
req.AddUrlSegment ("idGame", MtgGameId.ToString ());
req.AddUrlSegment ("idLanguage", EnglishLanguageId.ToString ());
req.AddUrlSegment ("isExact", "false");
AddAuthorizationHeader (req);
var result = client.Execute<ProductQueryResult> (req);
if (result.StatusCode != System.Net.HttpStatusCode.OK) {
System.Console.WriteLine ("Mcm request failed: " + result.StatusCode + ": " + result.StatusDescription);
}
var casted = new List<MagicHelper_Bot.Models.Product> ();
foreach (Product product in result.Data.Products) {
casted.Add ((MagicHelper_Bot.Models.Product)product);
}
return casted;
}
示例2: GetAllChampions
/// <summary>
/// Returns a list of all Champions in the current Version
/// </summary>
/// <param name="region">Region of data</param>
public static List<Champion> GetAllChampions(string region)
{
var cacheName = "allChamps_" + region;
var cached = HttpContext.Current.Cache[cacheName] as List<Champion>;
if (cached != null)
return cached;
var client = ApiTools.GlobalApiClient();
var request = new RestRequest(UrlFormat, Method.GET);
request.AddUrlSegment("region", region);
request.AddUrlSegment("method", "champion");
request.AddParameter("dataById", true);
request.AddApiKey();
var response = client.Execute(request);
var response2 = client.Execute<dynamic>(request);
var champs = ParseAllChampsResponse(region, response.Content);
HttpContext.Current.Cache[cacheName] = champs;
return champs;
}
示例3: UploadFile
/// <summary>
/// Uploads a file, if the request fails this overload will delete the note record
/// </summary>
/// <param name="module">Notes</param>
/// <param name="id">Record ID</param>
/// <param name="filePath">Path to file on local disk</param>
/// <param name="deleteOnFailure">Bool: deletes record if upload fails</param>
/// <returns>Bool</returns>
public bool UploadFile(string module, string id, string filePath, bool deleteOnFailure)
{
var request = new RestRequest("{module}/{id}/file/filename", Method.POST);
request.AddUrlSegment("module", module);
request.AddUrlSegment("id", id);
request.AddParameter("format", "sugar-html-json");
request.AddParameter("delete_if_fails", deleteOnFailure);
if (deleteOnFailure)
{
request.AddParameter("oauth_token", Token);
}
if (!File.Exists(filePath))
{
//@todo create a SugarFileException class
throw new SugarException("Can not locate file path. Path attempted = " + filePath);
}
request.AddFile("filename", filePath);//?
FileUploadResponse response = Execute<FileUploadResponse>(request);
return ! string.IsNullOrEmpty(response.filename.name);
}
示例4: CreateLoadBalancer
/// <summary>
/// Adds a new load balancer to the IP
/// </summary>
/// <param name="server_id">Unique server's identifier.</param>
/// <param name="ip_id">Unique server's identifier.</param>
public ServerResponse CreateLoadBalancer(string server_id, string ip_id, string loadBalancerId)
{
try
{
var request = new RestRequest("/servers/{server_id}/ips/{ip_id}/load_balancers", Method.POST)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("server_id", server_id);
request.AddUrlSegment("ip_id", ip_id);
string load_balancer_id = loadBalancerId;
request.AddBody(new { load_balancer_id });
var result = restclient.Execute<ServerResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例5: DeleteFirewallPolicyRules
/// <summary>
/// Removes a rule from a firewall policy.
/// </summary>
/// <param name="firewall_id">Unique firewall's identifier.</param>
/// <param name="rule_id">Unique rule's identifier.</param>
///
public FirewallPolicyResponse DeleteFirewallPolicyRules(string firewall_id, string rule_id)
{
try
{
var request = new RestRequest("/firewall_policies/{firewall_id}/rules/{rule_id}", Method.DELETE)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("firewall_id", firewall_id);
request.AddUrlSegment("rule_id", rule_id);
request.AddHeader("Content-Type", "application/json");
var result = restclient.Execute<FirewallPolicyResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例6: DownloadZipball
public byte[] DownloadZipball(string owner, string repo, string branch)
{
RestClient _client = new RestClient
{
BaseUrl = "https://github.com",
Authenticator = client.Authenticator,
};
var request = new RestRequest
{
Resource = "/{owner}/{repo}/zipball/{branch}",
Method = Method.GET
};
request.AddUrlSegment("owner", owner);
request.AddUrlSegment("repo", repo);
request.AddUrlSegment("branch", branch);
var response =_client.Execute(request);
if (response.ContentLength != -1)
{
return response.RawBytes;
}
else {
return null;
}
}
示例7: LoadData
public void LoadData()
{
var client = new RestClient("http://api.nytimes.com");
client.ClearHandlers();
var request = new RestRequest("{a}/{b}/{c}/{d}/{e}/{f}");
request.AddUrlSegment("a", "svc");
request.AddUrlSegment("b", "mostpopular");
request.AddUrlSegment("c", "v2");
request.AddUrlSegment("d", "mostviewed");
request.AddUrlSegment("e", "all-sections");
request.AddUrlSegment("f", "1.json");
request.AddParameter("api-key", "536306de3cfe2283df9c091afea40e82:9:67546031");
request.RequestFormat = DataFormat.Json;
try
{
var asyncHandle = client.ExecuteAsync(request, response =>
{
if (response.ResponseStatus == ResponseStatus.Completed)
{
UpdateArticleList(response.Content);
MessageBox.Show(response.Content);
}
else
MessageBox.Show("Tidak dapat terhubung ke server");
});
}
catch {
MessageBox.Show("Eksekusi Gagal");
}
}
示例8: Delete
/// <summary>
/// Removes a process from a monitoring policy.
/// </summary>
/// <param name="process_id">Unique process's identifier.</param>
/// <param name="monitoring_policy_id">Unique monitoring policy's identifier.</param>
///
public MonitoringPoliciesResponse Delete(string monitoring_policy_id, string process_id)
{
try
{
var request = new RestRequest("/monitoring_policies/{monitoring_policy_id}/processes/{process_id}", Method.DELETE)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("monitoring_policy_id", monitoring_policy_id);
request.AddUrlSegment("process_id", process_id);
request.AddHeader("Content-Type", "application/json");
var result = restclient.Execute<MonitoringPoliciesResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例9: DeleteLoadBalancerRules
/// <summary>
/// Removes a rule from a load balancer.
/// </summary>
/// <param name="load_balancer_id">Unique load balancer's identifier..</param>
/// <param name="rule_id">Unique rule's identifier.</param>
///
public LoadBalancerResponse DeleteLoadBalancerRules(string load_balancer_id, string rule_id)
{
try
{
var request = new RestRequest("/load_balancers/{load_balancer_id}/rules/{rule_id}", Method.DELETE)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("load_balancer_id", load_balancer_id);
request.AddUrlSegment("rule_id", rule_id);
request.AddHeader("Content-Type", "application/json");
var result = restclient.Execute<LoadBalancerResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例10: DeleteSharedStoragesServer
/// <summary>
/// Unattaches a server from a shared storage.
/// </summary>
/// <param name="shared_storage_id">Unique shared storage's identifier.</param>
///
public SharedStoragesResponse DeleteSharedStoragesServer(string shared_storage_id, string server_id)
{
try
{
var request = new RestRequest("/shared_storages/{shared_storage_id}/servers/{server_id}", Method.DELETE)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("shared_storage_id", shared_storage_id);
request.AddUrlSegment("server_id", server_id);
request.AddHeader("Content-Type", "application/json");
var result = restclient.Execute<SharedStoragesResponse>(request);
if (result.StatusCode != HttpStatusCode.Accepted)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例11: DeleteUserIp
/// <summary>
/// Deletes an IP and forbides API access for it.
/// </summary>
/// <param name="user_id">Unique user's identifier.</param>
/// <param name="ip">Desired IP</param>
///
public UserResponse DeleteUserIp(string user_id, string ip)
{
try
{
var request = new RestRequest("/users/{user_id}/api/ips/{ip}", Method.DELETE)
{
RequestFormat = DataFormat.Json,
JsonSerializer = new CustomSerializer()
};
request.AddUrlSegment("user_id", user_id);
request.AddUrlSegment("ip", ip);
request.AddHeader("Content-Type", "application/json");
var result = restclient.Execute<UserResponse>(request);
if (result.StatusCode != HttpStatusCode.OK)
{
throw new Exception(result.Content);
}
return result.Data;
}
catch
{
throw;
}
}
示例12: GetMatches
public MinimizedMatchDtoContainer GetMatches(int? playerID = null, int? matchID = null, int? heroID = null, int? matchCount = null)
{
var client = new RestClient(Globals.DotaSteamAPI);
var request = new RestRequest(Globals.DotaSteamAPIDotaInterfarce + "GetMatchHistory/" + Globals.DotaSteamAPIWeb1 + "?key={raktas}&account_id={player_id}&matches_requested={match_count}&start_at_match_id={match_id}&hero_id={hero_id}", Method.GET);
request.AddUrlSegment("raktas", Globals.DotaAPIKey);
if (playerID != null)
{
request.AddUrlSegment("player_id", playerID.ToString());
}
if (matchID != null)
{
request.AddUrlSegment("match_id", matchID.ToString());
}
if (heroID != null)
{
request.AddUrlSegment("hero_id", heroID.ToString());
}
if (matchCount != null)
{
request.AddUrlSegment("match_count", matchCount.ToString());
}
var response = client.Execute(request);
var data = JsonConvert.DeserializeObject<MinimizedMatchDtoContainer>(response.Content);
return data;
}
示例13: CheckCredentials
public bool CheckCredentials(string email, string password)
{
var request = new RestRequest("api/User/CheckCredentials?email={email}&password={password}", Method.GET);
request.AddUrlSegment("email", email);
request.AddUrlSegment("password", password);
return client.Execute<bool>(request).Data;
}
示例14: PostLogFile
private void PostLogFile(string macAddress, Guid requestId, Guid logFileId, string fileName)
{
string path = GetFilePath(fileName);
if (!File.Exists(path))
{
Logger.Instance.Write("PostLogFile", LogLevel.Medium, "PostLog failed as the log file does not exist.");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, false));
return;
}
var request = new RestRequest("v1/signboards/{macAddress}/logFiles/{logFileId}/file", Method.POST);
request.RequestFormat = RestSharp.DataFormat.Json;
request.AddUrlSegment("macAddress", macAddress);
request.AddUrlSegment("logFileId", logFileId.ToString());
request.AddBody(DeviceLogModel.From(fileName));
request.AddFile("file", File.ReadAllBytes(path), Path.GetFileName(path), "multipart/form-data");
Client.ExecuteAsync<DeviceLogResponseModel>(request, (response) =>
{
if (response.StatusCode == System.Net.HttpStatusCode.OK)
{
Logger.Instance.Write("PostLogFile", LogLevel.Low, "Uploaded log file successfully.");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, true));
return;
}
else
{
Logger.Instance.Write("PostLog", LogLevel.Medium, "PostLog request failed. ");
RequestComponent.GetInstance().FinishRequest(macAddress, RequestInputModel.From(requestId, false));
return;
}
});
}
示例15: ClearElementText
/// <summary>
/// Clear a textarea or text imput element's value.
/// </summary>
/// <param name="sessionID">ID of the session to route the command to</param>
/// <param name="driverElementID">Driver element ID (is found by FindElement method)</param>
public static void ClearElementText(string sessionID, int driverElementID)
{
var client = new RestClient(ServerUrl);
var request = new RestRequest("wd/hub/session/{id}/element/{elementID}/clear", Method.POST);
request.AddUrlSegment("id", sessionID);
request.AddUrlSegment("elementID", driverElementID.ToString("0"));
client.Execute(request);
}