Class: ShopifyAPI::Webhooks::Registrations::PubSub
Constant Summary
ShopifyAPI::Webhooks::Registration::FIELDS_DELIMITER
Instance Attribute Summary
#fields, #handler, #topic
Instance Method Summary
collapse
#build_register_query, #initialize
Instance Method Details
#build_check_query ⇒ Object
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
# File 'lib/shopify_api/webhooks/registrations/pub_sub.rb', line 29
def build_check_query
<<~QUERY
{
webhookSubscriptions(first: 1, topics: #{@topic}) {
edges {
node {
id
endpoint {
__typename
... on WebhookPubSubEndpoint {
pubSubProject
pubSubTopic
}
}
}
}
}
}
QUERY
end
|
#callback_address ⇒ Object
11
12
13
|
# File 'lib/shopify_api/webhooks/registrations/pub_sub.rb', line 11
def callback_address
@path
end
|
#mutation_name(webhook_id) ⇒ Object
24
25
26
|
# File 'lib/shopify_api/webhooks/registrations/pub_sub.rb', line 24
def mutation_name(webhook_id)
webhook_id ? "pubSubWebhookSubscriptionUpdate" : "pubSubWebhookSubscriptionCreate"
end
|
#parse_check_result(body) ⇒ Object
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/shopify_api/webhooks/registrations/pub_sub.rb', line 51
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 = "pubsub://#{node["endpoint"]["pubSubProject"]}:#{node["endpoint"]["pubSubTopic"]}"
end
{ webhook_id: webhook_id, current_address: current_address }
end
|
#subscription_args ⇒ Object
16
17
18
19
20
21
|
# File 'lib/shopify_api/webhooks/registrations/pub_sub.rb', line 16
def subscription_args
project_topic_pair = callback_address.gsub(%r{^pubsub://}, "").split(":")
project = project_topic_pair[0]
topic = project_topic_pair[1]
{ pubSubProject: project, pubSubTopic: topic, includeFields: fields }.compact
end
|