API v1 config endpoint

This commit is contained in:
wvengen 2018-10-13 15:18:55 +02:00 committed by wvengen
parent 110c7cc3e9
commit 9c5a5d9492
4 changed files with 50 additions and 0 deletions

View File

@ -0,0 +1,7 @@
class Api::V1::ConfigsController < Api::V1::BaseController
def show
render json: FoodsoftConfig, serializer: ConfigSerializer, root: 'config'
end
end

View File

@ -0,0 +1,39 @@
class ConfigSerializer < ActiveModel::Serializer
# details
attributes :name, :homepage, :contact
# settings
attributes :currency_unit, :currency_space, :default_locale, :price_markup,
:tolerance_is_costly, :use_apple_points, :use_tolerance
# layout
attributes :page_footer_html, :webstats_tracking_code_html
# help and version
attributes :applepear_url, :help_url, :foodsoft
def foodsoft
{
version: Foodsoft::VERSION,
revision: Foodsoft::REVISION,
url: object[:foodsoft_url]
}
end
def page_footer_html
# also see footer layout
if FoodsoftConfig[:page_footer].present?
FoodsoftConfig[:page_footer]
elsif FoodsoftConfig[:homepage].present?
ActionController::Base.helpers.link_to(FoodsoftConfig[:name], FoodsoftConfig[:homepage])
else
FoodsoftConfig[:name]
end
end
def webstats_tracking_code_html
FoodsoftConfig[:webstats_tracking_code].presence
end
end

View File

@ -246,6 +246,7 @@ Foodsoft::Application.routes.draw do
namespace :api do
namespace :v1 do
resource :user, only: [:show]
resource :config, only: [:show]
end
end

View File

@ -180,6 +180,9 @@ class FoodsoftConfig
Hash[keys.map {|k| [k, self[k]]} ]
end
# for using active_model_serializer in the api/v1/configs controller
alias :read_attribute_for_serialization :[]
protected
# @!attribute default_config