Class: Bing::Ads::API::V11::Services::Base
- Inherits:
-
Object
- Object
- Bing::Ads::API::V11::Services::Base
- Defined in:
- lib/bing/ads/api/v11/services/base.rb
Overview
Bing::Ads::API::V11::Base
Direct Known Subclasses
Instance Attribute Summary collapse
-
#environment ⇒ Object
Returns the value of attribute environment.
-
#retry_attempts ⇒ Object
Returns the value of attribute retry_attempts.
-
#soap_client ⇒ Object
Returns the value of attribute soap_client.
Instance Method Summary collapse
-
#call(operation, payload) ⇒ Object
This is a utility wrapper for calling services into the SOAPClient.
-
#initialize(options = {}) ⇒ Base
constructor
-
environment -
:productionor:sandbox* developer_token - client application’s developer access token * customer_id - identifier for the customer that owns the account * account_id - identifier of the account that own the entities in the request * client_settings - Hash with any Client additional options (such as header, logger or enconding) * retry_attempts - Number of times the service must retry on failure * log_level - :debug :warn :error :fatal (EITHER) * authentication_token - OAuth2 token (OR) * username - Bing Ads username * password - Bing Ads password.
-
-
#response_body(response, method) ⇒ Object
Extracts the actual response from the entire response hash.
Constructor Details
#initialize(options = {}) ⇒ Base
-
environment -
:productionor:sandbox -
developer_token - client application’s developer access token
-
customer_id - identifier for the customer that owns the account
-
account_id - identifier of the account that own the entities in the request
-
client_settings - Hash with any Client additional options (such as header, logger or enconding)
-
retry_attempts - Number of times the service must retry on failure
-
log_level - :debug :warn :error :fatal
(EITHER)
-
authentication_token - OAuth2 token
(OR)
-
username - Bing Ads username
-
password - Bing Ads password
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 23 def initialize( = {}) @environment = .delete(:environment) @retry_attempts = .delete(:retry_attempts) || 0 @account_id = [:account_id] @customer_id = [:customer_id] raise 'You must set the service environment' unless @environment [:wsdl_url] = service_wsdl_url [:namespace_identifier] = Bing::Ads::API::V11::NAMESPACE_IDENTIFIER @soap_client = Bing::Ads::API::SOAPClient.new() end |
Instance Attribute Details
#environment ⇒ Object
Returns the value of attribute environment.
8 9 10 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 8 def environment @environment end |
#retry_attempts ⇒ Object
Returns the value of attribute retry_attempts.
8 9 10 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 8 def retry_attempts @retry_attempts end |
#soap_client ⇒ Object
Returns the value of attribute soap_client.
8 9 10 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 8 def soap_client @soap_client end |
Instance Method Details
#call(operation, payload) ⇒ Object
This is a utility wrapper for calling services into the SOAPClient. This methods handle the Savon::Client Exceptions and returns a Hash with the call response
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 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 47 def call(operation, payload) retries_made = 0 raise 'You must provide an operation' if operation.nil? begin response = soap_client.call(operation: operation.to_sym, payload: payload) return response.hash rescue Savon::SOAPFault => error fault_detail = error.to_hash[:fault][:detail] if fault_detail.key?(:api_fault_detail) handle_soap_fault(operation, fault_detail, :api_fault_detail) elsif fault_detail.key?(:ad_api_fault_detail) handle_soap_fault(operation, fault_detail, :ad_api_fault_detail) else if retries_made < retry_attempts sleep(2**retries_made) retries_made += 1 retry else raise Bing::Ads::API::Errors::UnhandledSOAPFault, "SOAP error (#{fault_detail.keys.join(', ')}) while calling #{operation}. #{error.}" end end rescue Savon::HTTPError => error # TODO better handling raise rescue Savon::InvalidResponseError => error # TODO better handling raise rescue if retries_made < retry_attempts sleep(2**retries_made) retries_made += 1 retry else raise end end end |
#response_body(response, method) ⇒ Object
Extracts the actual response from the entire response hash.
96 97 98 |
# File 'lib/bing/ads/api/v11/services/base.rb', line 96 def response_body(response, method) response[:envelope][:body]["#{method}_response".to_sym] end |