Class: ShopifyAPI::Webhooks::Registrations::EventBridge

Inherits:
ShopifyAPI::Webhooks::Registration show all
Extended by:
T::Sig
Defined in:
lib/shopify_api/webhooks/registrations/event_bridge.rb

Constant Summary

Constants inherited from ShopifyAPI::Webhooks::Registration

ShopifyAPI::Webhooks::Registration::FIELDS_DELIMITER

Instance Attribute Summary

Attributes inherited from ShopifyAPI::Webhooks::Registration

#fields, #handler, #topic

Instance Method Summary collapse

Methods inherited from ShopifyAPI::Webhooks::Registration

#build_register_query, #initialize

Constructor Details

This class inherits a constructor from ShopifyAPI::Webhooks::Registration

Instance Method Details

#build_check_queryObject



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/shopify_api/webhooks/registrations/event_bridge.rb', line 26

def build_check_query
  <<~QUERY
    {
      webhookSubscriptions(first: 1, topics: #{@topic}) {
        edges {
          node {
            id
            endpoint {
              __typename
              ... on WebhookEventBridgeEndpoint {
                arn
              }
            }
          }
        }
      }
    }
  QUERY
end

#callback_addressObject



11
12
13
# File 'lib/shopify_api/webhooks/registrations/event_bridge.rb', line 11

def callback_address
  @path
end

#mutation_name(webhook_id) ⇒ Object



21
22
23
# File 'lib/shopify_api/webhooks/registrations/event_bridge.rb', line 21

def mutation_name(webhook_id)
  webhook_id ? "eventBridgeWebhookSubscriptionUpdate" : "eventBridgeWebhookSubscriptionCreate"
end

#parse_check_result(body) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/shopify_api/webhooks/registrations/event_bridge.rb', line 47

def parse_check_result(body)
  edges = body.dig("data", "webhookSubscriptions", "edges") || {}
  webhook_id = nil
  current_address = nil
  unless edges.empty?
    node = edges[0]["node"]
    webhook_id = node["id"].to_s
    current_address = node["endpoint"]["arn"].to_s
  end
  { webhook_id: webhook_id, current_address: current_address }
end

#subscription_argsObject



16
17
18
# File 'lib/shopify_api/webhooks/registrations/event_bridge.rb', line 16

def subscription_args
  { arn: callback_address, includeFields: fields }.compact
end