Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support full URL and schemeless URL when register HTTP webhooks as usual #1004

Merged
merged 5 commits into from
Sep 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -9,6 +9,7 @@ Note: For changes to the API, see https://shopify.dev/changelog?filter=api
## Version 11.1.0

- [#1002](https://github.com/Shopify/shopify-api-ruby/pull/1002) Add new method to construct the host app URL for an embedded app, allowing for safer redirect to app inside appropriate shop admin
- [#1004](https://github.com/Shopify/shopify-api-ruby/pull/1004) Support full URL and scheme-less URL when registering HTTP webhooks

## Version 11.0.1

8 changes: 7 additions & 1 deletion lib/shopify_api/webhooks/registrations/http.rb
Original file line number Diff line number Diff line change
@@ -9,7 +9,13 @@ class Http < Registration

sig { override.returns(String) }
def callback_address
"https://#{Context.host_name}/#{@path}"
if @path.match?(%r{^https://})
@path
elsif @path.match?(/^#{Context.host_name}/)
"https://#{@path}"
else
"https://#{Context.host_name}/#{@path}"
end
end

sig { override.returns(T::Hash[Symbol, String]) }
8 changes: 8 additions & 0 deletions test/webhooks/registry_test.rb
Original file line number Diff line number Diff line change
@@ -82,6 +82,14 @@ def test_http_registration_add_and_update
do_registration_test(:http, "test-webhooks")
end

def test_http_registration_add_and_update_with_full_url
do_registration_test(:http, "https://app-address.com/test-webhooks")
end

def test_http_registration_add_and_update_with_schemeless_url
do_registration_test(:http, "app-address.com/test-webhooks")
end

def test_http_registration_with_fields_add_and_update
do_registration_test(:http, "test-webhooks", fields: "field1, field2")
end