Class: Plivo::Resources::AddressInterface
- Inherits:
-
Base::ResourceInterface
- Object
- Base::ResourceInterface
- Plivo::Resources::AddressInterface
- Defined in:
- lib/plivo/resources/addresses.rb
Constant Summary
Constants included from Utils
Instance Method Summary collapse
-
#create(country_iso, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, address_proof_type, file_to_upload = nil, options = nil) ⇒ Address
Create a new address.
-
#delete(address_id) ⇒ Object
Delete an address.
- #each ⇒ Object
-
#get(address_id) ⇒ Address
Get an address.
-
#initialize(client, resource_list_json = nil) ⇒ AddressInterface
constructor
A new instance of AddressInterface.
-
#list(options = nil) ⇒ Hash
List all addresses.
-
#update(address_id, file_to_upload = nil, options = nil) ⇒ Address
Update an address.
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) ⇒ AddressInterface
Returns a new instance of AddressInterface.
96 97 98 99 100 101 |
# File 'lib/plivo/resources/addresses.rb', line 96 def initialize(client, resource_list_json = nil) @_name = 'Verification/Address' @_resource_type = Address @_identifier_string = 'id' super end |
Instance Method Details
#create(country_iso, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, address_proof_type, file_to_upload = nil, options = nil) ⇒ Address
Create a new address
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
# File 'lib/plivo/resources/addresses.rb', line 183 def create(country_iso, salutation, first_name, last_name, address_line1, address_line2, city, region, postal_code, address_proof_type, file_to_upload=nil, =nil) valid_param?(:country_iso, country_iso, [String, Symbol], true) valid_param?(:salutation, salutation, [String, Symbol], true, ['Mr', 'Ms', :Ms, :Mr]) valid_param?(:first_name, first_name, [String, Symbol], true) valid_param?(:last_name, last_name, [String, Symbol], true) valid_param?(:address_line1, address_line1, [String, Symbol], true) valid_param?(:address_line2, address_line2, [String, Symbol], true) valid_param?(:city, city, [String, Symbol], true) valid_param?(:region, region, [String, Symbol], true) valid_param?(:postal_code, postal_code, [String, Symbol], true) valid_param?(:address_proof_type, address_proof_type, [String, Symbol], true, ['national_id', 'passport', 'business_id', 'NIF', 'NIE', 'DNI', 'others', :national_id, :passport, :business_id, :NIF, :NIE, :DNI, :others]) params = { country_iso: country_iso, salutation: salutation, first_name: first_name, last_name: last_name, address_line1: address_line1, address_line2: address_line2, city: city, region: region, postal_code: postal_code, address_proof_type: address_proof_type } if country_iso == 'ES' valid_param?(:fiscal_identification_code, [:fiscal_identification_code], [String, Symbol], true) params[:fiscal_identification_code] = [:fiscal_identification_code] end if country_iso == 'DK' valid_param?(:street_code, [:street_code], [String, Symbol], true) valid_param?(:municipal_code, [:municipal_code], [String, Symbol], true) params[:street_code] = [:street_code] params[:municipal_code] = [:municipal_code] end unless file_to_upload.nil? file_extension = file_to_upload.split('.')[-1] content_type = case file_extension when 'jpeg' then 'image/jpeg' when 'jpg' then 'image/jpeg' when 'png' then 'image/png' when 'pdf' then 'application/pdf' else raise_invalid_request("#{file_extension} is not yet supported for upload") end params[:file] = Faraday::UploadIO.new(file_to_upload, content_type) end %i[alias fiscal_identification_code street_code municipal_code callback_url] .each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end %i[auto_correct_address] .each do |param| if .key?(param) && valid_param?(param, [param], nil, true, [true, false]) params[param] = [param] end end perform_create(params, true) end |
#delete(address_id) ⇒ Object
Delete an address
285 286 287 288 289 |
# File 'lib/plivo/resources/addresses.rb', line 285 def delete(address_id) valid_param?(:address_id, address_id, [String, Symbol], true) Address.new(@_client, resource_id: address_id).delete end |
#each ⇒ Object
291 292 293 294 295 296 297 298 299 |
# File 'lib/plivo/resources/addresses.rb', line 291 def each offset = 0 loop do address_list = list(offset: offset) address_list[:objects].each { |address| yield address } offset += 20 return unless address_list.length == 20 end end |
#get(address_id) ⇒ Address
Get an address
107 108 109 110 |
# File 'lib/plivo/resources/addresses.rb', line 107 def get(address_id) valid_param?(:address_id, address_id, [String, Symbol], true) perform_get(address_id) end |
#list(options = nil) ⇒ Hash
List all addresses
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/plivo/resources/addresses.rb', line 123 def list(=nil) return perform_list if .nil? params = {} %i[country_iso customer_name alias].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true) params[param] = [param] end end %i[verification_status validation_status].each do |param| if .key?(param) && valid_param?(param, [param], [String, Symbol], true, ['pending', 'accepted', 'rejected', :pending, :accepted, :rejected]) params[param] = [param] end end %i[offset limit].each do |param| if .key?(param) && valid_param?(param, [param], [Integer], true) params[param] = [param] end end 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 if .key?(:offset) && [:offset] < 0 raise_invalid_request("Offset can't be negative") end perform_list(params) end |