module Ecoportal module API class V2 class S3 class Files class Poll < Common::Content::DoubleModel passthrough :poll_url embeds_one :status, nullable: true, klass: "Ecoportal::API::V2::S3::Files::PollStatus" def poll_id return @poll_id if instance_variable_defined?(:@poll_id) return @poll_id = nil unless (uri = parsed_poll_url) @poll_id = uri.path.split('/poll/').last end alias_method :id, :poll_id # The final File eP container id def container_id return unless status? status.container_id end def status? !doc['status'].nil? end def status=(value) case value when NilClass doc["status"] = nil when Ecoportal::API::V2::S3::Files::PollStatus doc["status"] = JSON.parse(value.to_json) when Hash doc["status"] = value else # TODO raise "Invalid set on status: Need nil, PollStatus or Hash; got #{value.class}" end remove_instance_variable("@status") if defined?(@status) end def pending? !complete? end def complete? status&.complete? end def success? status&.success? end def failed? status&.failed? end def timeout? status&.timeout? end private def parsed_poll_url return nil unless poll_url require 'uri' URI.parse(poll_url) end def callbacks @callbacks ||= [] end end end end end end end