Skip to content
Merged
Show file tree
Hide file tree
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
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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")
```
1 change: 1 addition & 0 deletions lib/embed_workflow.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
75 changes: 75 additions & 0 deletions lib/embed_workflow/app_connections.rb
Original file line number Diff line number Diff line change
@@ -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
168 changes: 168 additions & 0 deletions spec/app_connections_spec.rb
Original file line number Diff line number Diff line change
@@ -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