From 11be7949974f5779c6122b5f6881f7f038955f8d Mon Sep 17 00:00:00 2001 From: David Amrani Date: Fri, 7 Mar 2025 11:10:34 -0500 Subject: [PATCH 1/2] app connections --- README.md | 53 ++++++++ lib/embed_workflow.rb | 1 + lib/embed_workflow/app_connections.rb | 75 ++++++++++++ spec/app_connections_spec.rb | 168 ++++++++++++++++++++++++++ 4 files changed, 297 insertions(+) create mode 100644 lib/embed_workflow/app_connections.rb create mode 100644 spec/app_connections_spec.rb diff --git a/README.md b/README.md index 43f110f..2ae2bf6 100644 --- a/README.md +++ b/README.md @@ -167,3 +167,56 @@ EmbedWorkflow::Users.delete(key: "api-user-1") ```ruby EmbedWorkflow.catch_hook(user_key: "main", hook_id: "70e59f4d-1dc4-4720-b0bb-46929dc48d47", anything: "else", you: "need") ``` + +### App Connections + +App Connections allow you to store encrypted credentials for third-party integrations. + +#### List app connections + +```ruby +# Default pagination (25 items) +EmbedWorkflow::AppConnections.list + +# With pagination parameters +EmbedWorkflow::AppConnections.list(starting_after: "550e8400-e29b-41d4-a716-446655440000", limit: 50) + +# For a specific user +EmbedWorkflow::AppConnections.list(user_key: "api-user-1") +``` + +#### Fetch an app connection + +```ruby +EmbedWorkflow::AppConnections.fetch(id: "75233470-6316-4fa9-a7f5-5196f3d06067") +``` + +#### Create an app connection + +```ruby +config = { + api_key: "sk-1234567890abcdef", + organization_id: "org-abcdefg123456" +} + +EmbedWorkflow::AppConnections.create( + name: "My OpenAI Connection", + app_type: "openai", + config: config +) +``` + +#### Update an app connection + +```ruby +EmbedWorkflow::AppConnections.update( + id: "75233470-6316-4fa9-a7f5-5196f3d06067", + name: "Updated OpenAI Connection" +) +``` + +#### Delete an app connection + +```ruby +EmbedWorkflow::AppConnections.delete(id: "75233470-6316-4fa9-a7f5-5196f3d06067") +``` diff --git a/lib/embed_workflow.rb b/lib/embed_workflow.rb index 8080b30..0bb2718 100644 --- a/lib/embed_workflow.rb +++ b/lib/embed_workflow.rb @@ -20,6 +20,7 @@ def self.skey! autoload :Client, "embed_workflow/client" autoload :Actions, "embed_workflow/actions" + autoload :AppConnections, "embed_workflow/app_connections" autoload :Executions, "embed_workflow/executions" autoload :Trigger, "embed_workflow/trigger" autoload :CatchHook, "embed_workflow/catch_hook" diff --git a/lib/embed_workflow/app_connections.rb b/lib/embed_workflow/app_connections.rb new file mode 100644 index 0000000..908ca6c --- /dev/null +++ b/lib/embed_workflow/app_connections.rb @@ -0,0 +1,75 @@ +# frozen_string_literal: true + +require "net/http" +require "uri" + +module EmbedWorkflow + module AppConnections + class << self + include Base + include Client + + RESOURCE_BASE_PATH = "#{BASE_API_PATH}/app_connections".freeze + + def list(user_key: nil, starting_after: nil, ending_before: nil, limit: nil) + params = { + user_key: user_key, + starting_after: starting_after, + ending_before: ending_before, + limit: limit + }.compact + + get_request( + path: RESOURCE_BASE_PATH, + params: params + ) + end + + def fetch(id:, user_key: nil) + params = { user_key: user_key }.compact + + get_request( + path: "#{RESOURCE_BASE_PATH}/#{id}", + params: params + ) + end + + def create(name:, app_type:, config:, user_key: nil) + attrs = { + name: name, + app_type: app_type, + config: config, + user_key: user_key + }.compact + + post_request( + path: RESOURCE_BASE_PATH, + body: attrs + ) + end + + def update(id:, name: nil, app_type: nil, config: nil, user_key: nil) + attrs = { + name: name, + app_type: app_type, + config: config, + user_key: user_key + }.compact + + put_request( + path: "#{RESOURCE_BASE_PATH}/#{id}", + body: attrs + ) + end + + def delete(id:, user_key: nil) + params = { user_key: user_key }.compact + + delete_request( + path: "#{RESOURCE_BASE_PATH}/#{id}", + params: params + ) + end + end + end +end \ No newline at end of file diff --git a/spec/app_connections_spec.rb b/spec/app_connections_spec.rb new file mode 100644 index 0000000..3e115b6 --- /dev/null +++ b/spec/app_connections_spec.rb @@ -0,0 +1,168 @@ +# frozen_string_literal: true + +require_relative "../lib/embed_workflow" +require "net/http" + +describe "app_connections" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:execute_request) + .with(instance_of(Net::HTTPRequest)) + .and_return("response") + end + + describe "#list" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:get_request) + .with({ path: "/api/v1/app_connections", params: {} }) + .and_return("response") + end + + it "sends the correct parameters to the app_connections API" do + EmbedWorkflow::AppConnections.list + end + + context "with pagination parameters" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:get_request) + .with({ + path: "/api/v1/app_connections", + params: { + starting_after: "550e8400-e29b-41d4-a716-446655440000", + limit: 50 + } + }) + .and_return("response") + end + + it "sends the correct pagination parameters" do + EmbedWorkflow::AppConnections.list( + starting_after: "550e8400-e29b-41d4-a716-446655440000", + limit: 50 + ) + end + end + + context "with user_key parameter" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:get_request) + .with({ + path: "/api/v1/app_connections", + params: { user_key: "api-user-1" } + }) + .and_return("response") + end + + it "sends the correct user_key parameter" do + EmbedWorkflow::AppConnections.list(user_key: "api-user-1") + end + end + end + + describe "#fetch" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:get_request) + .with({ + path: "/api/v1/app_connections/75233470-6316-4fa9-a7f5-5196f3d06067", + params: {} + }) + .and_return("response") + end + + it "sends the correct parameters to the app_connections API" do + EmbedWorkflow::AppConnections.fetch(id: "75233470-6316-4fa9-a7f5-5196f3d06067") + end + + context "with user_key parameter" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:get_request) + .with({ + path: "/api/v1/app_connections/75233470-6316-4fa9-a7f5-5196f3d06067", + params: { user_key: "api-user-1" } + }) + .and_return("response") + end + + it "sends the correct user_key parameter" do + EmbedWorkflow::AppConnections.fetch( + id: "75233470-6316-4fa9-a7f5-5196f3d06067", + user_key: "api-user-1" + ) + end + end + end + + describe "#create" do + before do + config = { + api_key: "sk-1234567890abcdef", + organization_id: "org-abcdefg123456" + } + + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:post_request) + .with({ + path: "/api/v1/app_connections", + body: { + name: "My OpenAI Connection", + app_type: "openai", + config: config + } + }) + .and_return("response") + end + + it "sends the correct parameters to the app_connections API" do + config = { + api_key: "sk-1234567890abcdef", + organization_id: "org-abcdefg123456" + } + + EmbedWorkflow::AppConnections.create( + name: "My OpenAI Connection", + app_type: "openai", + config: config + ) + end + end + + describe "#update" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:put_request) + .with({ + path: "/api/v1/app_connections/75233470-6316-4fa9-a7f5-5196f3d06067", + body: { name: "Updated OpenAI Connection" } + }) + .and_return("response") + end + + it "sends the correct parameters to the app_connections API" do + EmbedWorkflow::AppConnections.update( + id: "75233470-6316-4fa9-a7f5-5196f3d06067", + name: "Updated OpenAI Connection" + ) + end + end + + describe "#delete" do + before do + allow_any_instance_of(EmbedWorkflow::Client) + .to receive(:delete_request) + .with({ + path: "/api/v1/app_connections/75233470-6316-4fa9-a7f5-5196f3d06067", + params: {} + }) + .and_return("response") + end + + it "sends the correct parameters to the app_connections API" do + EmbedWorkflow::AppConnections.delete(id: "75233470-6316-4fa9-a7f5-5196f3d06067") + end + end +end \ No newline at end of file From 16bd3c0ddb47eab25298e73b9e527d64218b55b0 Mon Sep 17 00:00:00 2001 From: David Amrani Date: Fri, 7 Mar 2025 11:12:29 -0500 Subject: [PATCH 2/2] whitespace --- lib/embed_workflow/app_connections.rb | 2 +- spec/app_connections_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/embed_workflow/app_connections.rb b/lib/embed_workflow/app_connections.rb index 908ca6c..04bf3c2 100644 --- a/lib/embed_workflow/app_connections.rb +++ b/lib/embed_workflow/app_connections.rb @@ -72,4 +72,4 @@ def delete(id:, user_key: nil) end end end -end \ No newline at end of file +end diff --git a/spec/app_connections_spec.rb b/spec/app_connections_spec.rb index 3e115b6..535cd3f 100644 --- a/spec/app_connections_spec.rb +++ b/spec/app_connections_spec.rb @@ -165,4 +165,4 @@ EmbedWorkflow::AppConnections.delete(id: "75233470-6316-4fa9-a7f5-5196f3d06067") end end -end \ No newline at end of file +end