Skip to content

Instantly share code, notes, and snippets.

View kwhinnery's full-sized avatar

Kevin Whinnery kwhinnery

View GitHub Profile
# Download the 'Preview Release' version of the Python helper library from
# twilio.com/docs/python/install
from twilio.rest import Client
# Your Account Sid and Auth Token from twilio.com/user/account
account = 'AC421124bfab3052ad108f3e8c7a119cfb'
token = 'AUTH_TOKEN'
client = Client(account, token)
# Delete the service
// Load user year data
$.ajax('/ga/users').then(function(data) {
// Populate raw numbers
var usersYearFormatted = humanize.numberFormat(data.usersThisYear, 0);
var usersQuarterFormatted = humanize.numberFormat(data.usersThisQuarter,
0);
$('.users-year').text(usersYearFormatted);
$('.users-quarter').text(usersQuarterFormatted);
// Populate progress bar
$quarterGoal = $('.progress.current-goal .progress-bar');
var http = require('http');
var express = require('express');
var bodyParser = require('body-parser');
var KeenClient = require('keen-js');
// 1.) create an authenticated Keen analytics client
var keen = new KeenClient({
projectId: 'your project ID here',
writeKey: 'your write key here'
});
var client = new Twilio.Conversations.Client('token');
var convo = client.conversation('myCall');
convo.display('#them', '#me').then(function() {
console.log('now your local media is showing, as is theirs!');
}).catch(function(err) {
console.log('oops, something bad happened')
});
convo.on('participantJoined', function(participant) {
var client = new Twilio.IPMessaging.Client('token');
// Creates a reference to a channel that may or may not exist
var channel = client.channel('general');
// If there's such a thing as an online/offline channel, this serves as the way the channel
// gets updated when it's reconnected from an offline state. It could also serve as a way
// to get updated when the channel information is initially fetched from the server
//
// Fired when:
@kwhinnery
kwhinnery / sample_one.js
Last active February 19, 2016 04:43
Twilio IP Messaging is intended to help developers build chat applications, and is in public beta. Given the following options, which interface would you prefer to initialize the Twilio IP Messaging SDK and execute a few basic tasks? Vote here: https://twitter.com/kevinwhinnery/status/700445163672510468
var client = new Twilio.IPMessaging.Client('token');
var channel = client.getOrCreateChannelByUniqueName('general');
channel.join();
channel.listMessages().then(function(messages) {
console.log(messages);
}).catch(function(err) {
console.log(err);
});
@kwhinnery
kwhinnery / sync.js
Last active February 18, 2016 19:30
var map = client.sync.map('uniqueName');
map.set('foo', { bar: 42 }).then(function() {
console.log('set it!');
}).catch(function(err) {
console.log('dang it, dont have access');
});
// same as above...
map.set('foo', { bar: 42 }, function(err) {
var channel = client.channel('uniqueName');
channel.listMessages().then(function(messages) {
console.log(messages);
}).catch(function(err) {
console.log('whoops! I dont have access to this channel');
});
@kwhinnery
kwhinnery / demo.js
Last active February 9, 2016 22:58
var client = twilio.sync('jwt token here');
// Example Document interaction
var doc = client.Document('uniqueName');
doc.set({
foo: 'bar'
});
doc.on('update', function(e) {
var client = require('twilio')('sid', 'token');
var pager = client.messages.each({ pageSize: 100 });
pager.on('data', function(message) {
console.log(message.sid);
});
pager.on('end', function() {
console.log('no more messages!');