Added UserAgent to RestClient.
This commit is contained in:
parent
e9f39493f4
commit
9a649cf58e
|
@ -43,6 +43,10 @@
|
|||
<HintPath>..\packages\SharpZipLib.0.86.0\lib\20\ICSharpCode.SharpZipLib.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="Microsoft.CSharp" />
|
||||
<Reference Include="RestSharp, Version=104.4.0.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\RestSharp.104.4.0\lib\net4\RestSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Configuration" />
|
||||
<Reference Include="System.Configuration.Install" />
|
||||
|
|
|
@ -3,5 +3,6 @@
|
|||
<package id="loggly-csharp" version="2.3" targetFramework="net40" />
|
||||
<package id="Newtonsoft.Json" version="5.0.8" targetFramework="net40" />
|
||||
<package id="NLog" version="2.1.0" targetFramework="net40" />
|
||||
<package id="RestSharp" version="104.4.0" targetFramework="net40" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net40" />
|
||||
</packages>
|
|
@ -43,7 +43,7 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
|||
{
|
||||
_logger.Debug("Fetching Series IDs from");
|
||||
|
||||
var restClient = new RestClient(XEM_BASE_URL);
|
||||
var restClient = RestClientFactory.BuildClient(XEM_BASE_URL);
|
||||
|
||||
var request = BuildRequest("havemap");
|
||||
|
||||
|
@ -57,7 +57,7 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
|||
{
|
||||
_logger.Debug("Fetching Mappings for: {0}", id);
|
||||
|
||||
var restClient = new RestClient(XEM_BASE_URL);
|
||||
var restClient = RestClientFactory.BuildClient(XEM_BASE_URL);
|
||||
|
||||
var request = BuildRequest("all");
|
||||
request.AddParameter("id", id);
|
||||
|
@ -71,7 +71,7 @@ namespace NzbDrone.Core.DataAugmentation.Xem
|
|||
public List<SceneMapping> GetSceneTvdbNames()
|
||||
{
|
||||
_logger.Debug("Fetching alternate names");
|
||||
var restClient = new RestClient(XEM_BASE_URL);
|
||||
var restClient = RestClientFactory.BuildClient(XEM_BASE_URL);
|
||||
|
||||
var request = BuildRequest("allNames");
|
||||
request.AddParameter("origin", "tvdb");
|
||||
|
|
|
@ -172,7 +172,7 @@ namespace NzbDrone.Core.Download.Clients.Nzbget
|
|||
|
||||
_logger.Debug("Url: " + url);
|
||||
|
||||
var client = new RestClient(url);
|
||||
var client = RestClientFactory.BuildClient(url);
|
||||
client.Authenticator = new HttpBasicAuthenticator(settings.Username, settings.Password);
|
||||
|
||||
return client;
|
||||
|
|
|
@ -7,6 +7,7 @@ using NLog;
|
|||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Extensions;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Rest;
|
||||
using NzbDrone.Core.Download.Clients.Sabnzbd.Responses;
|
||||
using RestSharp;
|
||||
|
||||
|
@ -138,7 +139,7 @@ namespace NzbDrone.Core.Download.Clients.Sabnzbd
|
|||
|
||||
_logger.Debug("Url: " + url);
|
||||
|
||||
return new RestClient(url);
|
||||
return RestClientFactory.BuildClient(url);
|
||||
}
|
||||
|
||||
private void CheckForError(IRestResponse response)
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace NzbDrone.Core.MetadataSource
|
|||
|
||||
private static IRestClient BuildClient(string resource, string method)
|
||||
{
|
||||
return new RestClient(string.Format("http://api.trakt.tv/{0}/{1}.json/bc3c2c460f22cbb01c264022b540e191", resource, method));
|
||||
return RestClientFactory.BuildClient(string.Format("http://api.trakt.tv/{0}/{1}.json/bc3c2c460f22cbb01c264022b540e191", resource, method));
|
||||
}
|
||||
|
||||
private static Series MapSeries(Show show)
|
||||
|
|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
using NzbDrone.Core.Rest;
|
||||
using NzbDrone.Core.Indexers;
|
||||
using NzbDrone.Core.Tv;
|
||||
using RestSharp;
|
||||
|
@ -38,7 +39,7 @@ namespace NzbDrone.Core.MetadataSource.Tvdb
|
|||
|
||||
private static IRestClient BuildClient(string resource)
|
||||
{
|
||||
return new RestClient(String.Format("http://thetvdb.com/data/{0}", resource));
|
||||
return RestClientFactory.BuildClient(String.Format("http://thetvdb.com/data/{0}", resource));
|
||||
}
|
||||
|
||||
private static Series MapSeries(XElement item)
|
||||
|
|
|
@ -28,7 +28,7 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
|
|||
|
||||
public void SendNotification(string title, string message, string apiKey, NotifyMyAndroidPriority priority)
|
||||
{
|
||||
var client = new RestClient(URL);
|
||||
var client = RestClientFactory.BuildClient(URL);
|
||||
var request = new RestRequest("notify", Method.POST);
|
||||
request.RequestFormat = DataFormat.Xml;
|
||||
request.AddParameter("apikey", apiKey);
|
||||
|
@ -43,7 +43,7 @@ namespace NzbDrone.Core.Notifications.NotifyMyAndroid
|
|||
|
||||
private void Verify(string apiKey)
|
||||
{
|
||||
var client = new RestClient(URL);
|
||||
var client = RestClientFactory.BuildClient(URL);
|
||||
var request = new RestRequest("verify", Method.GET);
|
||||
request.RequestFormat = DataFormat.Xml;
|
||||
request.AddParameter("apikey", apiKey, ParameterType.GetOrPost);
|
||||
|
|
|
@ -7,6 +7,7 @@ using NLog;
|
|||
using NzbDrone.Common;
|
||||
using NzbDrone.Common.Cache;
|
||||
using NzbDrone.Common.Serializer;
|
||||
using NzbDrone.Core.Rest;
|
||||
using RestSharp;
|
||||
|
||||
namespace NzbDrone.Core.Notifications.Plex
|
||||
|
@ -75,7 +76,7 @@ namespace NzbDrone.Core.Notifications.Plex
|
|||
|
||||
private RestClient GetMyPlexClient(string username, string password)
|
||||
{
|
||||
var client = new RestClient("https://my.plexapp.com");
|
||||
var client = RestClientFactory.BuildClient("https://my.plexapp.com");
|
||||
client.Authenticator = new HttpBasicAuthenticator(username, password);
|
||||
|
||||
return client;
|
||||
|
@ -96,7 +97,7 @@ namespace NzbDrone.Core.Notifications.Plex
|
|||
|
||||
private RestClient GetPlexServerClient(PlexServerSettings settings)
|
||||
{
|
||||
return new RestClient(String.Format("http://{0}:{1}", settings.Host, settings.Port));
|
||||
return RestClientFactory.BuildClient(String.Format("http://{0}:{1}", settings.Host, settings.Port));
|
||||
}
|
||||
|
||||
private RestRequest GetPlexServerRequest(string resource, Method method, PlexServerSettings settings)
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Notifications.PushBullet
|
|||
|
||||
public void SendNotification(string title, string message, string apiKey, string deviceId)
|
||||
{
|
||||
var client = new RestClient(URL);
|
||||
var client = RestClientFactory.BuildClient(URL);
|
||||
var request = BuildRequest(deviceId);
|
||||
|
||||
request.AddParameter("type", "note");
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace NzbDrone.Core.Notifications.Pushover
|
|||
|
||||
public void SendNotification(string title, string message, string apiKey, string userKey, PushoverPriority priority, string sound)
|
||||
{
|
||||
var client = new RestClient(URL);
|
||||
var client = RestClientFactory.BuildClient(URL);
|
||||
var request = new RestRequest(Method.POST);
|
||||
request.AddParameter("token", apiKey);
|
||||
request.AddParameter("user", userKey);
|
||||
|
|
|
@ -559,6 +559,7 @@
|
|||
<Compile Include="Qualities\QualityModelComparer.cs" />
|
||||
<Compile Include="Qualities\QualityProfileItem.cs" />
|
||||
<Compile Include="Rest\JsonNetSerializer.cs" />
|
||||
<Compile Include="Rest\RestClientFactory.cs" />
|
||||
<Compile Include="RootFolders\RootFolderRepository.cs" />
|
||||
<Compile Include="Security.cs" />
|
||||
<Compile Include="ThingiProvider\ConfigContractNotFoundException.cs" />
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using RestSharp;
|
||||
using NzbDrone.Common.EnvironmentInfo;
|
||||
|
||||
namespace NzbDrone.Core.Rest
|
||||
{
|
||||
public static class RestClientFactory
|
||||
{
|
||||
public static RestClient BuildClient(String baseUrl)
|
||||
{
|
||||
var restClient = new RestClient(baseUrl);
|
||||
|
||||
restClient.UserAgent = String.Format("NzbDrone/{0} (RestSharp/{1}; {2}/{3})",
|
||||
BuildInfo.Version,
|
||||
restClient.GetType().Assembly.GetName().Version,
|
||||
OsInfo.Os, OsInfo.Version.ToString(2));
|
||||
|
||||
return restClient;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -17,7 +17,7 @@ namespace NzbDrone.Core.Update
|
|||
{
|
||||
public UpdatePackage GetLatestUpdate(string branch, Version currentVersion)
|
||||
{
|
||||
var restClient = new RestClient(Services.RootUrl);
|
||||
var restClient = RestClientFactory.BuildClient(Services.RootUrl);
|
||||
|
||||
var request = new RestRequest("/v1/update/{branch}");
|
||||
|
||||
|
@ -34,7 +34,7 @@ namespace NzbDrone.Core.Update
|
|||
|
||||
public List<UpdatePackage> GetRecentUpdates(string branch)
|
||||
{
|
||||
var restClient = new RestClient(Services.RootUrl);
|
||||
var restClient = RestClientFactory.BuildClient(Services.RootUrl);
|
||||
|
||||
var request = new RestRequest("/v1/update/{branch}/changes");
|
||||
|
||||
|
|
Loading…
Reference in New Issue