This repository has been archived by the owner on Mar 22, 2024. It is now read-only.
generated from jshawl/saas-starter
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
67 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
db/migrate/20231028141221_add_attachments_to_notifications.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
class AddAttachmentsToNotifications < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :notifications, :attachments, :json, default: [] | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,18 +16,38 @@ The HTTP API is how emails are sent from Continuous Integration environments. | |
|to|string|true| | ||
|subject|string|true| | ||
|body|string|false| | ||
|attachments|array|false| | ||
|
||
#### Attachments | ||
|
||
|name|type|required|description| | ||
|---|---|---| | ||
|type|string|true|The content's MIME type| | ||
|content|string|true|The Base64 encoded content of the attachment| | ||
|filename|string|true|The attachment's filename| | ||
|
||
### Example | ||
|
||
#### application/x-www-form-urlencoded | ||
```bash | ||
curl --request POST 'https://www.cinotify.cc/api/notify' \ | ||
-d "[email protected]&subject=building main&body=hello." | ||
-d "[email protected]&subject=building main&body=hello.&attachments[][type]=text/plain&attachments[][content]=aGVsbG8sIHdvcmxkIQ==&attachments[][filename]=hello.txt" | ||
``` | ||
|
||
#### json | ||
```bash | ||
curl -X POST 'https://www.cinotify.cc/api/notify' \ | ||
-H "Content-Type: application/json" \ | ||
-d '{"to":"[email protected]", "subject": "building main", "body":"hello."}' | ||
-d '{ | ||
"to": "[email protected]", | ||
"subject": "building main", | ||
"body": "hello.", | ||
"attachments": [ | ||
{ | ||
"type": "text/plain", | ||
"content": "aGVsbG8sIHdvcmxkIQ==", | ||
"filename": "hello.txt" | ||
} | ||
] | ||
}' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -56,4 +56,25 @@ | |
} | ||
end.to change { Notification.count }.by(2) | ||
end | ||
it 'supports attachments' do | ||
stub_request(:post, 'https://api.sendgrid.com/v3/mail/send') | ||
.with( | ||
body: '{"from":{"email":"[email protected]"},"subject":"hello w/ attachments","personalizations":[{"to":[{"email":"[email protected]"}]}],"content":[{"type":"text/plain","value":"Please see the attached file(s)"}],"attachments":[{"content":"VGhpcyBpcyBhIGZpbGUgdG8gYmUgYXR0YWNoZWQgdG8gYW4gZW1haWwuCg==","type":"text/plain","filename":"attachment.txt"}]}' | ||
) | ||
.to_return(status: 200, body: '[]', headers: {}) | ||
expect do | ||
post :notify, params: { | ||
to: '[email protected]', | ||
subject: 'hello w/ attachments', | ||
body: 'Please see the attached file(s)', | ||
attachments: [ | ||
{ | ||
content: Base64.strict_encode64(File.read("spec/fixtures/attachment.txt")), | ||
type: "text/plain", | ||
filename: "attachment.txt" | ||
} | ||
] | ||
} | ||
end.to change { Notification.count }.by(1) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
This is a file to be attached to an email. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters