class Import extend Enumerize extend ActiveModel::Naming include ActiveModel::Model # enumerize :status, in: %w{created scheduled terminated canceled aborted}, default: "created", predicates: true # enumerize :format, in: %w{neptune netex gtfs}, default: "neptune", predicates: true attr_reader :datas, :links, :headers, :errors def initialize( response ) @datas = response[:datas] @headers = response[:headers] @links = response[:links] # @status = @datas.status.downcase if @datas.status? # @format = @datas.type.downcase if @datas.type? end def report report_path = links[:report] if report_path response = IevApi.request(:get, compliance_check_path, params) ImportReport.new(response) else raise IevApi::IevError("Impossible to access report path link for import") end end def compliance_check compliance_check_path = links[:validation] if compliance_check_path response = IevApi.request(:get, compliance_check_path, params) ComplianceCheck.new(response) else raise IevApi::IevError("Impossible to access compliance check path link for import") end end def delete delete_path = links[:delete] if delete_path IevApi.request(:delete, delete_path, params) else raise IevApi::IevError("Impossible to access delete path link for import") end end def cancel cancel_path = links[:cancel] if cancel_path IevApi.request(:delete, cancel_path, params) else raise IevApi::IevError("Impossible to access cancel path link for import") end end def id @datas.id end def status datas.status end def format datas.format end def filename @datas.filename end def filename_extension File.extname(filename) if filename end def percentage_progress if %w{created}.include? status 0 elsif %w{ terminated canceled aborted }.include? status 100 else 20 end end def referential_name @datas.referential end def name @datas.parameters.name end def user_name? @datas.parameters? && @datas.parameters.user_name? end def user_name @datas.parameters.user_name if user_name? end def no_save @datas.parameters.no_save end def filename @datas.filename end def created_at? @datas.created? end def created_at Time.at(@datas.created.to_i / 1000) if created_at? end def updated_at? @datas.updated? end def updated_at Time.at(@datas.updated.to_i / 1000) if updated_at? end end