Class: ActivityNotification::SubscriptionsApiController
- Inherits:
-
SubscriptionsController
- Object
- SubscriptionsController
- ActivityNotification::SubscriptionsApiController
- Defined in:
- app/controllers/activity_notification/subscriptions_api_controller.rb
Overview
Controller to manage subscriptions API.
Direct Known Subclasses
Constant Summary
Constants included from CommonController
CommonController::DEFAULT_VIEW_DIRECTORY
Instance Method Summary collapse
-
#create(params) ⇒ JSON
Creates new subscription.
-
#destroy(params) ⇒ JSON
Deletes a subscription.
-
#index(params) ⇒ JSON
Finds and shows a subscription from specified key.
-
#index(params) ⇒ JSON
Returns subscription index of the target.
-
#index(params) ⇒ JSON
Finds and returns configured optional_target names from specified key.
-
#show(params) ⇒ JSON
Shows a subscription.
-
#open(params) ⇒ JSON
Updates a subscription to subscribe to the notifications.
-
#open(params) ⇒ JSON
Updates a subscription to subscribe to the notification email.
-
#open(params) ⇒ JSON
Updates a subscription to subscribe to the specified optional target.
-
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the notifications.
-
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the notification email.
-
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the specified optional target.
Methods included from StoreController
#store_controller_for_activity_notification
Instance Method Details
#create(params) ⇒ JSON
Creates new subscription.
POST /:target_type/:target_id/subscriptions
39 40 41 42 43 44 45 46 47 48 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 39 def create render_invalid_parameter("Parameter is missing or the value is empty: subscription") and return if params[:subscription].blank? optional_target_names = (params[:subscription][:optional_targets] || {}).keys.select { |key| !key.to_s.start_with?("subscribing_to_") } optional_target_names.each do |optional_target_name| subscribing_param = params[:subscription][:optional_targets][optional_target_name][:subscribing] params[:subscription][:optional_targets]["subscribing_to_#{optional_target_name}"] = subscribing_param unless subscribing_param.nil? end super render status: 201, json: subscription_json if @subscription end |
#destroy(params) ⇒ JSON
Deletes a subscription.
DELETE /:target_type/:target_id/subscriptions/:id
94 95 96 97 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 94 def destroy super head 204 end |
#index(params) ⇒ JSON
Finds and shows a subscription from specified key.
GET /:target_type/:target_id/subscriptions/find
57 58 59 60 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 57 def find super render json: subscription_json if @subscription end |
#index(params) ⇒ JSON
Returns subscription index of the target.
GET /:target_type/:target_id/subscriptions
22 23 24 25 26 27 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 22 def index super json_response = { configured_count: @subscriptions.size, subscriptions: @subscriptions } if @subscriptions json_response = (json_response || {}).merge(unconfigured_count: @notification_keys.size, unconfigured_notification_keys: @notification_keys) if @notification_keys render json: json_response end |
#index(params) ⇒ JSON
Finds and returns configured optional_target names from specified key.
GET /:target_type/:target_id/subscriptions/optional_target_names
69 70 71 72 73 74 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 69 def optional_target_names latest_notification = @target.notifications.filtered_by_key(params[:key]).latest latest_notification ? render(json: { configured_count: latest_notification.optional_target_names.length, optional_target_names: latest_notification.optional_target_names }) : render_resource_not_found("Couldn't find notification with this target and 'key'=#{params[:key]}") end |
#show(params) ⇒ JSON
Shows a subscription.
GET /:target_type/:target_id/subscriptions/:id
82 83 84 85 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 82 def show super render json: subscription_json end |
#open(params) ⇒ JSON
Updates a subscription to subscribe to the notifications.
PUT /:target_type/:target_id/subscriptions/:id/subscribe
107 108 109 110 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 107 def subscribe super validate_and_render_subscription end |
#open(params) ⇒ JSON
Updates a subscription to subscribe to the notification email.
PUT /:target_type/:target_id/subscriptions/:id/subscribe_email
129 130 131 132 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 129 def subscribe_to_email super validate_and_render_subscription end |
#open(params) ⇒ JSON
Updates a subscription to subscribe to the specified optional target.
PUT /:target_type/:target_id/subscriptions/:id/subscribe_to_optional_target
152 153 154 155 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 152 def subscribe_to_optional_target super validate_and_render_subscription end |
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the notifications.
PUT /:target_type/:target_id/subscriptions/:id/unsubscribe
118 119 120 121 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 118 def unsubscribe super validate_and_render_subscription end |
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the notification email.
PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_email
140 141 142 143 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 140 def unsubscribe_to_email super validate_and_render_subscription end |
#open(params) ⇒ JSON
Updates a subscription to unsubscribe to the specified optional target.
PUT /:target_type/:target_id/subscriptions/:id/unsubscribe_to_optional_target
164 165 166 167 |
# File 'app/controllers/activity_notification/subscriptions_api_controller.rb', line 164 def unsubscribe_to_optional_target super validate_and_render_subscription end |