Skip to content

Commit

Permalink
API v1 config endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
wvengen committed Oct 13, 2018
1 parent 110c7cc commit 9c5a5d9
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
7 changes: 7 additions & 0 deletions app/controllers/api/v1/configs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Api::V1::ConfigsController < Api::V1::BaseController

def show
render json: FoodsoftConfig, serializer: ConfigSerializer, root: 'config'
end

end
39 changes: 39 additions & 0 deletions app/serializers/config_serializer.rb
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@
namespace :api do
namespace :v1 do
resource :user, only: [:show]
resource :config, only: [:show]
end
end

Expand Down
3 changes: 3 additions & 0 deletions lib/foodsoft_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ def to_hash
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
Expand Down

0 comments on commit 9c5a5d9

Please sign in to comment.