API v1 config endpoint
This commit is contained in:
parent
110c7cc3e9
commit
9c5a5d9492
4 changed files with 50 additions and 0 deletions
7
app/controllers/api/v1/configs_controller.rb
Normal file
7
app/controllers/api/v1/configs_controller.rb
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
class Api::V1::ConfigsController < Api::V1::BaseController
|
||||||
|
|
||||||
|
def show
|
||||||
|
render json: FoodsoftConfig, serializer: ConfigSerializer, root: 'config'
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
39
app/serializers/config_serializer.rb
Normal file
39
app/serializers/config_serializer.rb
Normal 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
|
|
@ -246,6 +246,7 @@ Foodsoft::Application.routes.draw do
|
||||||
namespace :api do
|
namespace :api do
|
||||||
namespace :v1 do
|
namespace :v1 do
|
||||||
resource :user, only: [:show]
|
resource :user, only: [:show]
|
||||||
|
resource :config, only: [:show]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -180,6 +180,9 @@ class FoodsoftConfig
|
||||||
Hash[keys.map {|k| [k, self[k]]} ]
|
Hash[keys.map {|k| [k, self[k]]} ]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# for using active_model_serializer in the api/v1/configs controller
|
||||||
|
alias :read_attribute_for_serialization :[]
|
||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
# @!attribute default_config
|
# @!attribute default_config
|
||||||
|
|
Loading…
Reference in a new issue