Class: Plivo::Resources::PhoneNumberCompliancesInterface

Inherits:
Base::ResourceInterface show all
Defined in:
lib/plivo/resources/phone_number_compliance.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) ⇒ PhoneNumberCompliancesInterface

Returns a new instance of PhoneNumberCompliancesInterface.



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

def initialize(client, resource_list_json = nil)
  @_name = 'PhoneNumber/Compliance'
  @_resource_type = PhoneNumberCompliance
  @_identifier_string = 'compliance_id'
  super
end

Instance Method Details

#create(data_hash, documents = nil) ⇒ Response

Create a phone number compliance application

Parameters:

  • data_hash (Hash)
    • compliance data (country_iso, number_type, alias, end_user, documents, etc.)

  • documents (Array) (defaults to: nil)
    • list of local file paths for document uploads (optional)

Returns:

  • (Response)


104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/plivo/resources/phone_number_compliance.rb', line 104

def create(data_hash, documents = nil)
  params = { data: JSON.generate(data_hash) }
  if documents
    documents.each_with_index do |filepath, index|
      file_extension = filepath.split('.')[-1]
      content_type = case file_extension
                     when 'jpeg', 'jpg' then 'image/jpeg'
                     when 'png' then 'image/png'
                     when 'pdf' then 'application/pdf'
                     else raise_invalid_request("#{file_extension} is not supported")
                     end
      params["documents[#{index}].file"] = Faraday::UploadIO.new(filepath, content_type)
    end
  end
  perform_create(params, true)
end

#delete(compliance_id) ⇒ Object

Delete a phone number compliance application

Parameters:

  • compliance_id (String)


211
212
213
214
215
# File 'lib/plivo/resources/phone_number_compliance.rb', line 211

def delete(compliance_id)
  valid_param?(:compliance_id, compliance_id, [String, Symbol], true)
  PhoneNumberCompliance.new(@_client,
                  resource_id: compliance_id).delete
end

#get(compliance_id, options = nil) ⇒ PhoneNumberCompliance

Get a phone number compliance application

Parameters:

  • compliance_id (String)
  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :expand (String)

Returns:



127
128
129
130
131
132
133
134
135
136
137
138
# File 'lib/plivo/resources/phone_number_compliance.rb', line 127

def get(compliance_id, options = nil)
  valid_param?(:compliance_id, compliance_id, [String, Symbol], true)
  params = {}
  if options
    valid_param?(:options, options, Hash, true)
    if options.key?(:expand) &&
       valid_param?(:expand, options[:expand], [String, Symbol], false)
      params[:expand] = options[:expand]
    end
  end
  perform_get(compliance_id, params)
end

#list(options = nil) ⇒ Hash

List phone number compliance applications

Parameters:

  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :limit (Int)
  • :offset (Int)
  • :status (String)
  • :country_iso (String)
  • :number_type (String)
  • :user_type (String)
  • :alias (String)
  • :expand (String)

Returns:

  • (Hash)


152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/plivo/resources/phone_number_compliance.rb', line 152

def list(options = nil)
  return perform_list if options.nil?
  valid_param?(:options, options, Hash, true)

  params = {}
  %i[status country_iso number_type user_type alias expand].each do |param|
    if options.key?(param) &&
       valid_param?(param, options[param], [String, Symbol], false)
      params[param] = options[param]
    end
  end

  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [Integer], false)
      params[param] = options[param]
    end
  end

  raise_invalid_request("Offset can't be negative") if options.key?(:offset) && options[:offset] < 0

  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

  perform_list(params)
end

#update(compliance_id, data_hash, documents = nil) ⇒ PhoneNumberCompliance

Update a phone number compliance application

Parameters:

  • compliance_id (String)
  • data_hash (Hash)
    • compliance data to update

  • documents (Array) (defaults to: nil)
    • list of local file paths for document uploads (optional)

Returns:



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/plivo/resources/phone_number_compliance.rb', line 187

def update(compliance_id, data_hash, documents = nil)
  valid_param?(:compliance_id, compliance_id, [String, Symbol], true)

  params = { data: JSON.generate(data_hash) }
  if documents
    documents.each_with_index do |filepath, index|
      file_extension = filepath.split('.')[-1]
      content_type = case file_extension
                     when 'jpeg', 'jpg' then 'image/jpeg'
                     when 'png' then 'image/png'
                     when 'pdf' then 'application/pdf'
                     else raise_invalid_request("#{file_extension} is not supported")
                     end
      params["documents[#{index}].file"] = Faraday::UploadIO.new(filepath, content_type)
    end
  end

  PhoneNumberCompliance.new(@_client,
                  resource_id: compliance_id).update(params)
end