diff --git a/README.md b/README.md index 415dadf..f48d423 100644 --- a/README.md +++ b/README.md @@ -665,6 +665,17 @@ body = { } client.update_subscriber_credentials('', body) ``` +- Upsert subscriber credentials: `upsert_subscriber_credentials(subscriber_id, body)` + +```ruby +body = { + 'providerId' => '', + 'credentials' => { + # Insert all fields here + } +} +client.upsert_subscriber_credentials('', body) +``` - Delete subscriber credentials by providerId: `delete_subscriber_credentials(subscriberId, providerId)` diff --git a/lib/novu/api/subscribers.rb b/lib/novu/api/subscribers.rb index a54f24a..83a5c1b 100644 --- a/lib/novu/api/subscribers.rb +++ b/lib/novu/api/subscribers.rb @@ -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. @@ -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. # diff --git a/spec/subscribers_spec.rb b/spec/subscribers_spec.rb index 1748285..0f4113b 100644 --- a/spec/subscribers_spec.rb +++ b/spec/subscribers_spec.rb @@ -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'