Class: Docproof::Document
- Inherits:
-
Object
- Object
- Docproof::Document
- Defined in:
- lib/docproof/document.rb
Defined Under Namespace
Classes: AlreadyNotarized, Existed, Invalid, NotFound
Constant Summary collapse
- REGISTER_ENDPOINT =
URI('https://proofofexistence.com/api/v1/register')
- STATUS_ENDPOINT =
URI('https://proofofexistence.com/api/v1/status')
Instance Attribute Summary collapse
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#sha256_hash ⇒ Object
readonly
Returns the value of attribute sha256_hash.
Instance Method Summary collapse
-
#initialize(sha256_hash) ⇒ Document
constructor
A new instance of Document.
- #lookup! ⇒ Object
- #notarize! ⇒ Object
- #register! ⇒ Object
Constructor Details
#initialize(sha256_hash) ⇒ Document
Returns a new instance of Document.
19 20 21 |
# File 'lib/docproof/document.rb', line 19 def initialize(sha256_hash) @sha256_hash = sha256_hash end |
Instance Attribute Details
#response ⇒ Object (readonly)
Returns the value of attribute response.
16 17 18 |
# File 'lib/docproof/document.rb', line 16 def response @response end |
#sha256_hash ⇒ Object (readonly)
Returns the value of attribute sha256_hash.
16 17 18 |
# File 'lib/docproof/document.rb', line 16 def sha256_hash @sha256_hash end |
Instance Method Details
#lookup! ⇒ Object
37 38 39 40 41 42 43 44 45 |
# File 'lib/docproof/document.rb', line 37 def lookup! post(STATUS_ENDPOINT) if response['reason'] == 'nonexistent' raise NotFound, "\"#{sha256_hash}\" does not existed." end response end |
#notarize! ⇒ Object
47 48 49 50 51 52 53 |
# File 'lib/docproof/document.rb', line 47 def notarize! if response['tx'] raise AlreadyNotarized, "\"#{sha256_hash}\" is already notarized." end PaymentProcessor.new(response).perform! end |
#register! ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/docproof/document.rb', line 23 def register! post(REGISTER_ENDPOINT) if response['reason'] == 'existing' raise Existed, "\"#{sha256_hash}\" already registered" end if response['reason'] && response['reason'][/Invalid/] raise Invalid, "\"#{sha256_hash}\" is invalid" end response end |