Class: SynapsePayRest::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/synapse_pay_rest/models/user/document.rb

Overview

TODO:

refactor this as a mixin since it shouldn’t be instantiated.

Ancestor of physical/social/virtual document types.

Direct Known Subclasses

PhysicalDocument, SocialDocument, VirtualDocument

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, **options) ⇒ Document

Note:

Do not instantiate directly. User #create on subclasses.

Returns a new instance of Document.



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/synapse_pay_rest/models/user/document.rb', line 59

def initialize(type:, **options)
  @type         = type.upcase
  # only exist for created (not for fetched)
  @id           = options[:id]
  @value        = options[:value]
  # only exist for fetched data
  @status       = options[:status]
  @last_updated = options[:last_updated]
  @document_value = options[:document_value]
  @meta = options[:meta]
end

Instance Attribute Details

#base_documentSynapsePayRest::BaseDocument

Returns the base document to which the document belongs.

Returns:



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def base_document
  @base_document
end

#document_valueObject

Returns the value of attribute document_value.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def document_value
  @document_value
end

#idObject

Returns the value of attribute id.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def id
  @id
end

#last_updatedObject

Returns the value of attribute last_updated.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def last_updated
  @last_updated
end

#metaObject

Returns the value of attribute meta.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def meta
  @meta
end

#statusString



11
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

attr_accessor :base_document, :status, :id, :type, :value, :last_updated, :document_value, :meta

#typeObject

Returns the value of attribute type.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def type
  @type
end

#valueObject

Returns the value of attribute value.



11
12
13
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11

def value
  @value
end

Class Method Details

.create(type:, value:) ⇒ SynapsePayRest::Document

Note:

This should only be called on subclasses of Document, not on Document itself.

Creates a document instance but does not submit it to the API. Use BaseDocument#create/#update/#add_physical_documents or related methods to submit the document to the API.

Parameters:

  • type (String)
  • value (String)

Returns:

Raises:

  • (ArgumentError)

See Also:



29
30
31
32
33
34
# File 'lib/synapse_pay_rest/models/user/document.rb', line 29

def create(type:, value:)
  raise ArgumentError, 'type must be a String' unless type.is_a?(String)
  raise ArgumentError, 'value must be a String' unless type.is_a?(String)

  self.new(type: type, value: value)
end

.from_response(data) ⇒ Object

Note:

Do not call this method. It is used by child classes only.



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/synapse_pay_rest/models/user/document.rb', line 37

def from_response(data)
  doc = self.new(
    type:           data['document_type'],
    id:             data['id'],
    status:         data['status'],
    last_updated:   data['last_updated'],
    document_value: nil,
    meta:           nil
  )

  if data.has_key?('document_value')
    doc.document_value = data['document_value']
  end

  if data.has_key?('meta')
    doc.meta = data['meta']
  end
  doc
end

Instance Method Details

#==(other) ⇒ Object

Checks if two Document instances have same id (different instances of same record).



72
73
74
# File 'lib/synapse_pay_rest/models/user/document.rb', line 72

def ==(other)
  other.instance_of?(self.class) && !id.nil? &&  id == other.id 
end

#to_hashHash

Note:

You shouldn’t need to call this directly.

Converts the document into hash format for use in request JSON.

Returns:

  • (Hash)


80
81
82
# File 'lib/synapse_pay_rest/models/user/document.rb', line 80

def to_hash
  {'document_value' => value, 'document_type' => type}
end