require 'helix_sync/methods' require 'sinatra/base' module HelixSync class App < Sinatra::Base include HelixSync::Methods # Fetch the latest changelist for a Helix Sync project # # Note: this will likely require the Helix Sync shelf client to exist. get '/helix-sync/v1/:project_id/last-change' do |project_id| require_p4 # In case you create a new project, you can still send in a default of 0, # just to avoid a 404. The shelf client should still exist though. default = params['default'] if params.key?('default') change = find_latest_change_for_project(project_id) change = default if !change and default halt 404 unless change {change: change}.to_json end # Get a pending changelist for the user to use for a project get '/helix-sync/v1/:project_id/pending' do |project_id| require_p4 default = params['default'] if params.key?('default') change = find_pending_change_for_project(project_id) change = default if !change and default halt 404 unless change {change: change}.to_json end # Removes the pending changelist for a particular project. # # The main use case here might be uninstallation. delete '/helix-sync/v1/:project_id/pending' do |project_id| require_p4 delete_pending_change_for_project(project_id) '' end # Get a pending changelist for the user to use for a project get '/helix-sync/v1/:project_id/preview' do |project_id| require_p4 plan = preview_pending_change(project_id) halt 404 unless plan plan.to_json end # Submit a pending changelist for a project post '/helix-sync/v1/:project/submit' do |project_id| require_p4 resolve_and_submit_shelf(project_id) '' end # Create/update the client for a Helix Sync project post '/helix-sync/v1/:project/clients/device' do |project_id| require_p4 device = params['device'] root = params['root'] client_name = create_device_client(project_id, device, root) halt 404 unless client_name {client: client_name}.to_json end # There shouldn't be any real changelists on this device client. Or you # will get a failure. delete '/helix-sync/v1/:project/clients/device/:device' do |project_id, device_id| require_p4 delete_device_client(project_id, device_id) '' end post '/helix-sync/v1/:project/clients/shelf' do |project_id| require_p4 client_name = create_shelf_client(project_id, '/dev/null') halt 404 unless client_name {client: client_name}.to_json end # Note: It is up to the user to ensure that no pending changes are used # on the client. (See DELETE /helix-sync/v1/:project_id/pending) delete '/helix-sync/v1/:project/clients/shelf' do |project_id| require_p4 delete_shelf_client(project_id) '' end end end