Class: WavixApi::V1::Papers::Create

Inherits:
Object
  • Object
show all
Includes:
BaseMethods
Defined in:
lib/wavix_api/v1/papers/create.rb

Constant Summary collapse

CONTENT_TYPES =
{
  'jpeg' => 'image/jpeg',
  'jpg' => 'image/jpeg',
  'gif' => 'image/gif',
  'png' => 'image/png',
  'pdf' => 'application/pdf',
  'bmp' => 'image/bmp',
  'tiff' => 'image/tiff',
  'doc' => 'application/msword',
  'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
  'dib' => 'image/dib'
}.freeze

Constants included from BaseMethods

BaseMethods::AVAILABLE_TRANSCRIPTION_LANGUAGES, BaseMethods::BASE_DATE_FORMAT, BaseMethods::DEFAULT_HEADERS, BaseMethods::IP_REGEXP, BaseMethods::LIST_OF_DIGITS_REGEXP, BaseMethods::ONLY_DIGITS_REGEXP, BaseMethods::ONLY_ID_SCHEMA, BaseMethods::ONLY_UUID_SCHEMA, BaseMethods::PAGINATION_SCHEMA

Instance Attribute Summary

Attributes included from BaseMethods

#client, #id, #params

Class Method Summary collapse

Methods included from BaseMethods

#call, #delete, #download, #file_extention, #format_file, #get, #initialize, #patch, #post, #put, #raise_error, #stringify_dates!, #validate!, #validate_dates!

Class Method Details

.call(params = {}) ⇒ Object



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
# File 'lib/wavix_api/v1/papers/create.rb', line 35

def call(params = {})
  instance = new(params)
  instance.validate!

  doc_attachment = instance.params[:doc_attachment]
  unless doc_attachment.respond_to?(:path)
    instance.raise_error('doc_attachment must respond to method "path"')
  end

  extention = instance.file_extention(doc_attachment)
  unless CONTENT_TYPES.keys.include?(extention)
    instance.raise_error(
      "doc_attachment have invalid extention. Valid are #{CONTENT_TYPES.keys}"
    )
  end

  instance.params[:doc_attachment] = instance.format_file(
    doc_attachment,
    content_type: CONTENT_TYPES[extention]
  )
  instance.post(
    'v1/mydids/papers',
    with_file: true,
    headers: { 'Content-Disposition' => 'form-data', 'Content-Type' => '' }
  )
end