Class: BingAdsApi::Config
- Inherits:
-
Object
- Object
- BingAdsApi::Config
- Includes:
- Singleton
- Defined in:
- lib/bing-ads-api/config.rb
Overview
Public : Helper class for configuration issues like WSDL URLs and constants
- Author
Examples
class_usage
# => class_usage_return
Constant Summary collapse
- ENVIRONMENTS =
Array with Bing Ads API environments:
sandbox
andproduction
['sandbox', 'production']
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
Class Method Summary collapse
-
.hash_instance ⇒ Object
Public : Returns the config file as an Hash instance .
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
Public : Constructor .
-
#key ⇒ Object
Constants.
-
#service_wsdl(environment, service) ⇒ Object
Public : Returns a String with WSDL url for the service indicated .
Constructor Details
#initialize ⇒ Config
Public : Constructor
- Author
25 26 27 |
# File 'lib/bing-ads-api/config.rb', line 25 def initialize @config = YAML.load_file(File.join(File.dirname(__FILE__),"../bing-ads-api.yml")) end |
Instance Attribute Details
#config ⇒ Object
Returns the value of attribute config.
19 20 21 |
# File 'lib/bing-ads-api/config.rb', line 19 def config @config end |
Class Method Details
.hash_instance ⇒ Object
Public : Returns the config file as an Hash instance
- Author
- Returns
-
Hash
34 35 36 |
# File 'lib/bing-ads-api/config.rb', line 34 def self.hash_instance instance.config end |
Instance Method Details
#key ⇒ Object
Constants
39 40 41 42 43 44 45 46 |
# File 'lib/bing-ads-api/config.rb', line 39 @config['constants'].each do |key, value| define_method("#{key.to_s}_constants") do |constant=nil| value[constant.to_s] if constant value end end |
#service_wsdl(environment, service) ⇒ Object
Public : Returns a String with WSDL url for the service indicated
- Author
Parameters
environment - Bing Environment: ‘sandbox’ or ‘production’ service - service name
Examples
config.service_wsdl(:sandbox, :campaign_management)
# => "https://api.sandbox.bingads.microsoft.com/Api/Advertiser/CampaignManagement/v9/CampaignManagementService.svc?singleWsdl"
- Returns
-
returns
- Raises
-
exception
63 64 65 66 67 68 69 70 71 |
# File 'lib/bing-ads-api/config.rb', line 63 def service_wsdl(environment, service) if (ENVIRONMENTS.include?(environment.to_s)) if @config['wsdl'][environment.to_s].include?(service.to_s) return @config['wsdl'][environment.to_s][service.to_s] end raise "Unknown service '#{service.to_s}'. Available services: #{@config['wsdl'][environment.to_s].keys.join(", ")}" end raise "Invalid environment: #{environment}. Value should be 'sandbox' or 'production'" end |