Module: Vortex::Rails::Controller

Extended by:
ActiveSupport::Concern
Defined in:
lib/vortex/rails.rb

Overview

Rails controller integration for Vortex SDK

This module provides the same route structure as other SDKs (Express, Java, Python) to ensure complete compatibility with React providers and frontend frameworks.

Usage in Rails controller:

class VortexController < ApplicationController
  include Vortex::Rails::Controller

  private

  def authenticate_vortex_user
    # Return user data or nil
  end

  def authorize_vortex_operation(operation, user)
    # Return true/false
  end

  def vortex_client
    @vortex_client ||= Vortex::Client.new(ENV['VORTEX_API_KEY'])
  end
end

Instance Method Summary collapse

Instance Method Details

#accept_invitationsObject

Accept invitations POST /api/vortex/invitations/accept



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/vortex/rails.rb', line 118

def accept_invitations
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('ACCEPT_INVITATIONS', user)
    return render_forbidden('Not authorized to accept invitations')
  end

  invitation_ids = params[:invitationIds]
  target = params[:target]

  unless invitation_ids && target
    return render_bad_request('Missing invitationIds or target')
  end

  result = vortex_client.accept_invitations(invitation_ids, target)
  render json: result
rescue Vortex::VortexError => e
  render_server_error("Failed to accept invitations: #{e.message}")
end

#delete_invitations_by_groupObject

Delete invitations by group DELETE /api/vortex/invitations/by-group/:group_type/:group_id



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/vortex/rails.rb', line 160

def delete_invitations_by_group
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('DELETE_GROUP_INVITATIONS', user)
    return render_forbidden('Not authorized to delete group invitations')
  end

  group_type = params[:group_type]
  group_id = params[:group_id]

  vortex_client.delete_invitations_by_group(group_type, group_id)
  render json: { success: true }
rescue Vortex::VortexError => e
  render_server_error("Failed to delete group invitations: #{e.message}")
end

#generate_jwtObject

Generate JWT for authenticated user POST /api/vortex/jwt



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/vortex/rails.rb', line 41

def generate_jwt
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('JWT', user)
    return render_forbidden('Not authorized to generate JWT')
  end

  jwt = vortex_client.generate_jwt(
    user_id: user[:user_id],
    identifiers: user[:identifiers],
    groups: user[:groups],
    role: user[:role]
  )

  render json: { jwt: jwt }
rescue Vortex::VortexError => e
  render_server_error("Failed to generate JWT: #{e.message}")
end

#get_invitationObject

Get specific invitation by ID GET /api/vortex/invitations/:invitation_id



84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/vortex/rails.rb', line 84

def get_invitation
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('GET_INVITATION', user)
    return render_forbidden('Not authorized to get invitation')
  end

  invitation_id = params[:invitation_id]
  invitation = vortex_client.get_invitation(invitation_id)
  render json: invitation
rescue Vortex::VortexError => e
  render_not_found("Invitation not found: #{e.message}")
end

#get_invitations_by_groupObject

Get invitations by group GET /api/vortex/invitations/by-group/:group_type/:group_id



141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/vortex/rails.rb', line 141

def get_invitations_by_group
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('GET_GROUP_INVITATIONS', user)
    return render_forbidden('Not authorized to get group invitations')
  end

  group_type = params[:group_type]
  group_id = params[:group_id]

  invitations = vortex_client.get_invitations_by_group(group_type, group_id)
  render json: { invitations: invitations }
rescue Vortex::VortexError => e
  render_server_error("Failed to get group invitations: #{e.message}")
end

#get_invitations_by_targetObject

Get invitations by target GET /api/vortex/invitations?targetType=email&[email protected]



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/vortex/rails.rb', line 63

def get_invitations_by_target
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('GET_INVITATIONS', user)
    return render_forbidden('Not authorized to get invitations')
  end

  target_type = params[:targetType]
  target_value = params[:targetValue]

  return render_bad_request('Missing targetType or targetValue') unless target_type && target_value

  invitations = vortex_client.get_invitations_by_target(target_type, target_value)
  render json: { invitations: invitations }
rescue Vortex::VortexError => e
  render_server_error("Failed to get invitations: #{e.message}")
end

#reinviteObject

Reinvite user POST /api/vortex/invitations/:invitation_id/reinvite



179
180
181
182
183
184
185
186
187
188
189
190
191
192
# File 'lib/vortex/rails.rb', line 179

def reinvite
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('REINVITE', user)
    return render_forbidden('Not authorized to reinvite')
  end

  invitation_id = params[:invitation_id]
  result = vortex_client.reinvite(invitation_id)
  render json: result
rescue Vortex::VortexError => e
  render_server_error("Failed to reinvite: #{e.message}")
end

#revoke_invitationObject

Revoke (delete) invitation DELETE /api/vortex/invitations/:invitation_id



101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/vortex/rails.rb', line 101

def revoke_invitation
  user = authenticate_vortex_user
  return render_unauthorized('Authentication required') unless user

  unless authorize_vortex_operation('REVOKE_INVITATION', user)
    return render_forbidden('Not authorized to revoke invitation')
  end

  invitation_id = params[:invitation_id]
  vortex_client.revoke_invitation(invitation_id)
  render json: { success: true }
rescue Vortex::VortexError => e
  render_server_error("Failed to revoke invitation: #{e.message}")
end