Module: BingAdsApi::Helpers::TimeHelper

Included in:
PerformanceReportRequest
Defined in:
lib/bing-ads-api/data/reporting/helpers/time_helper.rb

Overview

Public : Utility module

Author

[email protected]

Constant Summary collapse

TIME_PERIODS =

Valid languages for reports

BingAdsApi::Config.instance.
reporting_constants['time_periods']

Instance Method Summary collapse

Instance Method Details

#time_to_hash(keys_case) ⇒ Object

Public : Return the time attribute of the ReportRequest as a valid Hash for SOAP requests

Author

[email protected]

keys_case - specifies the keys_case for the hash: :underscore or :camelcase

Returns

Hash

Raises:

  • (Exception)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/bing-ads-api/data/reporting/helpers/time_helper.rb', line 44

def time_to_hash(keys_case)
	raise Exception.new("Invalid time value: nil") if self.time.nil?
	
	# Custom date range
	if time.is_a?(Hash)
		return {
			get_attribute_key("custom_date_range_end", keys_case) => {
				get_attribute_key("day", keys_case) => self.time[:custom_date_range_end][:day],
				get_attribute_key("month", keys_case) => self.time[:custom_date_range_end][:month],
				get_attribute_key("year", keys_case) => self.time[:custom_date_range_end][:year],
				
			},
			get_attribute_key("custom_date_range_start", keys_case) => {
				get_attribute_key("day", keys_case) => self.time[:custom_date_range_start][:day],
				get_attribute_key("month", keys_case) => self.time[:custom_date_range_start][:month],
				get_attribute_key("year", keys_case) => self.time[:custom_date_range_start][:year],
			}
		}
	# Time periods
	else
		return TIME_PERIODS[time.to_s]
	end
end

#valid_time(time) ⇒ Object

Public : Validates the time attribute present in some report request

Author

[email protected]

time - Hash with the time attribute for the report request

Returns

true if validation is ok, raises Exception otherwise

Raises

Exception if custom date range is bad informed, or if time periods specified is unknown



24
25
26
27
28
29
30
31
32
33
34
# File 'lib/bing-ads-api/data/reporting/helpers/time_helper.rb', line 24

def valid_time(time)
	# Custom date range
	if time.is_a?(Hash)
		raise Exception.new("Invalid time: missing :custom_date_range_start key") if !time.key?(:custom_date_range_start)
		raise Exception.new("Invalid time: missing :custom_date_range_end key")  if !time.key?(:custom_date_range_end)
	# Time periods
	else
		return TIME_PERIODS.key?(time.to_s)
	end
	return true
end