Sha256: c4d417aa15862ff44f8a7714adc5d5363b075da2d2d87265000dfe29a963533a

Contents?: true

Size: 1.37 KB

Versions: 4

Compression:

Stored size: 1.37 KB

Contents

module RestFtpDaemon
  module API
    class Root < Grape::API


####### CLASS CONFIG

      # logger RestFtpDaemon::Logger.new(:api, "API")
      logger RestFtpDaemon::LoggerPool.instance.get :api

      do_not_route_head!
      do_not_route_options!

      # FIXME
      # add_swagger_documentation
      # default_error_formatter :json
      format :json


####### INITIALIZATION

      def initialize
        # Call daddy
        super

        # Check that Queue and Pool are available
        raise RestFtpDaemon::MissingQueue unless defined? $queue
        raise RestFtpDaemon::MissingQueue unless defined? $pool
      end


####### HELPERS

      helpers do

        def info message, context = {}
          Root.logger.info_with_id message, context
        end

        def api_error exception
          {
          :error => exception.message,
          :message => exception.backtrace.first,
          }
        end

        def render name, values={}
          template = File.read("#{APP_LIBS}/views/#{name.to_s}.haml")
          haml_engine = Haml::Engine.new(template)
          haml_engine.render(binding, values)
        end

        def job_find job_id
          return nil if ($queue.all_size==0)

          # Find a job with exactly this id, or prefixed if not found
          $queue.find_by_id(job_id) || $queue.find_by_id(job_id, true)
        end

      end

    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-ftp-daemon-0.202.2 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.202.1 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.202 lib/rest-ftp-daemon/api/root.rb
rest-ftp-daemon-0.200 lib/rest-ftp-daemon/api/root.rb