Sha256: 3f32699bbd13102f7595aec3f1824356affed2b377c6649188561f36d9d77ede

Contents?: true

Size: 1.31 KB

Versions: 2

Compression:

Stored size: 1.31 KB

Contents

# frozen_string_literal: true

require 'httparty'
require 'json'

module CampaignByMsg91
  # Campaign Class
  class Campaign
    CAMPAIGNS_BASE_URL = 'https://control.msg91.com/api/v5/campaign/api/campaigns'

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

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

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

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

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

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

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
campaign_by_msg91-0.1.6 lib/campaign_by_msg91/campaign.rb
campaign_by_msg91-0.1.5 lib/campaign_by_msg91/campaign.rb