Class: Mirakl::Requests::DR74

Inherits:
Object
  • Object
show all
Includes:
ApiOperations::Request
Defined in:
lib/mirakl/requests/dr74.rb

Constant Summary collapse

API_PATH =
'document-request/documents/upload'

Class Method Summary collapse

Methods included from ApiOperations::Request

included, #request

Class Method Details

.call(params = {}, opts = {}) ⇒ Object

Raises:

  • (ArgumentError)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/mirakl/requests/dr74.rb', line 10

def self.call(params = {}, opts = {})

  raise ArgumentError, "files must be an array" if params[:files].nil? ||
    !params[:files].is_a?(Array)

  params[:files] = params[:files].map do |fp|
    unless fp.respond_to?(:read)
      raise ArgumentError, "each file must respond to `#read`"
    end

    Faraday::FilePart.new(fp, 'application/pdf', File.basename(fp))
  end

  # params[:files] = params[:files][0]

  raise ArgumentError, "documents_input must be a Hash" if params[:documents_input].nil? ||
    !params[:documents_input].is_a?(Hash)

  params[:documents_input] = Faraday::ParamPart.new(params[:documents_input].to_json, 'application/json')

  puts params.inspect

  opts = {
    content_type: "multipart/form-data",
  }.merge(Util.normalize_opts(opts))

  resp, opts = request(:post, API_PATH, params, opts)
  obj = MiraklObject.construct_from(resp.data, opts)

  obj
end