Class: Braintree::DocumentUploadGateway

Inherits:
Object
  • Object
show all
Includes:
BaseModule
Defined in:
lib/braintree/document_upload_gateway.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BaseModule

included

Methods included from BaseModule::Methods

#copy_instance_variables_from_object, #return_object_or_raise, #set_instance_variables_from_hash, #singleton_class

Constructor Details

#initialize(gateway) ⇒ DocumentUploadGateway

Returns a new instance of DocumentUploadGateway.



5
6
7
8
9
# File 'lib/braintree/document_upload_gateway.rb', line 5

def initialize(gateway)
  @gateway = gateway
  @config = gateway.config
  @config.assert_has_access_token_or_keys
end

Class Method Details

._create_signatureObject



20
21
22
23
24
25
# File 'lib/braintree/document_upload_gateway.rb', line 20

def self._create_signature
  [
    :kind,
    :file
  ]
end

Instance Method Details

#_do_create(path, params, file) ⇒ Object



27
28
29
30
31
32
33
34
35
36
# File 'lib/braintree/document_upload_gateway.rb', line 27

def _do_create(path, params, file)
  response = @config.http.post("#{@config.base_merchant_path}#{path}", params, file)
  if response[:document_upload]
    SuccessfulResult.new(:document_upload => DocumentUpload._new(response[:document_upload]))
  elsif response[:api_error_response]
    ErrorResult.new(@gateway, response[:api_error_response])
  else
    raise UnexpectedError, "expected :document_upload or :api_error_response"
  end
end

#create(attributes) ⇒ Object



11
12
13
14
# File 'lib/braintree/document_upload_gateway.rb', line 11

def create(attributes)
  Util.verify_keys(DocumentUploadGateway._create_signature, attributes)
  _do_create "/document_uploads", {"document_upload[kind]" => attributes[:kind]}, attributes[:file]
end

#create!(*args) ⇒ Object



16
17
18
# File 'lib/braintree/document_upload_gateway.rb', line 16

def create!(*args)
  return_object_or_raise(:document_upload) { create(*args) }
end