Skip to content
Open
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
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,17 @@ body = {
}
client.update_subscriber_credentials('<insert-subscriber-id>', body)
```
- Upsert subscriber credentials: `upsert_subscriber_credentials(subscriber_id, body)`

```ruby
body = {
'providerId' => '<insert-provider-id>',
'credentials' => {
# Insert all fields here
}
}
client.upsert_subscriber_credentials('<insert-subscriber-id>', body)
```

- Delete subscriber credentials by providerId: `delete_subscriber_credentials(subscriberId, providerId)`

Expand Down
20 changes: 19 additions & 1 deletion lib/novu/api/subscribers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ def delete_subscriber(subscriber_id)
delete("/subscribers/#{subscriber_id}")
end

# Update subscriber credentials from the Novu platform. Subscriber credentials associated to the delivery methods such as slack and push tokens.
# Update subscriber credentials from the Novu platform. Subscriber credentials
# associated to the delivery methods such as slack and push tokens.
#
# @pathparams:
# @param `subscriber_id` [String] The ID of the subscriber to update credentials.
Expand All @@ -103,6 +104,23 @@ def update_subscriber_credentials(subscriber_id, body)
put("/subscribers/#{subscriber_id}/credentials", body: body)
end

# Upsert subscriber credentials from the Novu platform. Subscriber credentials
# associated to the delivery methods such as slack and push tokens.
#
# @pathparams:
# @param `subscriber_id` [String] The ID of the subscriber to update credentials.
#
# @bodyparams:
# @param `providerId` [String] The provider identifier for the credentials
# @param `credentials` [Hash] Credentials payload for the specified provider
#
# @return [Hash] Hash of updated subscriber credentials entity
# @return [number] status
# - Returns 200 if the subscriber credentials has been updated correctly.
def upsert_subscriber_credentials(subscriber_id, body)
patch("/subscribers/#{subscriber_id}/credentials", body: body)
end

# Delete subscriber credentials by providerId
# Delete subscriber credentials such as slack and expo tokens.
#
Expand Down
22 changes: 22 additions & 0 deletions spec/subscribers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,28 @@
end
end

describe "#upsert_subscriber_credentials" do
it "upserts the subscriber credentials" do
body = {
providerId: "slack",
credentials: { token: "new-slack-token" }
}.to_json

response_body = {
_id: "63f71b3ef067290fa669106d"
}.to_json

stub_request(:patch, "#{base_uri}/subscribers/#{subscriber_id}/credentials")
.with(body: body)
.to_return(status: 200, body: response_body)

result = client.upsert_subscriber_credentials(subscriber_id, body)

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

describe "#delete_subscriber_credentials" do
it "#Delete subscriber credentials such as slack and expo tokens." do
providerId = 'slack'
Expand Down