Class: BingAdsApi::Config

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/bing-ads-api/config.rb

Overview

Public : Helper class for configuration issues like WSDL URLs and constants

Author

[email protected]

Examples

class_usage 
# => class_usage_return

Constant Summary collapse

ENVIRONMENTS =

Array with Bing Ads API environments: sandbox and production

['sandbox', 'production']

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Public : Constructor

Author

[email protected]



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

#configObject

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_instanceObject

Public : Returns the config file as an Hash instance

Author

[email protected]

Returns

Hash



34
35
36
# File 'lib/bing-ads-api/config.rb', line 34

def self.hash_instance
	instance.config
end

Instance Method Details

#keyObject

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

[email protected]

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