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

Feat/workflows overrides #76

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
67 changes: 67 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -896,6 +896,73 @@ client.delete_topic('<insert-topic-key>')
client.subscriber_topic('<insert-topic-key>', '<insert-externalSubscriberId>')
```

### Workflow Overrides

- Create workflow overrides: `create_workflow_overrides(body)`
```ruby
client.create_workflow_overrides(
tenantId: "<insert-tenant-id>",
workflowId: "<insert-workflow-id>",
active: true # or false
)
```

- Get workflow overrides: `get_workflow_overrides(query = {})`
```ruby
client.get_workflow_overrides(
limit: 1,
page: 1
)
```

- Get tenant workflow overrides: `get_tenant_workflow_override(workflow_id, tenant_id)`
```ruby
client.get_tenant_workflow_override("<insert-workflow-id>", "<insert-tenant-id>")
```

- Get workflow override by ID: `get_workflow_override_by_id(override_id)`
```ruby
client.get_workflow_override_by_id("<insert-override-id>")
```

- Update workflow override by ID: `update_workflow_override_by_id(override_id, body)`
```ruby
client.update_workflow_override_by_id(
"<insert-tenant-id>",
{
preferenceSettings: {
sms: true, # or false,
in_app: true, # or false,
email: true, # or false,
push: true, # or false,
},
active: true # or false
}
)
```

- Update tenant workflow override: `update_tenant_workflow_override(workflow_id, tenant_id, body)`
```ruby
client.update_tenant_workflow_override(
"<insert-workflow-id>"
"<insert-tenant-id>",
{
preferenceSettings: {
sms: true, # or false,
in_app: true, # or false,
email: true, # or false,
push: true, # or false,
},
active: true # or false
}
)
```

- Delete workflow override: `delete_workflow_override(override_id)`
```ruby
client.delete_workflow_override("<insert-override-id>")
```

### Idempotent Request

This SDK allows you to perform idempotent requests, that is safely retrying requests without accidentally performing the same operation twice.
Expand Down
111 changes: 111 additions & 0 deletions lib/novu/api/workflow_overrides.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
# frozen_string_literal: true

module Novu
class Api
# Module Novu::Api::WorkflowOverrides provides an API for managing workflow overrides within your Novu account.
#
# This module includes methods for creating, retrieving, updating and deleting workflow overrides.
#
# For more information on the Novu API see https://api.novu.co/api#/Workflows-Overrides, https://docs.novu.co/api-reference/workflow-overrides
module WorkflowOverrides

# Create workflow overrides
#
# @bodyparams:
# @param `active` [Boolean] - The status of the workflow.
# @param `tenantId` [String] - The ID of the tenant.
# @param `workflowId` [String] - The ID of the workflow.
# @param `preferenceSettings` [Hash (Optional)] - A custom preference settings object that can store information about the workflow
#
# @return [Hash] data - The list of information with respect to the created workflow.
# @return [number] status - The status code.
def create_workflow_overrides(body)
post("/workflow-overrides", body: body.to_json, headers: {'Content-Type': 'application/json'})
end

# Returns a list of workflow overrides that can be paginated using the `page`
# and `limit` query parameter
#
# @queryparams:
# @param `page` [Integer(optional)] Number of page for the pagination.
# @param `limit` [Integer(optional)]
#
# @return [Hash] The list of workflow overrides are successfully returned.
# @return [number] status
# - Returns 200 if successful
def get_workflow_overrides(query = {})
get("/workflow-overrides", query: query)
end

# Returns a workflow ovverride
#
# @pathparams:
# @param `workflow_id` [String]
# @param `tenant_id` [String]
#
# @return [Hash] workflow override entity
# @return [number] status
# - Returns 200 if successful.
def get_tenant_workflow_override(workflow_id, tenant_id)
get("/workflow-overrides/workflows/#{workflow_id}/tenants/#{tenant_id}")
end

# Get the details of a workflow ovverride by it's ID
#
# @pathparams:
# @param `override_id` [String]
#
# @return [Hash] workflow override entity
# @return [number] status
# - Returns 200 if successful.
def get_workflow_override_by_id(override_id)
get("/workflow-overrides/#{override_id}")
end

# Update workflow ovverride by it's ID
#
# @pathparams:
# @param `override_id` [String]
#
# @bodyParam:
# @param `active` [Boolean] - The status of the workflow.
# @param `preferenceSettings` [Hash] - The preference settings of the workflow. It should include any/all of following keys: chat, email, sms, in_app, push.
#
# @return [Hash] workflow override entity
# @return [number] status
# - Returns 200 if successful.
def update_workflow_override_by_id(override_id, body)
put("/workflow-overrides/#{override_id}", body: body.to_json, headers: {'Content-Type': 'application/json'})
end

# Update tenant workflow ovverride
#
# @pathparams:
# @param `workflow_id` [String]
# @param `tenant_id` [String]
#
# @bodyParam:
# @param `active` [Boolean] - The status of the workflow.
# @param `preferenceSettings` [Hash] - The preference settings of the workflow. It should include any/all of following keys: chat, email, sms, in_app, push.
#
# @return [Hash] workflow override entity
# @return [number] status
# - Returns 200 if successful.
def update_tenant_workflow_override(workflow_id, tenant_id, body)
put("/workflow-overrides/workflows/#{workflow_id}/tenants/#{tenant_id}", body: body.to_json, headers: {'Content-Type': 'application/json'})
end

# Delete a workflow override by it's ID.
#
# @pathparams:
# @param `override_id` [Integer] The ID of the workflow override.
#
# @return [Hash] The result of the deletion.
# @return [number] status
# - Returns 200 if the workflow has been deleted correctly.
def delete_workflow_override(override_id)
delete("/workflow-overrides/#{override_id}")
end
end
end
end
4 changes: 3 additions & 1 deletion lib/novu/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
require "novu/api/subscribers"
require "novu/api/tenants"
require "novu/api/topics"
require "novu/api/workflow_Overrides"
Eazybright marked this conversation as resolved.
Show resolved Hide resolved
require_relative "version"

module Novu
Expand All @@ -41,6 +42,7 @@ class Client
include Novu::Api::Subscribers
include Novu::Api::Tenants
include Novu::Api::Topics
include Novu::Api::WorkflowOverrides

format :json

Expand Down Expand Up @@ -71,7 +73,7 @@ def initialize(access_token: nil, idempotency_key: nil, enable_retry: false, ret

self.class.default_options.merge!(headers: {
"Authorization" => "ApiKey #{@access_token}",
"User-Agent" => "novu/ruby/#{Novu::VERSION}"
"User-Agent" => "novu/ruby/#{Novu::VERSION}"
}
)

Expand Down
145 changes: 145 additions & 0 deletions spec/workflow_overrides_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
# frozen_string_literal: true

require "spec_helper"
require_relative "../lib/novu"

RSpec.describe Novu::Api::WorkflowOverrides do
let(:access_token) { "1234567890" }
let(:client) { Novu::Client.new(access_token: access_token) }
let(:base_uri) { "https://api.novu.co/v1" }
let(:override_id) { "985277" }
let(:workflow_id) { "3f71b3ef067" }
let(:tenant_id) { "ecaf52336" }

describe "#create_workflow_overrides" do
it "creates a workflow override" do
body = {
tenantId: "string",
workflowId: "string",
active: true
}

response_body = {
"data": {
"_environmentId": "<string>",
"_id": "<string>",
"_organizationId": "<string>",
"_tenantId": "<string>",
"_workflowId": "<string>",
"active": true,
"createdAt": "<string>",
"deleted": true,
"deletedAt": "<string>",
"deletedBy": "<string>",
"preferenceSettings": {
"chat": true,
"email": true,
"in_app": true,
"push": true,
"sms": true
},
"updatedAt": "<string>"
}
}.to_json

stub_request(:post, "#{base_uri}/workflow-overrides")
.with(body: body)
.to_return(status: 200, body: response_body)

result = client.create_workflow_overrides(body)

expect(result.body).to eq(response_body)
expect(result.code).to eq(200)
end
end

describe "#get_workflow_overrides" do
it "returns all workflow overrides" do
response_body = {
page: 0,
hasMore: false,
pageSize: 10,
data: [
{
_id: "63f71b3ef067290fa669106d"
}
]
}.to_json

stub_request(:get, "#{base_uri}/workflow-overrides")
.to_return(status: 200, body: response_body)

result = client.get_workflow_overrides

expect(result.body).to eq(response_body)
expect(result.code).to eq(200)
end
end

describe "#get_tenant_workflow_override" do
it "get tenant workflow overrides" do
stub_request(:get, "#{base_uri}/workflow-overrides/workflows/#{workflow_id}/tenants/#{tenant_id}")
.to_return(status: 200)

result = client.get_tenant_workflow_override(workflow_id, tenant_id)
expect(result.code).to eq(200)
end
end

describe "#get_workflow_override_by_id" do
it "get workflow override by it's ID" do
stub_request(:get, "#{base_uri}/workflow-overrides/#{override_id}")
.to_return(status: 200)

result = client.get_workflow_override_by_id(override_id)

expect(result.code).to eq(200)
end
end

describe "#update_workflow_override_by_id" do
it "update workflow override details" do
body = {
active: true
}

stub_request(:put, "#{base_uri}/workflow-overrides/#{override_id}")
.with(body: body)
.to_return(status: 200)

result = client.update_workflow_override_by_id(override_id, body)
expect(result.code).to eq(200)
end
end

describe "#update_tenant_workflow_override" do
it "update workflow override details" do
body = {
active: true
}

stub_request(:put, "#{base_uri}/workflow-overrides/workflows/#{workflow_id}/tenants/#{tenant_id}")
.with(body: body)
.to_return(status: 200)

result = client.update_tenant_workflow_override(workflow_id, tenant_id, body)
expect(result.code).to eq(200)
end
end

describe "#delete_workflow_override" do
it "delete a workflow override" do
response_body = {
data: true
}.to_json

stub_request(:delete, "#{base_uri}/workflow-overrides/#{override_id}")
.to_return(status: 200, body: response_body)

result = client.delete_workflow_override(override_id)

expect(result.body).to eq(response_body)
expect(result.code).to eq(200)
end
end
end