Module: Legion::DigitalWorker::Airb
- Defined in:
- lib/legion/digital_worker/airb.rb
Class Method Summary collapse
-
.check_status(intake_id) ⇒ Object
Check the AIRB approval status for a given intake_id.
-
.create_intake(worker_id, description:) ⇒ Object
Create an AIRB intake form for a worker registration.
-
.sync_status(worker_id) ⇒ Object
Sync AIRB status back to the Legion worker state.
Class Method Details
.check_status(intake_id) ⇒ Object
Check the AIRB approval status for a given intake_id. Returns: ‘pending’, ‘approved’, or ‘rejected’
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/legion/digital_worker/airb.rb', line 28 def check_status(intake_id) return mock_check_status(intake_id) unless live_api? endpoint = api_endpoint raise ArgumentError, 'AIRB API endpoint not configured' unless endpoint response = http_get("#{endpoint}/intakes/#{intake_id}/status") response[:status] || response['status'] || 'pending' rescue StandardError => e log_warn "AIRB check_status failed for #{intake_id}: #{e.}" 'pending' end |
.create_intake(worker_id, description:) ⇒ Object
Create an AIRB intake form for a worker registration. Returns an intake_id string.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/legion/digital_worker/airb.rb', line 9 def create_intake(worker_id, description:) return mock_create_intake(worker_id, description) unless live_api? endpoint = api_endpoint raise ArgumentError, 'AIRB API endpoint not configured' unless endpoint response = http_post( "#{endpoint}/intakes", { worker_id: worker_id, description: description, submitted_at: Time.now.utc.iso8601 } ) response[:intake_id] || response['intake_id'] rescue StandardError => e log_warn "AIRB create_intake failed: #{e.}" nil end |
.sync_status(worker_id) ⇒ Object
Sync AIRB status back to the Legion worker state. Calls approve/reject on the Registration module when AIRB has a decision.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/legion/digital_worker/airb.rb', line 43 def sync_status(worker_id) return { synced: false, reason: 'DigitalWorker not defined' } unless defined?(Legion::DigitalWorker) worker = find_worker(worker_id) return { synced: false, reason: 'worker not found' } unless worker return { synced: false, reason: 'not pending approval' } unless worker.lifecycle_state == 'pending_approval' intake_id = lookup_intake_id(worker_id) return { synced: false, reason: 'no intake_id found' } unless intake_id status = check_status(intake_id) log_info "worker=#{worker_id} intake=#{intake_id} airb_status=#{status}" case status when 'approved' apply_airb_approval(worker_id) when 'rejected' apply_airb_rejection(worker_id) else { synced: false, reason: "airb_status=#{status}", intake_id: intake_id } end end |