Class: Pdfmonkey::Document
- Inherits:
-
Object
- Object
- Pdfmonkey::Document
- Extended by:
- Forwardable
- Defined in:
- lib/pdfmonkey/document.rb
Constant Summary collapse
- ATTRIBUTES =
%i[ app_id checksum created_at document_template_id download_url id meta payload preview_url status updated_at ].freeze
- COMPLETE_STATUSES =
%w[failure success].freeze
- COLLECTION =
'documents'- MEMBER =
'document'
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(adapter: Pdfmonkey::Adapter.new, **attributes) ⇒ Document
constructor
A new instance of Document.
- #reload! ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(adapter: Pdfmonkey::Adapter.new, **attributes) ⇒ Document
Returns a new instance of Document.
47 48 49 50 51 |
# File 'lib/pdfmonkey/document.rb', line 47 def initialize(adapter: Pdfmonkey::Adapter.new, **attributes) @adapter = adapter @attributes = OpenStruct.new(ATTRIBUTES.zip([]).to_h) update(attributes) end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
29 30 31 |
# File 'lib/pdfmonkey/document.rb', line 29 def attributes @attributes end |
Class Method Details
.generate(template_id, payload) ⇒ Object
38 39 40 41 42 43 44 45 |
# File 'lib/pdfmonkey/document.rb', line 38 def self.generate(template_id, payload) document = new( document_template_id: template_id, payload: payload.to_json, status: 'pending') document.send(:save) end |
.generate!(document_template_id, payload) ⇒ Object
32 33 34 35 36 |
# File 'lib/pdfmonkey/document.rb', line 32 def self.generate!(document_template_id, payload) document = generate(document_template_id, payload) document.reload! until COMPLETE_STATUSES.include?(document.status) document end |
Instance Method Details
#reload! ⇒ Object
53 54 55 56 57 |
# File 'lib/pdfmonkey/document.rb', line 53 def reload! attributes = adapter.call(:get, self) update(attributes) self end |
#to_json ⇒ Object
59 60 61 |
# File 'lib/pdfmonkey/document.rb', line 59 def to_json { document: attributes.to_h }.to_json end |