Class: Msg91::Services::CampaignService

Inherits:
Object
  • Object
show all
Defined in:
lib/msg91/services/campaign_service.rb

Constant Summary collapse

BASE_URL =

Base URL for Msg91 API

'https://control.msg91.com/api/v5/campaign/api/'

Instance Method Summary collapse

Constructor Details

#initialize(auth_key) ⇒ CampaignService

Returns a new instance of CampaignService.



10
11
12
# File 'lib/msg91/services/campaign_service.rb', line 10

def initialize(auth_key)
  @auth_key = auth_key # Initializing the Msg91 authentication key
end

Instance Method Details

#run_campaign(campaign_slug, input_data) ⇒ Object

Method to run a campaign



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/msg91/services/campaign_service.rb', line 15

def run_campaign(campaign_slug, input_data)
  begin
    verify_input_data(input_data) # Validate input data for the campaign
    mapping_data = verify_and_get_campaign_mappings(campaign_slug) # Retrieve campaign mappings
    send_campaign = { data: create_send_to_body(input_data, mapping_data) } # Prepare campaign payload
    response = send_campaign_request(campaign_slug, send_campaign) # Send the campaign
  rescue => e
    raise "Exception: #{e.message}" # Handle exceptions
  end

  {
    "message" => "Campaign Run Successfully",
    "request_id" => response['request_id']
  }
end