Class: Asaas::Api::Document

Inherits:
Base
  • Object
show all
Defined in:
lib/asaas/api/document.rb

Instance Attribute Summary

Attributes inherited from Base

#endpoint, #errors, #meta, #route, #success, #token

Instance Method Summary collapse

Methods inherited from Base

#create, #delete, #extract_meta, #get, #list, #update

Constructor Details

#initialize(token) ⇒ Document

Returns a new instance of Document.



5
6
7
# File 'lib/asaas/api/document.rb', line 5

def initialize(token)
  super(token, 2, '/documents')
end

Instance Method Details

#upload(document_type, group_type, file) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/asaas/api/document.rb', line 9

def upload(document_type, group_type, file)
  group_types = %w[ASAAS_ACCOUNT_OWNER PARTNER LIMITED_COMPANY]
  types = %w[IDENTIFICATION SOCIAL_CONTRACT]

  raise ArgumentError, 'Wrong document_type' unless types.include? document_type
  raise ArgumentError, 'Wrong group_type' unless group_types.include? group_type

  @response = Typhoeus.post(URI(endpoint + route).to_s,
                            body: {
                              documentType: document_type,
                              documentGroupType: group_type,
                              documentFile: file
                            },
                            headers: {
                              'access_token': @token || Asaas::Configuration.token,
                              'Content-Type': 'multipart/form-data'
                            },
                            verbose: Asaas::Configuration.debug
              )
  @response
end