Class: Plivo::Resources::Address

Inherits:
Base::Resource show all
Defined in:
lib/plivo/resources/addresses.rb

Constant Summary

Constants included from Utils

Utils::TYPE_WHITELIST

Instance Attribute Summary

Attributes inherited from Base::Resource

#id

Instance Method Summary collapse

Methods included from Utils

expected_type?, expected_value?, raise_invalid_request, valid_account?, valid_mainaccount?, valid_param?, valid_signature?, valid_subaccount?

Constructor Details

#initialize(client, options = nil) ⇒ Address

Returns a new instance of Address.



6
7
8
9
10
# File 'lib/plivo/resources/addresses.rb', line 6

def initialize(client, options = nil)
  @_name = 'Verification/Address'
  @_identifier_string = 'id'
  super
end

Instance Method Details

#deleteObject



12
13
14
# File 'lib/plivo/resources/addresses.rb', line 12

def delete
  perform_delete
end

#to_sObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/plivo/resources/addresses.rb', line 71

def to_s
  {
    account: @account,
    address_line1: @address_line1,
    address_line2: @address_line2,
    alias: @alias,
    api_id: @api_id,
    city: @city,
    country_iso: @country_iso,
    document_details: @document_details,
    first_name: @first_name,
    id: @id,
    last_name: @last_name,
    postal_code: @postal_code,
    region: @region,
    salutation: @salutation,
    subaccount: @subaccount,
    url: @url,
    validation_status: @validation_status,
    verification_status: @verification_status
  }.to_s
end

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

Update an address

Parameters:

  • 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:



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/plivo/resources/addresses.rb', line 33

def update(file_to_upload = nil, options = nil)
  params = {}

  unless options.nil?
    %i[salutation first_name last_name country_iso address_line1 address_line2 city region postal_code alias 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
  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

  return perform_update(params, true)
end