Pastebin API - devuxd/SeeCodeRun GitHub Wiki

Description

Pastebins in SeeCodeRun can be shared and you can know when that happens.

API Navigation

Pastebin events are part of the external communications SeeCodeRun offers.

Commands

Share pastebin

This command is used by the Share UI element to copy pastebins. Be aware that the copy is made based on the content the original pastebin had at the time of copying. You can share pastebins so others can work independently based on your current work by taking your current URL and add a ":" right before your pastebin ID starts. A pastebin ID is a unique identifier that lets SeeCodeRun recover your previous work on the platform, it is the string that goes after "https://seecode.run/#".

Note: Do not forget your SeeCodeRun URL(or pastebin id). Otherwise, it will be forever lost in our pastebin sea.

Example

Normally, your browser shows an URL like this one: "https://seecode.run/#-KhF_XVS9OsV8sFl2Ek_", to share the pastebin it should look like this "https://seecode.run/#:-KhF_XVS9OsV8sFl2Ek_". Once the URL is loaded, a new copy of the curretn content of the original pastebin is created.

Events

SeeCodeRun publishes two types of events when users share pastebins: UI and System events.

UI Events

There events are emitted once the the user interacts with the Share UI element.

"shareLinkShown"

Every time the user clicks on the share button, this event will be emitted.

"shareLinkCopied"

Every time the user copies the share link, this event will be emitted.

"shareLinkClicked"

Every time the user clicks the share link, this event will be emitted.

System Events

These events are responses from SeeCodeRun to user actions.

"shareLinkUsed"

Every time a user creates a pastebin based via share command, this event will be emitted. Either the user used the command directly, or the link shown in the Share UI element.

LifeCycle

Previous events are connected as follows: "shareLinkShown" --> "shareLinkCopied" or "shareLinkClicked" --> "shareLinkUsed".

Note: There are cases not done via SeeCodeRun UI. Well, it is a URL, once you got the link you can use it afterwards or use the URL share command ":" to create it.

Usage

To listen pastebin share events, provide the pastebin id and the path "content/share/events":

var shareEventsFirebase =
 new Firebase(
`https://seecoderun.firebaseio.com/test/-KhGIb91d_T3gIjfW5dq/content/share/events`
);

shareEventsFirebase
.limitToLast(1)
.on('child_added', 
function child_added(snapshot) {
        var data = snapshot.val();
	console.log(data);
    });

Once you listen to the reference data changes, each event data will look like this:

 {event: "shareLinkShown", timestamp: 1491716254084}

Try it!

This fiddle shows how it works.

Note: Due to cross-origin constraints, the "most" elegant way of publishing SeeCodeRun events is via Firebase.