Class: Ecoportal::API::V2::S3::Files
- Inherits:
-
Object
- Object
- Ecoportal::API::V2::S3::Files
- Extended by:
- Common::BaseClass
- Defined in:
- lib/ecoportal/api/v2/s3/files.rb,
lib/ecoportal/api/v2/s3/files/poll.rb,
lib/ecoportal/api/v2/s3/files/poll_status.rb,
lib/ecoportal/api/v2/s3/files/batch_upload.rb
Defined Under Namespace
Classes: BatchUpload, CantCheckStatus, FailedPollRequest, Poll, PollStatus
Constant Summary collapse
- POLL_TIMEOUT =
240
- DELAY_STATUS_CHECK =
5
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#s3_api ⇒ Object
readonly
Returns the value of attribute s3_api.
Instance Method Summary collapse
-
#create_poll(s3_file_reference) ⇒ Ecoportal::API::V2::S3::Files::Poll, NilClass
Create Poll Request to ecoPortal so it registers the file in an actual File Container.
-
#initialize(client, s3_api:) ⇒ Schemas
constructor
An instance object ready to make schema api requests.
-
#poll!(s3_file_reference, check_delay: DELAY_STATUS_CHECK, raise_timeout: false) {|poll| ... } ⇒ Ecoportal::API::V2::S3::Files::PollStatus, NilClass
Tell ecoPortal to register the file in an actual File Container.
-
#poll_status(poll_id) ⇒ Object
Check progress on the File Poll status.
-
#upload!(files, **kargs, &block) ⇒ Object
Helper to upload multiple files at once.
Constructor Details
#initialize(client, s3_api:) ⇒ Schemas
Returns an instance object ready to make schema api requests.
25 26 27 28 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 25 def initialize(client, s3_api:) @client = client @s3_api = s3_api end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
19 20 21 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 19 def client @client end |
#s3_api ⇒ Object (readonly)
Returns the value of attribute s3_api.
19 20 21 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 19 def s3_api @s3_api end |
Instance Method Details
#create_poll(s3_file_reference) ⇒ Ecoportal::API::V2::S3::Files::Poll, NilClass
Create Poll Request to ecoPortal so it registers the file in an actual File Container
74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 74 def create_poll(s3_file_reference) response = client.post("/s3/files", data: s3_file_reference) body = body_data(response.body) return poll_class.new(body) if response.success? msg = "Could not create poll request for\n" msg << JSON.pretty_generate(s3_file_reference) msg << "\n - Error #{response.status}: #{body}" raise FailedPollRequest, msg end |
#poll!(s3_file_reference, check_delay: DELAY_STATUS_CHECK, raise_timeout: false) {|poll| ... } ⇒ Ecoportal::API::V2::S3::Files::PollStatus, NilClass
this is essential to do for the file to be attachable.
- eP will scan the file and give create the proper data model that refers to the file (FileContainer).
- FileContainers also have a file versioning sytem.
- A file container belongs only to one single organization.
Tell ecoPortal to register the file in an actual File Container
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 46 def poll!( s3_file_reference, check_delay: DELAY_STATUS_CHECK, raise_timeout: false ) raise ArgumentError, "Block required. None given" unless block_given? poll = create_poll(s3_file_reference) yield(poll) if block_given? wait_for_poll_completion(poll.id, check_delay: check_delay).tap do |status| poll.status = status next unless raise_timeout next if status&.complete? msg = "File poll `#{poll.id}` not complete. " msg << "Probably timeout after #{POLL_TIMEOUT} seconds. " msg << "Current status: #{poll.status.status}" raise Ecoportal::API::Errors::TimeOut, msg end end |
#poll_status(poll_id) ⇒ Object
Check progress on the File Poll status
88 89 90 91 92 93 94 95 96 97 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 88 def poll_status(poll_id) response = client.get("/s3/files/poll/#{poll_id}") body = body_data(response.body) return poll_status_class.new(body) if response.success? msg = "Could not get status for poll '#{poll_id}' " msg << "- Error #{response.status}: #{body}" raise CantCheckStatus, msg end |
#upload!(files, **kargs, &block) ⇒ Object
Helper to upload multiple files at once
31 32 33 |
# File 'lib/ecoportal/api/v2/s3/files.rb', line 31 def upload!(files, **kargs, &block) BatchUpload.new(files, files_api: self).upload!(**kargs, &block) end |