Files
sanasto-wiki/app/controllers/api/base.rb
2026-02-01 05:32:30 +01:00

60 lines
1.4 KiB
Ruby

require "grape"
require "grape-swagger"
class Api::Base < Grape::API
format :json
content_type :json, "application/json"
helpers do
def parse_since_param(raw_since)
return nil if raw_since.blank?
Time.iso8601(raw_since)
rescue ArgumentError
error!({ error: "Invalid since parameter. Use ISO8601 timestamp." }, 400)
end
end
resource :entries do
desc "Return public entries in all languages",
is_array: true,
success: Api::Entities::Entry,
produces: [ "application/json" ]
params do
optional :since,
type: String,
desc: "ISO8601 timestamp. Returns entries updated after this time."
end
get do
since_time = parse_since_param(params[:since])
entries_scope = Entry.active_entries
entries_scope = entries_scope.where("updated_at > ?", since_time) if since_time
entries_scope
.order(:updated_at, :id)
.select(
:id,
:category,
:fi,
:en,
:sv,
:no,
:ru,
:de,
:updated_at
)
end
end
add_swagger_documentation(
info: {
title: "Sanasto Wiki API",
description: "Public sync API for Sanasto Wiki glossary entries."
},
mount_path: "/swagger",
hide_documentation_path: true,
format: :json
)
end