/// <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); }
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 => { }); }
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; }
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"); }
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()); }
/// <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; }
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); }
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); }
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()); }
public BusBuddy() { _restClient = new RestClient("http://api.busbuddy.norrs.no:8080/api/1.2/"); _restClient.AddDefaultParameter("apiKey", "HwSJ6xL9wCUnpegC"); }
public FoursquareService() { _fourSquareClient = new RestClient("https://api.foursquare.com"); _fourSquareClient.Authenticator = this; _fourSquareClient.AddDefaultParameter("v","20121006",ParameterType.GetOrPost); }
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..."); continue; } AirByDateEpisode episode = null; foreach (var season in episodes.Data.data) { foreach (var ep in season.Value) if (ep.Value.airdate == failedItem.NamedDate.Replace(".", "-")) { episode = ep.Value; seasonNumber = Int32.Parse(season.Key); episodeNumber = Int32.Parse(ep.Key); break; } if (episode != null) break; } if (episode == null) { Console.WriteLine("FAILED: Couldn't find episode number for " + failedItem.Description + ", skipping..."); continue; } } else { seasonNumber = failedItem.SeasonNumber; episodeNumber = failedItem.EpisodeNumber; } var getEpisodeRequest = new RestRequest(); getEpisodeRequest.AddParameter("cmd", "episode"); getEpisodeRequest.AddParameter("tvdbid", showId); getEpisodeRequest.AddParameter("season", seasonNumber); getEpisodeRequest.AddParameter("episode", episodeNumber); var getEpisodeResult = sickbeardClient.Execute<EpisodeRequest>(getEpisodeRequest); if (!getEpisodeResult.Data.result.Equals("success", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("FAILED: Encountered non-success code getting episode status for " + failedItem.Description + ", skipping..."); continue; } if (String.IsNullOrWhiteSpace(getEpisodeResult.Data.data.location)) { var setEpisodeStatusRequest = new RestRequest(); setEpisodeStatusRequest.AddParameter("cmd", "episode.setstatus"); setEpisodeStatusRequest.AddParameter("tvdbid", showId); setEpisodeStatusRequest.AddParameter("season", seasonNumber); setEpisodeStatusRequest.AddParameter("episode", episodeNumber); setEpisodeStatusRequest.AddParameter("status", "wanted"); var setStatusResult = sickbeardClient.Execute<EpisodeSetStatusRequest>(setEpisodeStatusRequest).Data; if (!setStatusResult.result.Equals("success", StringComparison.OrdinalIgnoreCase)) { Console.WriteLine("FAILED: Encountered non-success code setting episode status for " + failedItem.Description + ", skipping..."); continue; } Console.WriteLine("SUCCESS: Retried " + failedItem.Description); RetryData.Increment(failedItem.OriginalFileName); } else { Console.WriteLine("We already have this episode downloaded, removing from SAB history. Details: " + failedItem.Description); } var deleteHistoryRequest = new RestRequest(); deleteHistoryRequest.AddParameter("mode", "history"); deleteHistoryRequest.AddParameter("name", "delete"); deleteHistoryRequest.AddParameter("value", failedItem.SabnzbdId); deleteHistoryRequest.AddParameter("failed_only", 1); deleteHistoryRequest.AddParameter("del_files", 0); sabnzbdClient.Execute(deleteHistoryRequest); Console.WriteLine("SUCCESS: Removed old SAB history entry for " + failedItem.Description); } RetryData.Save(); }
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"); } }
public WeatherController() { _client = new RestClient("http://api.openweathermap.org/data/2.5/"); _client.AddDefaultParameter("APPID", "7472543b52ecdbc0d9c848fd2a3364ed", ParameterType.GetOrPost); }
private RestClient CreateGoogleMapsRestClient() { var restClient = new RestClient("https://maps.googleapis.com/maps/api"); restClient.AddDefaultParameter("key", _apiKey); return restClient; }
private RestClient CreateDbtRestClient() { var restClient = new RestClient("http://dbt.io/"); restClient.AddDefaultParameter("key", _apiKey); restClient.AddDefaultParameter("v", ApiVersion); return restClient; }
public static bool Initialize() { Client = new RestClient(@"http://pillbox.nlm.nih.gov/PHP/pillboxAPIService.php"); Client.AddDefaultParameter("key", "WGY7R8OGHU"); Client.AddDefaultParameter("has_image", "1"); IsInitialized = true; return IsInitialized; }
/// <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) { var client = new RestClient() { Timeout = this.Timeout, BaseUrl = "https://" + Subdomain + ".pagerduty.com/api" + url }; client.AddDefaultParameter(new Parameter { Name = "Authorization", Value = "Token token=" + this.AccessToken, Type = ParameterType.HttpHeader }); return client; }
private void Initialize(string baseUrl, bool useSsl, string apiKey) { ApiKey = apiKey; string httpScheme = useSsl ? "https" : "http"; _client = new RestClient(httpScheme + "://" + baseUrl + "/" + ApiVersion + "/"); _client.AddDefaultParameter("api_key", apiKey); _client.ClearHandlers(); _client.AddHandler("application/json", new JsonDeserializer()); }
private void Setup(Config config) { client = new RestClient(config.MarketAPI_URL); client.AddDefaultParameter("uid", config.MarketAPI_UserID); client.AddDefaultParameter("key", config.MarketAPI_Key); }