Class: SynapsePayRest::Document
- Inherits:
-
Object
- Object
- SynapsePayRest::Document
- Defined in:
- lib/synapse_pay_rest/models/user/document.rb
Overview
refactor this as a mixin since it shouldn’t be instantiated.
Ancestor of physical/social/virtual document types.
Direct Known Subclasses
Instance Attribute Summary collapse
-
#base_document ⇒ SynapsePayRest::BaseDocument
The base document to which the document belongs.
-
#document_value ⇒ Object
Returns the value of attribute document_value.
-
#id ⇒ Object
Returns the value of attribute id.
-
#last_updated ⇒ Object
Returns the value of attribute last_updated.
-
#meta ⇒ Object
Returns the value of attribute meta.
-
#status ⇒ String
Https://docs.synapsepay.com/docs/user-resources#section-document-status.
-
#type ⇒ Object
Returns the value of attribute type.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
-
.create(type:, value:) ⇒ SynapsePayRest::Document
Creates a document instance but does not submit it to the API.
- .from_response(data) ⇒ Object
Instance Method Summary collapse
-
#==(other) ⇒ Object
Checks if two Document instances have same id (different instances of same record).
-
#initialize(type:, **options) ⇒ Document
constructor
A new instance of Document.
-
#to_hash ⇒ Hash
Converts the document into hash format for use in request JSON.
Constructor Details
#initialize(type:, **options) ⇒ Document
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:, **) @type = type.upcase # only exist for created (not for fetched) @id = [:id] @value = [:value] # only exist for fetched data @status = [:status] @last_updated = [:last_updated] @document_value = [:document_value] @meta = [:meta] end |
Instance Attribute Details
#base_document ⇒ SynapsePayRest::BaseDocument
Returns the base document to which the document belongs.
11 12 13 |
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11 def base_document @base_document end |
#document_value ⇒ Object
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 |
#id ⇒ Object
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_updated ⇒ Object
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 |
#meta ⇒ Object
Returns the value of attribute meta.
11 12 13 |
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11 def @meta end |
#status ⇒ String
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 |
#type ⇒ Object
Returns the value of attribute type.
11 12 13 |
# File 'lib/synapse_pay_rest/models/user/document.rb', line 11 def type @type end |
#value ⇒ Object
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
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.
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
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. = 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_hash ⇒ Hash
You shouldn’t need to call this directly.
Converts the document into hash format for use in request JSON.
80 81 82 |
# File 'lib/synapse_pay_rest/models/user/document.rb', line 80 def to_hash {'document_value' => value, 'document_type' => type} end |