Class: AdCenterService
- Inherits:
-
Object
- Object
- AdCenterService
- Defined in:
- lib/adcenter_service.rb
Overview
Parent class for individual adCenter service classes
Direct Known Subclasses
AdIntelligenceService, AdministrationService, CampaignManagementService, CustomerBillingService, CustomerManagementService, NotificationManagement, NotificationService, OptimizerService, ReportingService, SecureDataManagementService
Defined Under Namespace
Classes: HeaderHandler
Constant Summary collapse
- DEFAULT_REQUIRED_CREDENTIALS =
list of required header fields for most services
%w[ ApplicationToken CustomerAccountId CustomerId UserName Password DeveloperToken ]
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
the endpoint to use when connecting to this service.
-
#required_credentials ⇒ Object
array of header fields required by the service.
-
#service ⇒ Object
the actual SOAP::RPC::Driver for the service.
-
#service_namespace ⇒ Object
sets the namespace to be used in service headers.
Instance Method Summary collapse
-
#initialize(endpoint, credentials) ⇒ AdCenterService
constructor
A new instance of AdCenterService.
-
#initialize_authentication_headers(creds) ⇒ Object
sets up authentication header handlers.
-
#initialize_service ⇒ Object
initializes the SOAP::RPC::Driver and does per-service configuration.
-
#method_missing(method, *args) ⇒ Object
passes the calls to our service to the SOAP::RPC::driver version of the service as defined in @service.
Constructor Details
permalink #initialize(endpoint, credentials) ⇒ AdCenterService
Returns a new instance of AdCenterService.
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/adcenter_service.rb', line 18 def initialize(endpoint, credentials) @service_namespace = 'https://adcenter.microsoft.com/v8' @required_credentials = DEFAULT_REQUIRED_CREDENTIALS @endpoint = endpoint initialize_service(@endpoint) initialize_authentication_headers(credentials) # set options on service after it is built @service.wiredump_dev = STDERR if $DEBUG @service.["protocol.http.ssl_config.verify_mode"] = nil end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
permalink #method_missing(method, *args) ⇒ Object
passes the calls to our service to the SOAP::RPC::driver version of the service as defined in @service
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/adcenter_service.rb', line 43 def method_missing(method, *args) begin res = eval "@service.#{method}(*args)" raise AdCenterClientException.new(method, res.errors) if res.respond_to?(:errors) && ! res.errors.nil? rescue SOAP::FaultError => fault detail = fault.detail if detail.respond_to?(:adApiFaultDetail) detail.adApiFaultDetail.errors.each do |r| msg = sprintf("*** SOAP Fault found in '%s()': [%d] %s -- %s", method, r.code, r.errorCode, r.) warn msg end # TODO: test apiFaultDetail elsif detail.respond_to?('apiFaultDetail') operationErrors = detail.operationErrors.operationError if !operationErrors.respond_to?('each') operationErrors = [operationErrors] end operationErrors.each do |opError| warn "Operation error '#{opError.}' (#{opError.code}) encountered.\n" end # TODO: test generic SOAP error handling else if String == detail.class warn fault.to_s else warn "Generic SOAP fault '#{detail.exceptionDetail.}' encountered.\n" end end end res end |
Instance Attribute Details
permalink #endpoint ⇒ Object
the endpoint to use when connecting to this service
7 8 9 |
# File 'lib/adcenter_service.rb', line 7 def endpoint @endpoint end |
permalink #required_credentials ⇒ Object
array of header fields required by the service
13 14 15 |
# File 'lib/adcenter_service.rb', line 13 def required_credentials @required_credentials end |
permalink #service ⇒ Object
the actual SOAP::RPC::Driver for the service
9 10 11 |
# File 'lib/adcenter_service.rb', line 9 def service @service end |
permalink #service_namespace ⇒ Object
sets the namespace to be used in service headers
11 12 13 |
# File 'lib/adcenter_service.rb', line 11 def service_namespace @service_namespace end |
Instance Method Details
permalink #initialize_authentication_headers(creds) ⇒ Object
sets up authentication header handlers
30 31 32 33 34 |
# File 'lib/adcenter_service.rb', line 30 def initialize_authentication_headers(creds) @required_credentials.each do |key| self.headerhandler << HeaderHandler.new(@service_namespace, key, creds[key]) end end |
permalink #initialize_service ⇒ Object
initializes the SOAP::RPC::Driver and does per-service configuration
37 38 39 |
# File 'lib/adcenter_service.rb', line 37 def initialize_service raise NotImplementedError.new("children of AdCenterService must implement #{__method__}") end |