Class: AdCenterService
- Inherits:
-
Object
- Object
- AdCenterService
- Defined in:
- lib/adcenter_service.rb
Direct Known Subclasses
AdministrationService, CampaignManagementService, CustomerBillingService, CustomerManagementService, NotificationManagement, ReportingService, SecureDataManagementService
Defined Under Namespace
Classes: HeaderHandler
Constant Summary collapse
- DEFAULT_REQUIRED_CREDENTIALS =
%w[ ApplicationToken CustomerAccountId CustomerId UserName Password DeveloperToken ]
Instance Attribute Summary collapse
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#required_credentials ⇒ Object
Returns the value of attribute required_credentials.
-
#service ⇒ Object
Returns the value of attribute service.
-
#service_namespace ⇒ Object
Returns the value of attribute service_namespace.
Instance Method Summary collapse
-
#initialize(endpoint, credentials) ⇒ AdCenterService
constructor
A new instance of AdCenterService.
- #initialize_authentication_headers(creds) ⇒ Object
- #method_missing(method, *args) ⇒ Object
Constructor Details
#initialize(endpoint, credentials) ⇒ AdCenterService
Returns a new instance of AdCenterService.
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/adcenter_service.rb', line 12 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
#method_missing(method, *args) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'lib/adcenter_service.rb', line 29 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
#endpoint ⇒ Object
Returns the value of attribute endpoint.
5 6 7 |
# File 'lib/adcenter_service.rb', line 5 def endpoint @endpoint end |
#required_credentials ⇒ Object
Returns the value of attribute required_credentials.
8 9 10 |
# File 'lib/adcenter_service.rb', line 8 def required_credentials @required_credentials end |
#service ⇒ Object
Returns the value of attribute service.
6 7 8 |
# File 'lib/adcenter_service.rb', line 6 def service @service end |
#service_namespace ⇒ Object
Returns the value of attribute service_namespace.
7 8 9 |
# File 'lib/adcenter_service.rb', line 7 def service_namespace @service_namespace end |
Instance Method Details
#initialize_authentication_headers(creds) ⇒ Object
23 24 25 26 27 |
# File 'lib/adcenter_service.rb', line 23 def initialize_authentication_headers(creds) @required_credentials.each do |key| self.headerhandler << HeaderHandler.new(@service_namespace, key, creds[key]) end end |