Class: Nfe::NfeFileResource

Inherits:
Data
  • Object
show all
Defined in:
lib/nfe/resources/dto/nfe_file_resource.rb,
sig/nfe/resources/dto/nfe_file_resource.rbs

Overview

Immutable value object describing a downloadable file as returned by the api.nfse.io/v2 product-invoice download endpoints, which respond with a JSON envelope carrying a uri to the file rather than the raw bytes.

This is what distinguishes Resources::ProductInvoices downloads (which return a NfeFileResource) from the byte-returning downloads on the other invoice resources. NfeFileResource.from_api maps camelCase keys onto snake_case members, drops unknown keys, and is nil-tolerant.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeNfeFileResource

Returns a new instance of NfeFileResource.

Parameters:

  • uri: (String, nil)
  • name: (String, nil)
  • content_type: (String, nil)
  • size: (Object)


11
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 11

def initialize: (?uri: String?, ?name: String?, ?content_type: String?, ?size: untyped) -> void

Instance Attribute Details

#content_typeString? (readonly)

Returns the value of attribute content_type.

Returns:

  • (String, nil)


5
6
7
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 5

def content_type
  @content_type
end

#nameString? (readonly)

Returns the value of attribute name.

Returns:

  • (String, nil)


4
5
6
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 4

def name
  @name
end

#sizeObject (readonly)

Returns the value of attribute size.

Returns:

  • (Object)


6
7
8
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 6

def size
  @size
end

#uriString? (readonly)

Returns the value of attribute uri.

Returns:

  • (String, nil)


3
4
5
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 3

def uri
  @uri
end

Class Method Details

.from_api(payload) ⇒ Nfe::NfeFileResource?

Build a Nfe::NfeFileResource from an API payload.

Parameters:

  • payload (Hash, nil)

    the response object.

Returns:



17
18
19
20
21
22
23
24
25
26
# File 'lib/nfe/resources/dto/nfe_file_resource.rb', line 17

def self.from_api(payload)
  return nil if payload.nil?

  new(
    uri: payload["uri"] || payload["url"],
    name: payload["name"],
    content_type: payload["contentType"],
    size: payload["size"]
  )
end

.newinstance

Parameters:

  • uri: (String, nil)
  • name: (String, nil)
  • content_type: (String, nil)
  • size: (Object)

Returns:

  • (instance)


10
# File 'sig/nfe/resources/dto/nfe_file_resource.rbs', line 10

def self.new: (?uri: String?, ?name: String?, ?content_type: String?, ?size: untyped) -> instance