/// <summary> /// Create a service object. /// </summary> /// <param name="signature">Signature of the service being created.</param> /// <param name="user">The user for which the service is being created. /// <param name="serverUrl">The server to which the API calls should be /// made.</param> /// </param> /// <returns>An object of the desired service type.</returns> public override AdsClient CreateService(ServiceSignature signature, AdsUser user, Uri serverUrl) { DfpAppConfig dfpConfig = (DfpAppConfig)Config; if (serverUrl == null) { serverUrl = new Uri(dfpConfig.DfpApiServer); } if (user == null) { throw new ArgumentNullException("user"); } CheckServicePreconditions(signature); DfpServiceSignature dfpapiSignature = signature as DfpServiceSignature; AdsClient service = (AdsClient)Activator.CreateInstance(dfpapiSignature.ServiceType); PropertyInfo propInfo = dfpapiSignature.ServiceType.GetProperty("RequestHeader"); if (propInfo != null) { RequestHeader clonedHeader = (RequestHeader)requestHeader.Clone(); clonedHeader.Version = dfpapiSignature.Version; propInfo.SetValue(service, clonedHeader, null); } if (dfpConfig.Proxy != null) { service.Proxy = dfpConfig.Proxy; } service.Timeout = dfpConfig.Timeout; service.Url = string.Format("{0}apis/ads/publisher/{1}/{2}", serverUrl, dfpapiSignature.Version, dfpapiSignature.ServiceName); service.UserAgent = dfpConfig.GetUserAgent(); service.Signature = signature; service.User = user; return(service); }
/// <summary> /// Create a service object. /// </summary> /// <param name="signature">Signature of the service being created.</param> /// <param name="user">The user for which the service is being created. /// <param name="serverUrl">The server to which the API calls should be /// made.</param> /// </param> /// <returns>An object of the desired service type.</returns> public override AdsClient CreateService(ServiceSignature signature, AdsUser user, Uri serverUrl) { DfaAppConfig config = (DfaAppConfig)base.Config; if (serverUrl == null) { serverUrl = new Uri(config.DfaApiServer); } if (user == null) { throw new ArgumentNullException("user"); } CheckServicePreconditions(signature); DfaServiceSignature dfaapiSignature = signature as DfaServiceSignature; AdsClient service = (AdsClient)Activator.CreateInstance(dfaapiSignature.ServiceType); if (config.Proxy != null) { service.Proxy = config.Proxy; } service.Timeout = config.Timeout; service.Url = string.Format("{0}{1}/api/dfa-api/{2}", serverUrl, dfaapiSignature.Version, dfaapiSignature.ServiceEndpoint); service.UserAgent = config.GetUserAgent(); service.User = user; service.Signature = signature; service.GetType().GetProperty("RequestHeader").SetValue(service, GetRequestHeader(), null); SetRequestHeaderNameSpace(signature as DfaServiceSignature, service); return(service); }
/// <summary> /// Gets a login token for authenticating DFA API calls. /// </summary> /// <param name="user">The user for which token is generated.</param> /// <param name="serviceVersion">The service version.</param> /// <returns>A token which may be used for future API calls.</returns> public static UserToken GetAuthenticationToken(AdsUser user, string serviceVersion) { DfaAppConfig config = (DfaAppConfig)user.Config; if (string.IsNullOrEmpty(config.DfaUserName)) { throw new ArgumentNullException(DfaErrorMessages.UserNameCannotBeEmpty); } UserToken userToken = tokenCache.GetToken(config.DfaUserName); if (userToken == null) { lock (typeof(LoginUtil)) { userToken = tokenCache.GetToken(config.DfaUserName); if (userToken == null) { userToken = GenerateAuthenticationToken(user, serviceVersion); tokenCache.AddToken(config.DfaUserName, userToken); } } } return(userToken); }
/// <summary> /// Initializes a new instance of the <see cref="BulkJobErrorHandler"/> class. /// </summary> /// <param name="user">The AdWords user.</param> public BulkJobErrorHandler(AdsUser user) : base(user.Config) { }
/// <summary> /// Initializes a new instance of the <see cref="SoapListenerInspector"/> /// class. /// </summary> public SoapListenerInspector(AdsUser user, string serviceName) { this.user = user; this.serviceName = serviceName; }
/// <summary> /// Create a service object. /// </summary> /// <param name="signature">Signature of the service being created.</param> /// <param name="user">The user for which the service is being created. /// <param name="serverUrl">The server to which the API calls should be /// made.</param> /// </param> /// <returns>An object of the desired service type.</returns> public override AdsClient CreateService(ServiceSignature signature, AdsUser user, Uri serverUrl) { DfpAppConfig dfpConfig = (DfpAppConfig)Config; if (serverUrl == null) { serverUrl = new Uri(dfpConfig.DfpApiServer); } if (user == null) { throw new ArgumentNullException("user"); } CheckServicePreconditions(signature); DfpServiceSignature dfpapiSignature = signature as DfpServiceSignature; EndpointAddress endpoint = new EndpointAddress(string.Format(ENDPOINT_TEMPLATE, serverUrl, dfpapiSignature.Version, dfpapiSignature.ServiceName)); // Create the binding for the service BasicHttpBinding binding = new BasicHttpBinding(); binding.Security.Mode = BasicHttpSecurityMode.Transport; binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; binding.MaxReceivedMessageSize = int.MaxValue; binding.TextEncoding = Encoding.UTF8; AdsClient service = (AdsClient)Activator.CreateInstance( dfpapiSignature.ServiceType, new object[] { binding, endpoint }); ServiceEndpoint serviceEndpoint = (ServiceEndpoint)service.GetType().GetProperty("Endpoint").GetValue(service, null); AdsServiceInspectorBehavior inspectorBehavior = new AdsServiceInspectorBehavior(); inspectorBehavior.Add(new OAuth2ClientMessageInspector(user.OAuthProvider)); RequestHeader clonedHeader = (RequestHeader)requestHeader.Clone(); clonedHeader.Version = dfpapiSignature.Version; inspectorBehavior.Add(new DfpSoapHeaderInspector() { RequestHeader = clonedHeader, Config = dfpConfig }); inspectorBehavior.Add(new SoapListenerInspector(user, dfpapiSignature.ServiceName)); inspectorBehavior.Add(new SoapFaultInspector <DfpApiException>() { ErrorType = dfpapiSignature.ServiceType.Assembly.GetType( dfpapiSignature.ServiceType.Namespace + ".ApiException"), }); #if NET452 serviceEndpoint.Behaviors.Add(inspectorBehavior); #else serviceEndpoint.EndpointBehaviors.Add(inspectorBehavior); #endif if (dfpConfig.Proxy != null) { service.Proxy = dfpConfig.Proxy; } service.EnableDecompression = dfpConfig.EnableGzipCompression; service.Timeout = dfpConfig.Timeout; service.UserAgent = dfpConfig.GetUserAgent(); service.Signature = signature; service.User = user; return(service); }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilities"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> /// <param name="useChunking">if the operations should be broken into /// smaller chunks before uploading to the server.</param> /// <param name="chunkSize">The chunk size to use for resumable upload.</param> /// <exception cref="ArgumentException">Thrown if <paramref name="chunkSize"/> /// is not a multiple of 256KB.</exception> /// <remarks>Use chunking if your network is spotty for uploads, or if it /// has restrictions such as speed limits or timeouts. Chunking makes your /// upload reliable when the network is unreliable, but it is inefficient /// over a good connection, since an HTTPs request has to be made for every /// chunk being uploaded.</remarks> public BatchJobUtilities(AdsUser user, bool useChunking, int chunkSize) : base(user, useChunking, chunkSize) { }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilities"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> public BatchJobUtilities(AdsUser user) : base(user) { }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilities"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> public BatchJobUtilities(AdsUser user) : this(user, DEFAULT_CHUNK_SIZE) { }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilities"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> public BatchJobUtilities(AdsUser user) { this.user = user; }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilitiesBase"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> public BatchJobUtilitiesBase(AdsUser user) : this(user, false, DEFAULT_CHUNK_SIZE) { }
/// <summary> /// Initializes a new instance of the <see cref="BatchJobUtilitiesBase"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> /// <param name="useChunking">if the operations should be broken into /// smaller chunks before uploading to the server.</param> /// <param name="chunkSize">The chunk size to use for resumable upload.</param> /// <exception cref="ArgumentException">Thrown if <paramref name="chunkSize"/> /// is not a multiple of 256KB.</exception> /// <remarks>Use chunking if your network is spotty for uploads, or if it /// has restrictions such as speed limits or timeouts. Chunking makes your /// upload reliable when the network is unreliable, but it is inefficient /// over a good connection, since an HTTPs request has to be made for every /// chunk being uploaded.</remarks> public BatchJobUtilitiesBase(AdsUser user, bool useChunking, int chunkSize) { Init(user, useChunking, chunkSize); }
/// <summary> /// Create a service object. /// </summary> /// <param name="signature">Signature of the service being created.</param> /// <param name="user">The user for which the service is being created.</param> /// <param name="serverUrl">The server to which the API calls should be /// made.</param> /// <returns>An object of the desired service type.</returns> public override AdsClient CreateService(ServiceSignature signature, AdsUser user, Uri serverUrl) { AdWordsAppConfig awConfig = (AdWordsAppConfig)Config; if (serverUrl == null) { serverUrl = new Uri(awConfig.AdWordsApiServer); } if (user == null) { throw new ArgumentNullException("user"); } CheckServicePreconditions(signature); AdWordsServiceSignature awapiSignature = signature as AdWordsServiceSignature; EndpointAddress endpoint = new EndpointAddress(string.Format(ENDPOINT_TEMPLATE, serverUrl, awapiSignature.GroupName, awapiSignature.Version, awapiSignature.ServiceName)); // Create the binding for the service. BasicHttpBinding binding = new BasicHttpBinding(); // If the server end point is HTTP, then don't use security. This is used for testing // purposes only. if (endpoint.Uri.Scheme == "http") { binding.Security.Mode = BasicHttpSecurityMode.None; } else { binding.Security.Mode = BasicHttpSecurityMode.Transport; } binding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None; binding.MaxReceivedMessageSize = int.MaxValue; binding.TextEncoding = Encoding.UTF8; AdsClient service = (AdsClient)Activator.CreateInstance(awapiSignature.ServiceType, new object[] { binding, endpoint }); ServiceEndpoint serviceEndpoint = (ServiceEndpoint)service.GetType().GetProperty("Endpoint").GetValue(service, null); AdsServiceInspectorBehavior inspectorBehavior = new AdsServiceInspectorBehavior(); // Add OAuth client message inspector only if the authorization method is OAuth2. // In testing mode, the authorization method is set to Insecure. if (awConfig.AuthorizationMethod == AdWordsAuthorizationMethod.OAuth2) { inspectorBehavior.Add(new OAuthClientMessageInspector(user.OAuthProvider)); } RequestHeader clonedHeader = (RequestHeader)requestHeader.Clone(); clonedHeader.Version = awapiSignature.Version; clonedHeader.GroupName = awapiSignature.GroupName; inspectorBehavior.Add(new AdWordsSoapHeaderInspector() { RequestHeader = clonedHeader, User = (AdWordsUser)user, }); inspectorBehavior.Add(new SoapListenerInspector(user, awapiSignature.ServiceName)); inspectorBehavior.Add(new SoapFaultInspector <AdWordsApiException>() { ErrorType = awapiSignature.ServiceType.Assembly.GetType( awapiSignature.ServiceType.Namespace + ".ApiException") }); #if NET452 serviceEndpoint.Behaviors.Add(inspectorBehavior); #else serviceEndpoint.EndpointBehaviors.Add(inspectorBehavior); #endif if (awConfig.Proxy != null) { service.Proxy = awConfig.Proxy; } service.Timeout = awConfig.Timeout; service.EnableDecompression = awConfig.EnableGzipCompression; service.User = user; service.Signature = awapiSignature; return(service); }
/// <summary> /// Initializes a new instance of the <see cref="AdsReportUtilities"/> /// class. /// </summary> /// <param name="user">AdWords user to be used along with this /// utilities object.</param> public AdsReportUtilities(AdsUser user) { this.user = user; }
/// <summary> /// Create a service object. /// </summary> /// <param name="signature">Signature of the service being created.</param> /// <param name="user">The user for which the service is being created. /// <param name="serverUrl">The server to which the API calls should be /// made.</param></param> /// <param name="serverUrl"></param> /// <returns> /// An object of the desired service type. /// </returns> public override AdsClient CreateService(ServiceSignature signature, AdsUser user, Uri serverUrl) { return(null); }