Skip to content

Commit

Permalink
remove removing duplicate code
Browse files Browse the repository at this point in the history
  • Loading branch information
andy-liuu committed Nov 4, 2024
1 parent ce31b6a commit b4a0338
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 27 deletions.
17 changes: 2 additions & 15 deletions lib/shopify_api/webhooks/registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,27 +49,14 @@ def mutation_name(webhook_id); end
def build_check_query; end

sig do
params(body: T::Hash[String, T.untyped]).returns({
abstract.params(body: T::Hash[String, T.untyped]).returns({
webhook_id: T.nilable(String),
current_address: T.nilable(String),
fields: T::Array[String],
metafield_namespaces: T::Array[String],
})
end
def parse_check_result(body)
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
webhook_id = nil
fields = []
metafield_namespaces = []
unless edges.empty?
node = edges[0]["node"]
webhook_id = node["id"].to_s
fields = node["includeFields"] || []
metafield_namespaces = node["metafieldNamespaces"] || []
end
{ webhook_id: webhook_id, current_address: nil, fields: fields,
metafield_namespaces: metafield_namespaces, }
end
def parse_check_result(body); end

sig { params(webhook_id: T.nilable(String)).returns(String) }
def build_register_query(webhook_id: nil)
Expand Down
15 changes: 11 additions & 4 deletions lib/shopify_api/webhooks/registrations/event_bridge.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,28 @@ def build_check_query
end

sig do
params(body: T::Hash[String, T.untyped]).returns({
override.params(body: T::Hash[String, T.untyped]).returns({
webhook_id: T.nilable(String),
current_address: T.nilable(String),
fields: T::Array[String],
metafield_namespaces: T::Array[String],
})
end
def parse_check_result(body)
parse_results = super(body)
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
webhook_id = nil
fields = []
metafield_namespaces = []
current_address = nil
unless edges.empty?
node = edges[0]["node"]
parse_results[:current_address] = node["endpoint"]["arn"].to_s
webhook_id = node["id"].to_s
current_address = node["endpoint"]["arn"].to_s
fields = node["includeFields"] || []
metafield_namespaces = node["metafieldNamespaces"] || []
end
parse_results
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
metafield_namespaces: metafield_namespaces, }
end
end
end
Expand Down
15 changes: 11 additions & 4 deletions lib/shopify_api/webhooks/registrations/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,26 +52,33 @@ def build_check_query
end

sig do
params(body: T::Hash[String, T.untyped]).returns({
override.params(body: T::Hash[String, T.untyped]).returns({
webhook_id: T.nilable(String),
current_address: T.nilable(String),
fields: T::Array[String],
metafield_namespaces: T::Array[String],
})
end
def parse_check_result(body)
parse_results = super(body)
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
webhook_id = nil
fields = []
metafield_namespaces = []
current_address = nil
unless edges.empty?
node = edges[0]["node"]
parse_results[:current_address] =
webhook_id = node["id"].to_s
current_address =
if node.key?("endpoint")
node["endpoint"]["callbackUrl"].to_s
else
node["callbackUrl"].to_s
end
fields = node["includeFields"] || []
metafield_namespaces = node["metafieldNamespaces"] || []
end
parse_results
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
metafield_namespaces: metafield_namespaces, }
end
end
end
Expand Down
15 changes: 11 additions & 4 deletions lib/shopify_api/webhooks/registrations/pub_sub.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,22 +51,29 @@ def build_check_query
end

sig do
params(body: T::Hash[String, T.untyped]).returns({
override.params(body: T::Hash[String, T.untyped]).returns({
webhook_id: T.nilable(String),
current_address: T.nilable(String),
fields: T::Array[String],
metafield_namespaces: T::Array[String],
})
end
def parse_check_result(body)
parse_results = super(body)
edges = body.dig("data", "webhookSubscriptions", "edges") || {}
webhook_id = nil
fields = []
metafield_namespaces = []
current_address = nil
unless edges.empty?
node = edges[0]["node"]
parse_results[:current_address] =
webhook_id = node["id"].to_s
current_address =
"pubsub://#{node["endpoint"]["pubSubProject"]}:#{node["endpoint"]["pubSubTopic"]}"
fields = node["includeFields"] || []
metafield_namespaces = node["metafieldNamespaces"] || []
end
parse_results
{ webhook_id: webhook_id, current_address: current_address, fields: fields,
metafield_namespaces: metafield_namespaces, }
end
end
end
Expand Down

0 comments on commit b4a0338

Please sign in to comment.