Class: CampaignByMsg91::Campaign

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

Overview

Campaign Class

Constant Summary collapse

CAMPAIGNS_BASE_URL =
'https://control.msg91.com/api/v5/campaign/api/campaigns'

Instance Method Summary collapse

Constructor Details

#initializeCampaign

Returns a new instance of Campaign.



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

def initialize
  @authkey = CampaignByMsg91.configuration.auth_key
  raise 'Set authkey in config/initializers/campaign_by_msg91.rb' if !@authkey || @authkey.empty?
end

Instance Method Details

#indexObject



16
17
18
19
20
21
22
23
# File 'lib/campaign_by_msg91/campaign.rb', line 16

def index
  uri = '/'
  headers = {
    authkey: @authkey
  }

  HTTParty.get("#{CAMPAIGNS_BASE_URL}#{uri}", headers: headers).parsed_response
end

#index_fields(campaign_slug) ⇒ Object



25
26
27
28
29
30
31
32
# File 'lib/campaign_by_msg91/campaign.rb', line 25

def index_fields(campaign_slug)
  uri = "/#{campaign_slug}/fields"
  headers = {
    authkey: @authkey
  }

  HTTParty.get("#{CAMPAIGNS_BASE_URL}#{uri}", headers: headers).parsed_response
end

#run_campaign(campaign_slug, request_body) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/campaign_by_msg91/campaign.rb', line 43

def run_campaign(campaign_slug, request_body)
  uri = "/#{campaign_slug}/run?pluginsource=600"
  headers = {
    authkey: @authkey,
    'Content-Type': 'application/json'
  }

  HTTParty.post("#{CAMPAIGNS_BASE_URL}#{uri}", body: request_body, headers: headers).parsed_response
end

#show_request_body(campaign_slug) ⇒ Object



34
35
36
37
38
39
40
41
# File 'lib/campaign_by_msg91/campaign.rb', line 34

def show_request_body(campaign_slug)
  uri = "/#{campaign_slug}/snippets"
  headers = {
    authkey: @authkey
  }

  HTTParty.get("#{CAMPAIGNS_BASE_URL}#{uri}", headers: headers).parsed_response
end