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


C# RestClient.AddDefaultParameter方法代码示例

本文整理汇总了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);
        }
开发者ID:yceron,项目名称:goodreads-dotnet,代码行数:36,代码来源:GoodreadsClient.cs

示例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 => { });
        }
开发者ID:jdbrock,项目名称:beardharder,代码行数:11,代码来源:App.cs

示例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;
        }
开发者ID:Thoorium,项目名称:comicvine-api-net,代码行数:7,代码来源:RestHelper.cs

示例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");
 }
开发者ID:badomm,项目名称:TronderBuss,代码行数:8,代码来源:BussBuddy.cs

示例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());
        }
开发者ID:tobsa,项目名称:TvShowManager,代码行数:9,代码来源:TMDbClient.cs

示例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;
        }
开发者ID:jameswestbv,项目名称:PagerDuty.Net,代码行数:18,代码来源:PagerDutyAPI.cs

示例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);
        }
开发者ID:andycmaj,项目名称:SixDegreesApi,代码行数:17,代码来源:TmdbSearchTests.cs

示例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);
        }
开发者ID:nberardi,项目名称:stripe-dotnet,代码行数:19,代码来源:StripeClient.cs

示例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());
        }
开发者ID:cwachowicz,项目名称:twilio-forwarding,代码行数:37,代码来源:ResponseController.cs

示例10: BusBuddy

 public BusBuddy()
 {
     _restClient = new RestClient("http://api.busbuddy.norrs.no:8080/api/1.2/");
     _restClient.AddDefaultParameter("apiKey", "HwSJ6xL9wCUnpegC");
 }
开发者ID:marchon,项目名称:MonoBus,代码行数:5,代码来源:BusBuddy.cs

示例11: FoursquareService

 public FoursquareService()
 {
     _fourSquareClient = new RestClient("https://api.foursquare.com");
     _fourSquareClient.Authenticator = this;
     _fourSquareClient.AddDefaultParameter("v","20121006",ParameterType.GetOrPost);
 }
开发者ID:pdeparcq,项目名称:planmytrip,代码行数:6,代码来源:FoursquareService.cs

示例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...");
//.........这里部分代码省略.........
开发者ID:jdbrock,项目名称:beardharder,代码行数:101,代码来源:App.cs

示例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");
     }
 }
开发者ID:Miista,项目名称:TerrainGeneration,代码行数:18,代码来源:MapHandler.cs

示例14: WeatherController

 public WeatherController()
 {
     _client = new RestClient("http://api.openweathermap.org/data/2.5/");
     _client.AddDefaultParameter("APPID", "7472543b52ecdbc0d9c848fd2a3364ed", ParameterType.GetOrPost);
 }
开发者ID:Miista,项目名称:TerrainGeneration,代码行数:5,代码来源:WeatherController.cs

示例15: CreateGoogleMapsRestClient

 private RestClient CreateGoogleMapsRestClient()
 {
     var restClient = new RestClient("https://maps.googleapis.com/maps/api");
     restClient.AddDefaultParameter("key", _apiKey);
     return restClient;
 }
开发者ID:OlsonAndrewD,项目名称:the-phone-bible,代码行数:6,代码来源:TimeService.cs


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