Class: EngagingNetworks::Campaign

Inherits:
Base
  • Object
show all
Defined in:
lib/engaging_networks/campaign.rb

Instance Method Summary collapse

Methods inherited from Base

#action_path, #data_path, #export_path, #import_path, #scrape

Instance Method Details

#create(name:, description:, ajax_enabled: true) ⇒ Object



11
12
13
# File 'lib/engaging_networks/campaign.rb', line 11

def create(name:, description:, ajax_enabled: true)
  scrape.create_campaign(name: name, description: description, ajax_enabled: ajax_enabled)
end

#duplicate(a) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/engaging_networks/campaign.rb', line 16

def duplicate(a)
  # accept either hashes or objects as input
  action = if a.is_a?(Hash)
        DuplicateCampaignAction.new(a)
      else
        a
      end

  # if the token is blank, default it to the configured private token
  action.token = client.connection.configuration.options[:private_token] if action.token.blank?

  if action.valid?
    response = client.request_with_options(:post, import_path, action.to_params, content_type: 'multipart/form-data')
    if response.body =~ /uploaded successfully/
      action.job_id = /# is (\d*)/.match(response.body)[1]
    else
      raise CampaignDuplicationError.new("error while duplicating campaign: #{response.body}")
    end
  end

  action
end

#get(campaignId) ⇒ Object



6
7
8
9
# File 'lib/engaging_networks/campaign.rb', line 6

def get(campaignId)
  client.get_request(data_path, {service: 'EaCampaignInfo', campaignId: campaignId,
        token_type: EngagingNetworks::Request::MultiTokenAuthentication::PUBLIC})
end

#search(campaign_name) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/engaging_networks/campaign.rb', line 39

def search(campaign_name)
  response = client.get_request(data_path, {service: 'EaCampaignInfo', token_type: EngagingNetworks::Request::MultiTokenAuthentication::PUBLIC})
  if response.obj.is_a? EngagingNetworks::Response::Collection
    response.obj.objects.find { |elem| elem.campaignName == campaign_name }
  elsif response.obj.is_a? EngagingNetworks::Response::Object
    response.obj ? response.obj.campaignName == campaign_name : nil
  else
    nil
  end
end