Class: SoapyBing::Ads::Bulk::Campaigns

Inherits:
Object
  • Object
show all
Defined in:
lib/soapy_bing/ads/bulk/campaigns.rb

Constant Summary collapse

DEFAULT_ENTITIES =
%w(CampaignTargets Ads).freeze
DEFAULT_POLLING_SETTINGS =
{
  tries: 20,
  sleep: ->(n) { n < 7 ? 2**n : 120 }
}.freeze
NotCompleted =
Class.new(StandardError)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Campaigns

Returns a new instance of Campaigns.



15
16
17
18
19
20
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 15

def initialize(options)
  @oauth_credentials = options.fetch(:oauth_credentials)
  @account = options.fetch(:account)
  @entities = options.fetch(:entities) || DEFAULT_ENTITIES
  @polling_settings = DEFAULT_POLLING_SETTINGS.merge(options.fetch(:polling_settings) || {})
end

Instance Attribute Details

#accountObject (readonly)

Returns the value of attribute account.



13
14
15
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 13

def 
  @account
end

#entitiesObject (readonly)

Returns the value of attribute entities.



13
14
15
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 13

def entities
  @entities
end

#oauth_credentialsObject (readonly)

Returns the value of attribute oauth_credentials.



13
14
15
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 13

def oauth_credentials
  @oauth_credentials
end

#polling_settingsObject (readonly)

Returns the value of attribute polling_settings.



13
14
15
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 13

def polling_settings
  @polling_settings
end

#statusObject (readonly)

Returns the value of attribute status.



13
14
15
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 13

def status
  @status
end

Instance Method Details

#fetch_statusObject



33
34
35
36
37
38
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 33

def fetch_status
  @status = Soap::Request::GetBulkDownloadStatusRequest
    .new(context: context.merge(request_id: download_request_id))
    .perform
    .payload
end

#result_file_urlObject



26
27
28
29
30
31
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 26

def result_file_url
  @result_file_url ||= begin
    wait_status_complete
    status['ResultFileUrl']
  end
end

#rowsObject



22
23
24
# File 'lib/soapy_bing/ads/bulk/campaigns.rb', line 22

def rows
  @rows ||= Parsers::CSVParser.new(Helpers::ZipDownloader.new(result_file_url).read).rows
end