-
-
Notifications
You must be signed in to change notification settings - Fork 94
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
Basecamp 3 provider #180
Merged
Merged
Basecamp 3 provider #180
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
import {Embed} from '../model/Embed' | ||
import {BaseProvider} from '../provider/BaseProvider' | ||
import * as fs from 'fs' | ||
import {EmbedAuthor} from '../model/EmbedAuthor' | ||
|
||
import TurndownService from 'turndown' | ||
|
||
class Basecamp extends BaseProvider { | ||
private turndown: TurndownService | ||
private colorCreated = 0x00ff00 | ||
private colorDeleted = 0xff0000 | ||
private colorArchived = 0x8b0000 | ||
private colorUnarchived = 0x66cdaa | ||
private colorEdited = 0x40e0d0 | ||
|
||
constructor() { | ||
super() | ||
this.turndown = new TurndownService() | ||
} | ||
|
||
public getName(): string { | ||
return 'Basecamp' | ||
} | ||
|
||
public getPath(): string { | ||
return 'basecamp' | ||
} | ||
|
||
public async parseData(): Promise<void> { | ||
// console.log(this.body) | ||
// fs.appendFile('bc.json', JSON.stringify(this.body) + '\n\n', function (err) { | ||
// if (err) { | ||
// return console.log(err) | ||
// } | ||
// }) | ||
//let embed: Embed | ||
switch (this.body.kind) { | ||
case 'comment_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted comment', ['title'], true) | ||
break | ||
case 'comment_created': | ||
this.prepareEmbed(this.colorCreated, 'added comment', ['title'], true) | ||
break | ||
case 'todo_created': | ||
this.prepareEmbed(this.colorCreated, 'created todo', ['title']) | ||
break | ||
case 'todo_completed': | ||
this.prepareEmbed(0x4ca3dd, 'completed todo', ['title']) | ||
break | ||
case 'todo_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived todo', ['title']) | ||
break | ||
case 'todo_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived todo', ['title']) | ||
break | ||
case 'todo_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted todo', ['title']) | ||
break | ||
case 'comment_content_changed': | ||
this.prepareEmbed(this.colorEdited, 'changed comment', ['title'], true) | ||
break | ||
case 'todolist_description_changed': | ||
this.prepareEmbed(this.colorEdited, 'changed todolist\'s description', ['title'], true) | ||
break | ||
case 'todolist_created': | ||
this.prepareEmbed(this.colorCreated, 'created todolist', ['title'], true) | ||
break | ||
case 'todolist_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived todolist', ['title']) | ||
break | ||
case 'todolist_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived todolist', ['title']) | ||
break | ||
case 'todolist_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted todolist', ['title']) | ||
break | ||
case 'message_created': | ||
case 'message_active': | ||
this.prepareEmbed(this.colorCreated, 'published message', ['title'], true) | ||
break | ||
case 'message_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived message', ['title'], true) | ||
break | ||
case 'message_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived message', ['title'], true) | ||
break | ||
case 'message_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted message', ['title'], true) | ||
break | ||
case 'comment_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived comment', ['title'], true) | ||
break | ||
case 'comment_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived comment', ['title'], true) | ||
break | ||
case 'vault_created': | ||
this.prepareEmbed(this.colorCreated, 'created doc\'s folder', ['title'],) | ||
break | ||
case 'vault_copied': | ||
this.prepareEmbed(this.colorCreated, 'copied doc\'s folder', ['title'],) | ||
break | ||
case 'vault_inserted': | ||
this.prepareEmbed(this.colorCreated, 'added doc\'s folder', ['title'],) | ||
break | ||
case 'vault_title_changed': | ||
this.prepareEmbed(this.colorEdited, 'changed folder\'s title', ['title'],) | ||
break | ||
case 'vault_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted folder', ['title'], true) | ||
break | ||
case 'vault_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived folder', ['title'], true) | ||
break | ||
case 'vault_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived folder', ['title'], true) | ||
break | ||
case 'upload_created': | ||
case 'upload_active': | ||
this.prepareEmbed(this.colorCreated, 'uploaded file', ['title'], true) | ||
break | ||
case 'upload_copied': | ||
this.prepareEmbed(this.colorCreated, 'copied file', ['title'], true) | ||
break | ||
case 'upload_inserted': | ||
this.prepareEmbed(this.colorCreated, 'added file', ['title'], true) | ||
break | ||
case 'upload_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived file', ['title'], true) | ||
break | ||
case 'upload_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived file', ['title'], true) | ||
break | ||
case 'upload_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted file', ['title'], true) | ||
break | ||
case 'document_created': | ||
case 'document_active': | ||
this.prepareEmbed(this.colorCreated, 'created document', ['title'], true) | ||
break | ||
case 'document_copied': | ||
this.prepareEmbed(this.colorCreated, 'copied document', ['title'], true) | ||
break | ||
case 'document_inserted': | ||
this.prepareEmbed(this.colorCreated, 'added document', ['title'], true) | ||
break | ||
case 'document_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived document', ['title'], true) | ||
break | ||
case 'document_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived document', ['title'], true) | ||
break | ||
case 'document_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted document', ['title'], true) | ||
break | ||
case 'google_document_created': | ||
case 'google_document_active': | ||
this.prepareEmbed(this.colorCreated, 'created Google Document', ['title'], true) | ||
break | ||
case 'google_document_copied': | ||
this.prepareEmbed(this.colorCreated, 'copied Google Document', ['title'], true) | ||
break | ||
case 'google_document_inserted': | ||
this.prepareEmbed(this.colorCreated, 'added Google Document', ['title'], true) | ||
break | ||
case 'google_document_archived': | ||
this.prepareEmbed(this.colorArchived, 'archived Google Document', ['title'], true) | ||
break | ||
case 'google_document_unarchived': | ||
this.prepareEmbed(this.colorUnarchived, 'unarchived Google Document', ['title'], true) | ||
break | ||
case 'google_document_trashed': | ||
this.prepareEmbed(this.colorDeleted, 'deleted Google Document', ['title'], true) | ||
break | ||
default: | ||
console.log('unknown event ' + this.body.kind) | ||
this.prepareEmbed(0xf0ff00, this.body.kind, ['title', 'type'], true) | ||
break | ||
} | ||
} | ||
|
||
private escapeString(str: string): string { | ||
if (!str) { | ||
return '' | ||
} | ||
return this.turndown.turndown(str) | ||
} | ||
|
||
private prepareEmbed(color: number, title: string, fields: Array<string> = [], content = false): Embed { | ||
const embed = new Embed() | ||
embed.url = this.body.recording.app_url | ||
embed.color = color | ||
embed.title = `${title} on ${this.body.recording.bucket.name} / ${this.body.recording.parent.type} : ${this.body.recording.parent.title}` | ||
embed.author = new EmbedAuthor() | ||
embed.author.name = this.body.recording.creator.name | ||
embed.author.icon_url = this.body.recording.creator.avatar_url | ||
if (content) { | ||
embed.description = this.escapeString(this.body.recording.content).substring(0, 4096) | ||
} | ||
embed.fields = [] | ||
const body = this.body | ||
fields.forEach(function (field) { | ||
switch (field) { | ||
case 'title': | ||
embed.fields.push({name: 'Title', value: body.recording.title, inline: true}) | ||
break | ||
case 'type': | ||
embed.fields.push({name: 'Type', value: body.recording.type, inline: true}) | ||
} | ||
}) | ||
this.addEmbed(embed) | ||
return embed | ||
} | ||
} | ||
|
||
export {Basecamp} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove these commented out bits please?