Class: Wavix::Numbers::Papers::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/wavix/numbers/papers/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(client:) ⇒ void

Parameters:



10
11
12
# File 'lib/wavix/numbers/papers/client.rb', line 10

def initialize(client:)
  @client = client
end

Instance Method Details

#upload(request_options: {}, **params) ⇒ Array[Wavix::Types::NumberDocument]

Uploads a verification document for one or more phone numbers. Uploaded files must meet the following requirements:

  • Allowed formats: PNG, JPG, JPEG, TIFF, BMP, or PDF
  • Maximum file size: 10 MB
  • Files can't be password protected
  • PDF files must not contain digital signatures

Parameters:

  • request_options (Hash) (defaults to: {})
  • params (void)

Options Hash (request_options:):

  • :base_url (String)
  • :additional_headers (Hash{String => Object})
  • :additional_query_parameters (Hash{String => Object})
  • :additional_body_parameters (Hash{String => Object})
  • :timeout_in_seconds (Integer)

Returns:

Raises:

  • (error_class)


30
31
32
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
# File 'lib/wavix/numbers/papers/client.rb', line 30

def upload(request_options: {}, **params)
  params = Wavix::Internal::Types::Utils.normalize_keys(params)
  body = Internal::Multipart::FormData.new

  if params[:did_ids]
    body.add(
      name: "did_ids",
      value: params[:did_ids]
    )
  end
  body.add_part(params[:doc_attachment].to_form_data_part(name: "doc_attachment")) if params[:doc_attachment]
  if params[:doc_id]
    body.add(
      name: "doc_id",
      value: params[:doc_id]
    )
  end

  request = Wavix::Internal::Multipart::Request.new(
    base_url: request_options[:base_url],
    method: "POST",
    path: "v1/numbers/papers",
    body: body,
    request_options: request_options
  )
  begin
    response = @client.send(request)
  rescue Net::HTTPRequestTimeout
    raise Wavix::Errors::TimeoutError
  end
  code = response.code.to_i
  return if code.between?(200, 299)

  error_class = Wavix::Errors::ResponseError.subclass_for_code(code)
  raise error_class.new(response.body, code: code)
end