Expose all ICON constants in gears API

pull/11851/head
Javier Torres 8 years ago
parent 7a1b8ee33d
commit 2ab0cbd032

@ -7,6 +7,7 @@ module Carto
class Notification < ActiveRecord::Base
MAX_BODY_LENGTH = 140
# Update CartoGearsAPI::Notifications::Notification when adding constants here
ICON_WARNING = 'warning'.freeze
ICON_SUCCESS = 'success'.freeze
ICONS = [ICON_SUCCESS, ICON_WARNING].freeze

@ -11,7 +11,9 @@ module CartoGearsApi
# @attr_reader [String] recipients +builders+, +viewers+ or +all+ if this is an org-notification, nil otherwise
# @attr_reader [DateTime] created_at date this notification was created at
class Notification < Value.new(:id, :icon, :body, :organization, :recipients, :created_at)
# List of possible icon values
ICON_WARNING = Carto::Notification::ICON_WARNING
ICON_SUCCESS = Carto::Notification::ICON_SUCCESS
# List of possible icons
ICONS = Carto::Notification::ICONS
# @api private

@ -11,7 +11,7 @@ module CartoGearsApi
# @param [String] icon name of the icon (defaults to a generic notification icon)
# @return [Notification] the created notification
# @raise [Errors::ValidationFailed] if there were some invalid parameters
def create_notification(body:, icon: Notification::ICONS[0])
def create_notification(body:, icon: Notification::ICON_SUCCESS)
CartoGearsApi::Notifications::Notification.from_model(Carto::Notification.create!(body: body, icon: icon))
rescue ActiveRecord::RecordInvalid => e
raise Errors::ValidationFailed.new(e.record.errors.messages)

Loading…
Cancel
Save