Class: Plivo::Resources::CampaignInterface

Inherits:
Base::ResourceInterface show all
Defined in:
lib/plivo/resources/campaign.rb

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Method Summary collapse

Methods included from Utils

GetSortedQueryParamString?, compute_signatureV3?, expected_type?, expected_value?, generate_url?, getMapFromQueryString?, is_one_among_string_url?, multi_valid_param?, raise_invalid_request, valid_account?, valid_date_format?, valid_mainaccount?, valid_multiple_destination_integers?, valid_multiple_destination_nos?, valid_param?, valid_range?, valid_signature?, valid_signatureV3?, valid_subaccount?, valid_url?

Constructor Details

#initialize(client, resource_list_json = nil) ⇒ CampaignInterface

Returns a new instance of CampaignInterface.



20
21
22
23
24
25
# File 'lib/plivo/resources/campaign.rb', line 20

def initialize(client, resource_list_json = nil)
  @_name = '10dlc/Campaign'
  @_resource_type = Campaign
  @_identifier_string = 'campaign_id'
  super
end

Instance Method Details

#create(options = nil) ⇒ Object

Create a new Camapign



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/plivo/resources/campaign.rb', line 66

def create(options=nil)
  valid_param?(:options, options, Hash, true)
  if not options[:brand_id]
    raise_invalid_request("brand_id must be provided")
  end
  if not options[:vertical]
    raise_invalid_request("vertical must be provided")
  end
  if not options[:usecase]
    raise_invalid_request("usecase must be provided")
  end
  if not options[:message_flow]
    raise_invalid_request("message_flow must be provided")
  end
  if not options[:help_message]
    raise_invalid_request("help_message must be provided")
  end
  if not options[:optout_message]
    raise_invalid_request("optout_message must be provided")
  end
  perform_create(options)
end

#delete(campaign_id) ⇒ Object

Delete Campaign

Parameters:

  • campaign_id (String)


147
148
149
150
# File 'lib/plivo/resources/campaign.rb', line 147

def delete(campaign_id)
  valid_param?(:campaign_id, campaign_id, [String, Symbol], true)
  perform_delete(campaign_id)
end

#get(campaign_id) ⇒ Campaign

Get an Campaign

Parameters:

  • campaign_id (String)

Returns:



31
32
33
34
# File 'lib/plivo/resources/campaign.rb', line 31

def get(campaign_id)
  valid_param?(:campaign_id, campaign_id, [String, Symbol], true)
  perform_get(campaign_id)
end

#get_number(campaign_id, number) ⇒ Object

get campaign number



133
134
135
136
# File 'lib/plivo/resources/campaign.rb', line 133

def get_number(campaign_id, number)
  action = campaign_id + '/Number/' + number
  perform_action_with_identifier(action, 'GET', nil)
end

#get_numbers(campaign_id, options = nil) ⇒ Object

get campaign numbers



112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
# File 'lib/plivo/resources/campaign.rb', line 112

def get_numbers(campaign_id, options = nil)
  params = {}
  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer, Integer], true)
      params[param] = options[param]
    end
  end
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end
  action = campaign_id + '/Number'
  perform_action_with_identifier(action, 'GET', params)
end

#list(options = nil) ⇒ Hash

List all Campaign

Parameters:

  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :brand (String)
  • :usecase (Status)
  • :limit (Status)
  • :offset (Status)

Returns:

  • (Hash)


44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/plivo/resources/campaign.rb', line 44

def list(options=nil)
  return perform_list_without_object if options.nil?
  
  params = {}
  %i[usecase brand limit offset].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                             [String, Integer], true)
      params[param] = options[param]
    end
  end
  if options.key?(:limit) && (options[:limit] > 20 || options[:limit] <= 0)
    raise_invalid_request('The maximum number of results that can be '\
    "fetched is 20. limit can't be more than 20 or less than 1")
  end
  if options.key?(:offset) && options[:offset] < 0
    raise_invalid_request("Offset can't be negative")
  end  
  perform_list_without_object(params)
end

campaign number link



101
102
103
104
105
106
107
108
# File 'lib/plivo/resources/campaign.rb', line 101

def number_link(options=nil)
  valid_param?(:options, options, Hash, true)
  if not options[:campaign_id]
    raise_invalid_request("campaign_id must be provided")
  end
  action = options[:campaign_id] + '/Number'
  perform_action_with_identifier(action, 'POST', options)            
end

unlink campaign number



140
141
142
143
# File 'lib/plivo/resources/campaign.rb', line 140

def number_unlink(campaign_id, number, options = nil)
  action = campaign_id + '/Number/' + number
  perform_action_with_identifier(action, 'DELETE', nil)
end

#update(campaign_id, options = nil) ⇒ Object

Update Camapign



90
91
92
93
94
95
96
97
# File 'lib/plivo/resources/campaign.rb', line 90

def update(campaign_id, options=nil)
  valid_param?(:options, options, Hash, true)
  if not campaign_id
    raise_invalid_request("campaign_id must be provided")
  end
  action = campaign_id
  perform_action_with_identifier(action, 'POST', options)
end