本文整理汇总了C#中RestSharp.RestClient.AddDefaultParameter方法的典型用法代码示例。如果您正苦于以下问题:C# RestClient.AddDefaultParameter方法的具体用法?C# RestClient.AddDefaultParameter怎么用?C# RestClient.AddDefaultParameter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RestSharp.RestClient
的用法示例。
在下文中一共展示了RestClient.AddDefaultParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GoodreadsClient
/// <summary>
/// Initializes a new instance of the <see cref="GoodreadsClient"/> class.
/// Use this constructor if you already have OAuth permissions for the user.
/// </summary>
/// <param name="apiKey">Your Goodreads API key.</param>
/// <param name="apiSecret">Your Goodreads API secret.</param>
/// <param name="accessToken">The user's OAuth access token.</param>
/// <param name="accessSecret">The user's OAuth access secret.</param>
public GoodreadsClient(string apiKey, string apiSecret, string accessToken, string accessSecret)
{
var client = new RestClient(new Uri(GoodreadsUrl))
{
UserAgent = "goodreads-dotnet"
};
client.AddDefaultParameter("key", apiKey, ParameterType.QueryString);
client.AddDefaultParameter("format", "xml", ParameterType.QueryString);
var apiCredentials = new ApiCredentials(client, apiKey, apiSecret, accessToken, accessSecret);
// Setup the OAuth authenticator if they have passed on the appropriate tokens
if (!string.IsNullOrWhiteSpace(accessToken) &&
!string.IsNullOrWhiteSpace(accessSecret))
{
client.Authenticator = OAuth1Authenticator.ForProtectedResource(
apiKey, apiSecret, accessToken, accessSecret);
}
Connection = new Connection(client, apiCredentials);
Authors = new AuthorsClient(Connection);
Books = new BooksClient(Connection);
Shelves = new ShelvesClient(Connection);
Users = new UsersClient(Connection);
Reviews = new ReviewsClient(Connection);
Series = new SeriesClient(Connection);
}
示例2: RestartSabnzbd
public void RestartSabnzbd()
{
var sabnzbdClient = new RestClient(SABNZBD_URI);
sabnzbdClient.AddDefaultParameter("apikey", SABNZBD_APIKEY);
sabnzbdClient.AddDefaultParameter("output", "json");
var restartRequest = new RestRequest();
restartRequest.AddParameter("cmd", "restart");
sabnzbdClient.ExecuteAsync(restartRequest, X => { });
}
示例3: CreateComicVineClient
public static RestClient CreateComicVineClient(string ComicVineApiKey)
{
RestClient _Client = new RestClient(COMICVINE_API_URL);
_Client.AddDefaultParameter(new Parameter() { Name = "api_key", Type = ParameterType.QueryString, Value = ComicVineApiKey });
return _Client;
}
示例4: BussBuddy
private BussBuddy()
{
context = new BussDbContext("Data Source=isostore:/Data.sdf");
if (!context.DatabaseExists())
context.CreateDatabase();
client = new RestClient("http://api.busbuddy.norrs.no:8080/api/1.2/");
client.AddDefaultParameter("apiKey", "HwSJ6xL9wCUnpegC");
}
示例5: TMDbClient
public TMDbClient(string apiKey)
{
this.apiKey = apiKey;
client = new RestClient(BaseUrl);
client.AddDefaultParameter("api_key", apiKey, ParameterType.QueryString);
client.ClearHandlers();
client.AddHandler("application/json", new JsonDeserializer());
}
示例6: GetClient
/// <summary>
/// Returns a client object with the default values, virtual for testability
/// </summary>
/// <param name="url">The API endpoint you are hitting</param>
/// <returns></returns>
protected virtual IRestClient GetClient(string url) {
IRestClient client = new RestClient(){
Timeout = this.Timeout,
BaseUrl = String.Format("https://{0}.pagerduty.com/api{1}",Subdomain,url)
};
client.AddDefaultParameter(new Parameter {
Name = "Authorization",
Value = String.Format("Token token={0}", this.AccessToken),
Type = ParameterType.HttpHeader });
return client;
}
示例7: TestInit
public void TestInit()
{
var restClient = new RestClient("http://api.themoviedb.org/3");
restClient.AddDefaultHeader("Accept", "application/json");
restClient.AddDefaultParameter("api_key", "cd684dd007b56d859be21f1a4902b2b6");
//restClient.Proxy = new WebProxy("localhost", 8888);
var serializer = new JsonSerializer
{
MissingMemberHandling = MissingMemberHandling.Ignore,
NullValueHandling = NullValueHandling.Ignore,
DefaultValueHandling = DefaultValueHandling.Include
};
restClient.AddHandler("application/json", new NewtonsoftJsonDeserializer(serializer));
_searchService = new TmdbDegreeRepository(restClient);
}
示例8: StripeClient
public StripeClient(string apiKey, string apiVersion, string apiEndpoint)
{
ApiVersion = "v1";
ApiEndpoint = "https://api.stripe.com/";
ApiKey = apiKey;
// silverlight friendly way to get current version
var assembly = Assembly.GetExecutingAssembly();
AssemblyName assemblyName = new AssemblyName(assembly.FullName);
var version = assemblyName.Version;
_client = new RestClient();
_client.UserAgent = "stripe-dotnet/" + version;
_client.Authenticator = new StripeAuthenticator(apiKey);
_client.BaseUrl = new Uri(String.Format("{0}{1}", string.IsNullOrWhiteSpace(apiEndpoint) ? ApiEndpoint : apiEndpoint, ApiVersion));
if (apiVersion.HasValue())
_client.AddDefaultParameter("Stripe-Version", apiVersion, ParameterType.HttpHeader);
}
示例9: Get
public HttpResponseMessage Get()
{
var client = new RestClient() { Timeout = 10000, BaseUrl = new System.Uri("https://<subdomain>.pagerduty.com/api/") };
client.AddDefaultParameter(new Parameter { Name = "Authorization", Value = "Token token=<token>", Type = ParameterType.HttpHeader });
var onCallRequest = new RestRequest("v1/escalation_policies/on_call", Method.GET);
IRestResponse onCallResponse = client.Execute(onCallRequest);
var content = onCallResponse.Content;
dynamic pagerDutyOnCall = JsonConvert.DeserializeObject(content);
dynamic user = pagerDutyOnCall.escalation_policies[0].escalation_rules[0].rule_object;
User userObject = new Models.User();
userObject.id = user.id;
userObject.name = user.name;
userObject.email = user.email;
var userRequest = new RestRequest("v1/users/" + userObject.id + "/contact_methods", Method.GET);
IRestResponse userResponse = client.Execute(userRequest);
var userDetails = userResponse.Content;
dynamic userMobile = JsonConvert.DeserializeObject(userDetails);
var contactCounts = userMobile.contact_methods.Count;
for(int i = 0; i < contactCounts; i++)
{
if(userMobile.contact_methods[i].type == "phone")
{
userObject.mobile = "+" + userMobile.contact_methods[i].country_code + userMobile.contact_methods[i].address;
}
}
var twilioResponse = new TwilioResponse();
twilioResponse.Say("Welcome to the Support Centre. Please wait while we route your call.");
twilioResponse.Dial(userObject.mobile);
return this.Request.CreateResponse(HttpStatusCode.OK, twilioResponse.Element, new XmlMediaTypeFormatter());
}
示例10: BusBuddy
public BusBuddy()
{
_restClient = new RestClient("http://api.busbuddy.norrs.no:8080/api/1.2/");
_restClient.AddDefaultParameter("apiKey", "HwSJ6xL9wCUnpegC");
}
示例11: FoursquareService
public FoursquareService()
{
_fourSquareClient = new RestClient("https://api.foursquare.com");
_fourSquareClient.Authenticator = this;
_fourSquareClient.AddDefaultParameter("v","20121006",ParameterType.GetOrPost);
}
示例12: RetryFailedEpisodes
public void RetryFailedEpisodes()
{
RetryData.Load();
var sabnzbdClient = new RestClient(SABNZBD_URI);
sabnzbdClient.AddDefaultParameter("apikey", SABNZBD_APIKEY);
sabnzbdClient.AddDefaultParameter("output", "json");
var sickbeardClient = new RestClient(SICKBEARD_URI);
// Get SABnzbd history.
var historyRequest = new RestRequest();
historyRequest.AddParameter("mode", "history");
historyRequest.AddParameter("start", 0);
historyRequest.AddParameter("limit", SABNZBD_HISTORY_LIMIT);
var history = sabnzbdClient.Execute<HistoryRequest>(historyRequest);
if (history.Data == null)
{
Console.WriteLine("FAILED: SABnzbd history request failed.");
return;
}
// Filter for failed items.
var failedRaw = history.Data.history.slots
.Where(X => X.status == "Failed" && X.category == "tv");
var failed = new List<TVEpisode>();
// Parse failed items.
foreach (var slot in failedRaw)
{
var episode = TVEpisode.FromFileName(slot.name, slot.nzo_id);
if (episode == null)
continue;
failed.Add(episode);
}
// Get SickBeard shows.
var showsRequest = new RestRequest();
showsRequest.AddParameter("cmd", "shows");
var showsRaw = sickbeardClient.Execute<ShowsRequest>(showsRequest);
if (showsRaw == null || showsRaw.Data == null || showsRaw.Data.data == null)
{
Console.WriteLine("FAILED: SickBeard shows request failed.");
return;
}
var shows = showsRaw.Data.data;
// Find failed items in SickBeard.
foreach (var failedItem in failed)
{
if (RetryData.ExceedsLimit(5, failedItem.OriginalFileName))
{
Console.WriteLine("FAILED: Exceeded retry limit of 5 for " + failedItem.OriginalFileName + " (" + failedItem.Description + ")");
continue;
}
if (!failedItem.NamedByDate && (failedItem.SeasonNumber == 0 || failedItem.EpisodeNumber == 0))
{
Console.WriteLine("FAILED: Season and episode number must be non-zero for " + failedItem.Description + ", skipping...");
continue;
}
if (String.IsNullOrWhiteSpace(failedItem.SabnzbdId) || !failedItem.SabnzbdId.StartsWith("SABnzbd"))
{
Console.WriteLine("FAILED: Unrecognized SABnzbd ID for " + failedItem.Description + ", skipping...");
continue;
}
// Try to match show.
var showId = shows.Where(X => Matchers.MatchTVShow(X.Value.show_name, failedItem.ShowName)).Select(X => X.Key).FirstOrDefault();
if (showId == null)
{
Console.WriteLine("FAILED: Couldn't find show in SickBeard for " + failedItem.Description + ", skipping...");
continue;
}
Int32 seasonNumber = 0;
Int32 episodeNumber = 0;
if (failedItem.NamedByDate)
{
var episodesRequest = new RestRequest();
episodesRequest.AddParameter("cmd", "show.seasons");
episodesRequest.AddParameter("tvdbid", showId);
//episodesRequest.AddParameter("season", failedItem.SeasonNumber);
var episodes = sickbeardClient.Execute<EpisodesRequest>(episodesRequest);
if (!episodes.Data.result.Equals("success", StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("FAILED: Encountered non-success code getting episodes for " + failedItem.Description + ", skipping...");
//.........这里部分代码省略.........
示例13: Geolocate2
public void Geolocate2( string url, string qs)
{
RestClient _client = new RestClient();
_client.BaseUrl = new System.Uri(url);
_client.AddDefaultParameter("key", key, ParameterType.GetOrPost);
var request = new RestRequest();
request.Resource = qs + "&maxResults=1";
request.RequestFormat = DataFormat.Json;
request.JsonSerializer = new RestSharpJsonNetSerializer();
var response = _client.Get<GeocodedObject>(request);
if (response.Data.statusDescription == "OK")
{
centerCoord = response.Data.resourceSets[0].resources[0].point.coordinates;
}
else {
Debug.Log("Something went wrong: no location retrieved from geolocation");
}
}
示例14: WeatherController
public WeatherController()
{
_client = new RestClient("http://api.openweathermap.org/data/2.5/");
_client.AddDefaultParameter("APPID", "7472543b52ecdbc0d9c848fd2a3364ed", ParameterType.GetOrPost);
}
示例15: CreateGoogleMapsRestClient
private RestClient CreateGoogleMapsRestClient()
{
var restClient = new RestClient("https://maps.googleapis.com/maps/api");
restClient.AddDefaultParameter("key", _apiKey);
return restClient;
}