mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 17:59:47 +02:00
30 lines
931 B
Ruby
30 lines
931 B
Ruby
module Repp
|
|
class ContactV1 < Grape::API
|
|
version 'v1', using: :path
|
|
|
|
resource :contacts do
|
|
desc 'Return list of contact'
|
|
params do
|
|
optional :limit, type: Integer, values: (1..20).to_a, desc: 'How many contacts to show'
|
|
optional :offset, type: Integer, desc: 'Contact number to start at'
|
|
optional :details, type: String, values: %w(true false), desc: 'Whether to include details'
|
|
end
|
|
|
|
get '/' do
|
|
limit = params[:limit] || 20
|
|
offset = params[:offset] || 0
|
|
|
|
if params[:details] == 'true'
|
|
contacts = current_user.registrar.contacts.limit(limit).offset(offset)
|
|
else
|
|
contacts = current_user.registrar.contacts.limit(limit).offset(offset).pluck(:code)
|
|
end
|
|
|
|
@response = {
|
|
contacts: contacts,
|
|
total_number_of_records: current_user.registrar.contacts.count
|
|
}
|
|
end
|
|
end
|
|
end
|
|
end
|