Class: Plivo::Resources::PhoneNumberCompliancesInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::PhoneNumberCompliancesInterface
- Defined in:
- lib/plivo/resources/phone_number_compliance.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
-
#create(data_hash, documents = nil) ⇒ Response
Create a phone number compliance application.
-
#delete(compliance_id) ⇒ Object
Delete a phone number compliance application.
-
#get(compliance_id, options = nil) ⇒ PhoneNumberCompliance
Get a phone number compliance application.
-
#initialize(client, resource_list_json = nil) ⇒ PhoneNumberCompliancesInterface
constructor
A new instance of PhoneNumberCompliancesInterface.
-
#list(options = nil) ⇒ Hash
List phone number compliance applications.
-
#update(compliance_id, data_hash, documents = nil) ⇒ PhoneNumberCompliance
Update a phone number compliance application.
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.
98 99 100 101 102 103 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 98 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
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 110 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
234 235 236 237 238 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 234 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
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 133 def get(compliance_id, = nil) valid_param?(:compliance_id, compliance_id, [String, Symbol], true) params = {} if valid_param?(:options, , Hash, true) if .key?(:expand) && valid_param?(:expand, [:expand], [String, Symbol], false) params[:expand] = [:expand] end end response_json = @_client.send_request(@_resource_uri + compliance_id.to_s + '/', 'GET', params, nil, false, is_voice_request: false) # Extract the compliance wrapper returned by the API compliance_data = response_json['compliance'] || response_json compliance_data['api_id'] = response_json['api_id'] if response_json['api_id'] @_resource_type.new(@_client, resource_json: compliance_data) end |
#list(options = nil) ⇒ Hash
List phone number compliance applications
162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 162 def list( = nil) params = {} if valid_param?(:options, , Hash, true) %i[status country_iso number_type user_type alias expand].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], false) params[param] = [param] end end %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer], false) params[param] = [param] end end raise_invalid_request("Offset can't be negative") if .key?(:offset) && [:offset] < 0 if .key?(:limit) && ([:limit] > 20 || [: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 end response_json = @_client.send_request(@_resource_uri, 'GET', params, nil, false, is_voice_request: false) # Remap 'compliances' to 'objects' for base class compatibility if response_json.key?('compliances') response_json['objects'] = response_json.delete('compliances') end parse_and_set(response_json) { api_id: @api_id, meta: @_meta, objects: @_resource_list } end |
#update(compliance_id, data_hash, documents = nil) ⇒ PhoneNumberCompliance
Update a phone number compliance application
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/plivo/resources/phone_number_compliance.rb', line 210 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 |