Class: NewsmastMastodon::Api::V1::WebhooksController

Inherits:
Api::BaseController
  • Object
show all
Defined in:
app/controllers/newsmast_mastodon/api/v1/webhooks_controller.rb

Instance Method Summary collapse

Instance Method Details

#handle_ghostObject

manage Ghost webhook



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'app/controllers/newsmast_mastodon/api/v1/webhooks_controller.rb', line 7

def handle_ghost
  ghost_post_articles = params[:post]
  if ghost_post_articles.present?
    ghost_post_data = {
      'title' => ghost_post_articles[:current][:title],
      'article_id' => ghost_post_articles[:current][:id].to_s,
    }
    NewsmastMastodon::GhostNotificationWorker.perform_async(ghost_post_data)
    render json: { message: "Webhook received" }, status: :ok
  else
    render json: { error: "No post data found" }, status: :unprocessable_entity
  end
rescue => e
  render json: { errors: e.message }, status: :internal_server_error
end

#handle_wordpressObject

manage WordPress webhook



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/newsmast_mastodon/api/v1/webhooks_controller.rb', line 24

def handle_wordpress
  wordpress_post = params.to_unsafe_h
  if wordpress_post.present?
    wordpress_post_data = {
      'title' => wordpress_post[:post][:post_title],
      'article_id' => wordpress_post[:post_id].to_s,
    }
    NewsmastMastodon::ArticleNotificationWorker.perform_async(wordpress_post_data)
    render json: { message: "Webhook received" }, status: :ok
  else
    render json: { error: "No article data" }, status: :unprocessable_entity
  end
end