Sha256: b537d7658a489d6919bb82c866e18b3e47b6fa44e22294b178f88c61030c19e1

Contents?: true

Size: 833 Bytes

Versions: 5

Compression:

Stored size: 833 Bytes

Contents

# frozen_string_literal: true

require 'roda'
require 'json'
require 'gov_fake_notify/commands/fetch_templates_command'
require 'gov_fake_notify/current_service'

module GovFakeNotify
  # A group of endpoints for the templates
  class TemplatesApp < Roda
    include CurrentService
    plugin :request_headers
    plugin :halt
    plugin :sinatra_helpers
    plugin :json_parser
    route do |r|
      unless current_service
        r.halt 403, { 'Content-Type' => 'application/json' }, { message: 'Invalid or missing token' }.to_json
      end
      r.is do
        r.get do
          result = FetchTemplatesCommand.call(request.params)
          if result.success?
            result.to_json
          else
            r.halt 404, { message: result.errors.join(', ') }.to_json
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
gov_fake_notify-2.0.0 lib/gov_fake_notify/templates_app.rb
gov_fake_notify-1.2.0 lib/gov_fake_notify/templates_app.rb
gov_fake_notify-1.1.3 lib/gov_fake_notify/templates_app.rb
gov_fake_notify-1.1.2 lib/gov_fake_notify/templates_app.rb
gov_fake_notify-1.1.1 lib/gov_fake_notify/templates_app.rb