2019-01-16 16:28:25 +01:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
# API Controller for resources of type Openlab::Projects
|
|
|
|
# Openlab::Projects are Projects shared between different instances
|
2016-04-22 18:17:55 +02:00
|
|
|
class API::OpenlabProjectsController < API::ApiController
|
2020-06-08 15:17:56 +02:00
|
|
|
before_action :init_openlab
|
2016-04-22 18:17:55 +02:00
|
|
|
|
|
|
|
def index
|
2022-02-25 15:22:14 +01:00
|
|
|
render json: @projects.search(params[:q], page: params[:page], per_page: params[:per_page]).response.body
|
2019-01-16 16:28:25 +01:00
|
|
|
rescue StandardError
|
|
|
|
render json: { errors: ['service unavailable'] }
|
2016-04-22 18:17:55 +02:00
|
|
|
end
|
2020-06-08 15:17:56 +02:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def init_openlab
|
|
|
|
client = Openlab::Client.new(app_secret: Setting.get('openlab_app_secret'))
|
2022-02-25 15:22:14 +01:00
|
|
|
@projects = Openlab::Projects.new(client)
|
2020-06-08 15:17:56 +02:00
|
|
|
end
|
2016-04-22 18:17:55 +02:00
|
|
|
end
|