Class: Plivo::Resources::AddressInterface

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

Parameters:

  • country_iso (String)
  • salutation (String)
  • first_name (String)
  • last_name (String)
  • address_line1 (String)
  • address_line2 (String)
  • city (String)
  • region (String)
  • postal_code (String)
  • address_proof_type (String)
  • file_to_upload (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :alias (String)
    • Alias name of the address

  • :auto_correct_address (String)
    • If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.

  • :fiscal_identification_code (String)
    • The code is valid for businesses alone

  • :street_code (String)
    • Street code of the address

  • :municipal_code (String)
    • Municipal code of the address

  • :callback_url (String)
    • The callback URL that gets the result of address creation POSTed to.

Returns:



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, options=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, options[:fiscal_identification_code], [String, Symbol], true)
    params[:fiscal_identification_code] = options[:fiscal_identification_code]
  end

  if country_iso == 'DK'
    valid_param?(:street_code, options[:street_code], [String, Symbol], true)
    valid_param?(:municipal_code, options[:municipal_code], [String, Symbol], true)

    params[:street_code] = options[:street_code]
    params[:municipal_code] = options[: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 options.key?(param) &&
        valid_param?(param, options[param], [String, Symbol], true)
      params[param] = options[param]
    end
  end

  %i[auto_correct_address]
      .each do |param|
    if options.key?(param) &&
        valid_param?(param, options[param], nil, true, [true, false])
      params[param] = options[param]
    end
  end

  perform_create(params, true)
end

#delete(address_id) ⇒ Object

Delete an address

Parameters:

  • address_id (String)


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

#eachObject



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

Parameters:

  • address_id (String)

Returns:



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

Parameters:

  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :country_iso (String)
    • Country ISO 2 code

  • :customer_name (String)
    • Name of the customer or business that is mentioned in the address

  • :alias (String)
    • Friendly name of the id proof

  • :verification_status (String)
    • The status of the address: pending. accepted, rejected, null

  • :validation_status (String)
    • The status of the address: pending. accepted, rejected, null

  • :offset (Int)
  • :limit (Int)

Returns:

  • (Hash)


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(options=nil)
  return perform_list if options.nil?

  params = {}

  %i[country_iso customer_name alias].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [String, Symbol], true)
      params[param] = options[param]
    end
  end

  %i[verification_status validation_status].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [String, Symbol], true, ['pending', 'accepted', 'rejected',
                                                                    :pending, :accepted, :rejected])
      params[param] = options[param]
    end
  end

  %i[offset limit].each do |param|
    if options.key?(param) && valid_param?(param, options[param],
                                           [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(params)
end

#update(address_id, file_to_upload = nil, options = nil) ⇒ Address

Update an address

Parameters:

  • address_id (String)
  • file_to_upload (String) (defaults to: nil)
  • options (Hash) (defaults to: nil)

Options Hash (options):

  • :salutation (String)
    • One of Mr or Ms

  • :first_name (String)
    • First name of the user for whom the address is created

  • :last_name (String)
    • Last name of the user for whom the address is created

  • :country_iso (String)
    • Country ISO 2 code

  • :address_line1 (String)
    • Building name/number

  • :address_line2 (String)
    • The street name/number of the address

  • :city (String)
    • The city of the address for which the address proof is created

  • :region (String)
    • The region of the address for which the address proof is created

  • :postal_code (String)
    • The postal code of the address that is being created

  • :alias (String)
    • Alias name of the address

  • :auto_correct_address (String)
    • If set to true, the address will be auto-corrected by the system if necessary. The param needs to be set to false explicitly so that it is not auto-corrected.

  • :callback_url (String)
    • The callback URL that gets the result of address creation POSTed to.

Returns:



277
278
279
280
# File 'lib/plivo/resources/addresses.rb', line 277

def update(address_id, file_to_upload=nil, options=nil)
  Address.new(@_client,
                  resource_id: address_id).update(file_to_upload, options)
end