From 937d019dbdd529ac2b0729eb36afc0ab6753945b Mon Sep 17 00:00:00 2001 From: David Amrani Date: Wed, 5 Mar 2025 13:24:27 -0500 Subject: [PATCH 1/5] catch hook --- README.md | 6 ++++++ lib/embed_workflow.rb | 5 +++++ lib/embed_workflow/catch_hook.rb | 24 ++++++++++++++++++++++++ lib/embed_workflow/workflows.rb | 13 ++++++------- 4 files changed, 41 insertions(+), 7 deletions(-) create mode 100644 lib/embed_workflow/catch_hook.rb diff --git a/README.md b/README.md index c2c1866..d1266e6 100644 --- a/README.md +++ b/README.md @@ -130,3 +130,9 @@ EmbedWorkflow::Users.upsert(name: "Jane Smith", id: user["id"], config: config) ```ruby EmbedWorkflow::Users.fetch(key: "api-user-1") ``` + +### Catch a webhook + +```ruby +EmbedWorkflow.catch_hook(user_key: "main", hook_id: "70e59f4d-1dc4-4720-b0bb-46929dc48d47", anything: "else", you: "need") +``` diff --git a/lib/embed_workflow.rb b/lib/embed_workflow.rb index 35c1547..8080b30 100644 --- a/lib/embed_workflow.rb +++ b/lib/embed_workflow.rb @@ -22,6 +22,7 @@ def self.skey! autoload :Actions, "embed_workflow/actions" autoload :Executions, "embed_workflow/executions" autoload :Trigger, "embed_workflow/trigger" + autoload :CatchHook, "embed_workflow/catch_hook" autoload :Users, "embed_workflow/users" autoload :Workflows, "embed_workflow/workflows" @@ -32,4 +33,8 @@ def self.skey! def self.trigger(**args) Trigger.create(**args) end + + def self.catch_hook(**args) + CatchHook.create(**args) + end end diff --git a/lib/embed_workflow/catch_hook.rb b/lib/embed_workflow/catch_hook.rb new file mode 100644 index 0000000..7bc73ad --- /dev/null +++ b/lib/embed_workflow/catch_hook.rb @@ -0,0 +1,24 @@ +# frozen_string_literal: true + +require "net/http" +require "uri" + +module EmbedWorkflow + module CatchHook + class << self + include Base + include Client + + RESOURCE_BASE_PATH = "#{BASE_API_PATH}/hooks".freeze + + def create(hook_id:, user_key:, **rest) + attrs = { user_key: user_key }.merge(rest).compact + puts "#{RESOURCE_BASE_PATH}/#{hook_id}/catch" + post_request( + path: "#{RESOURCE_BASE_PATH}/#{hook_id}/catch", + body: attrs + ) + end + end + end +end diff --git a/lib/embed_workflow/workflows.rb b/lib/embed_workflow/workflows.rb index 7728937..aa1f58e 100644 --- a/lib/embed_workflow/workflows.rb +++ b/lib/embed_workflow/workflows.rb @@ -11,13 +11,13 @@ class << self RESOURCE_BASE_PATH = "#{BASE_API_PATH}/workflows" - def create(name:, template: nil, context: nil, auto_start: nil, tenant_key: nil) + def create(name:, template: nil, user_key: nil, event_trigger: nil, trigger_conditions: nil) attrs = { name: name, template: template, - auto_start: auto_start, - tenant_key: tenant_key, - context: context + event_trigger: event_trigger, + trigger_conditions: trigger_conditions, + user_key: user_key } post_request( @@ -32,12 +32,11 @@ def fetch(hashid: nil, key: nil) ) end - def update(hashid:, name: nil, template: nil, tenant_key: nil, context: nil, auto_start: nil) + def update(hashid:, name: nil, template: nil, user_key: nil) attrs = { name: name, template: template, - tenant_key: tenant_key, - context: context + user_key: user_key }.compact put_request( From ef3ae2137303df6b80f2dadf3af1a7e469eb0ba7 Mon Sep 17 00:00:00 2001 From: David Amrani Date: Wed, 5 Mar 2025 13:31:19 -0500 Subject: [PATCH 2/5] bump verion --- README.md | 2 -- lib/embed_workflow/catch_hook.rb | 2 +- lib/embed_workflow/version.rb | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d1266e6..741c7cb 100644 --- a/README.md +++ b/README.md @@ -111,8 +111,6 @@ EmbedWorkflow::Actions.activities(hashid: "7l0al") ```ruby config = { - primary_color: "#333333", - logo_url: "https://embedworkflow.com/assets/logo-dark-ac3f24918e46816034763925e7e2272381c18907601677ffa9e842f46555e80d.png", user_data: { foo: "bar" }, diff --git a/lib/embed_workflow/catch_hook.rb b/lib/embed_workflow/catch_hook.rb index 7bc73ad..fd154dc 100644 --- a/lib/embed_workflow/catch_hook.rb +++ b/lib/embed_workflow/catch_hook.rb @@ -13,7 +13,7 @@ class << self def create(hook_id:, user_key:, **rest) attrs = { user_key: user_key }.merge(rest).compact - puts "#{RESOURCE_BASE_PATH}/#{hook_id}/catch" + post_request( path: "#{RESOURCE_BASE_PATH}/#{hook_id}/catch", body: attrs diff --git a/lib/embed_workflow/version.rb b/lib/embed_workflow/version.rb index 88db537..45d9c8b 100644 --- a/lib/embed_workflow/version.rb +++ b/lib/embed_workflow/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module EmbedWorkflow - VERSION = "0.0.1" + VERSION = "0.1.0" end From 2554c141e43f118bb745598b5d772fb850a7562d Mon Sep 17 00:00:00 2001 From: David Amrani Date: Wed, 5 Mar 2025 13:56:25 -0500 Subject: [PATCH 3/5] upgrade ruby --- .ruby-version | 2 +- Gemfile.lock | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.ruby-version b/.ruby-version index 6816713..8122ad0 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.6.5 \ No newline at end of file +2.7.8 \ No newline at end of file diff --git a/Gemfile.lock b/Gemfile.lock index 13ca384..65fc41e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,7 @@ PATH remote: . specs: - embed_workflow (0.0.1) + embed_workflow (0.1.0) GEM remote: https://rubygems.org/ From 83189e579d3cf1f43a436ddfb99be0f24a3d88e2 Mon Sep 17 00:00:00 2001 From: David Amrani Date: Wed, 5 Mar 2025 14:19:55 -0500 Subject: [PATCH 4/5] upgrade ruby --- .github/workflows/ruby.yml | 7 ++----- .ruby-version | 2 +- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 10dda2e..78fe96a 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -22,15 +22,12 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - ruby-version: ['2.6', '2.7', '3.0'] + ruby-version: ["2.7", "3.0", "3.1", "3.2"] steps: - uses: actions/checkout@v3 - name: Set up Ruby - # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby, - # change this to (see https://github.com/ruby/setup-ruby#versioning): - # uses: ruby/setup-ruby@v1 - uses: ruby/setup-ruby@2b019609e2b0f1ea1a2bc8ca11cb82ab46ada124 + uses: ruby/setup-ruby@v1 with: ruby-version: ${{ matrix.ruby-version }} bundler-cache: true # runs 'bundle install' and caches installed gems automatically diff --git a/.ruby-version b/.ruby-version index 8122ad0..448ada3 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -2.7.8 \ No newline at end of file +3.2.5 \ No newline at end of file From 979dd685aadc6d999f7f6e05d6f16424638a1efb Mon Sep 17 00:00:00 2001 From: David Amrani Date: Wed, 5 Mar 2025 14:28:13 -0500 Subject: [PATCH 5/5] fix lint job --- .github/workflows/ruby.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 78fe96a..5c5269c 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -41,7 +41,7 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - name: Install Ruby and gems - uses: ruby/setup-ruby@8f312efe1262fb463d906e9bf040319394c18d3e # v1.92 + uses: ruby/setup-ruby@v1 with: bundler-cache: true # Add or replace any other lints here