add sync API with swagger documentation at /api
CI / scan_ruby (push) Successful in 23s
CI / scan_js (push) Successful in 15s
CI / lint (push) Successful in 22s
CI / test (push) Successful in 47s

This commit is contained in:
2026-01-31 22:39:12 +01:00
parent fa36305244
commit 4fe95ca538
7 changed files with 199 additions and 8 deletions
+58
View File
@@ -0,0 +1,58 @@
require "grape"
require "grape-swagger"
require "ostruct"
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",
attributes: OpenStruct.new(success: nil, produces: nil)
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