Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
desk.ready(function() {
desk.interaction.ajax('/api/v2/customers/search?email=tstachl%40salesforce.com', {
method: 'GET',
callback: function(data) {
if (data.status === 200 && data.payload.total_entries > 0) {
var customer = data.payload.entries.first;
desk.interaction.screenPop(customer.id, 'object=customer', function(response) {
if (response.result) {
alert('screenPop successful.');
} else {
def parse_signed_request(request, max_age=3600)
# Split the signed request on the first period. The result is two strings: the hashed Based64 context signed with the consumer secret and the Base64 encoded context itself.
encoded_sig, enc_envelope = request.split('.', 2)
envelope = JSON.parse(base64_url_decode(enc_envelope)).with_indifferent_access # Needs ActiveSupport
algorithm = envelope[:algorithm]
# ADDITIONAL: Check the algorithm is HMAC SHA-256
if algorithm != 'HMACSHA256'
raise 'Invalid request. (Unsupported algorithm.)'
end
#!/usr/bin/env node
var resolve = require('path').resolve
, connect = require('connect')
, https = require('https')
, fs = require('fs');
var server = connect()
, path = resolve('.')
, port = process.env['PORT'] || 3000;
@tstachl
tstachl / customers.java
Created September 3, 2015 17:57
This is an untested example of how you could use the Desk.com API to fetch all customers in java.
// Use:
// Desk client = new Desk('support@example.com', '$upp0rt!', 'https://example.desk.com');
// JSONObject[] customers = client.getAllCustomers();
class Desk {
public Desk(String username, String password, String endpoint) {
this.username = username;
this.password = password;
this.endpoint = endpoint;
@tstachl
tstachl / index.html
Created August 31, 2015 23:34
Updating the draft using Desk.com Canvas.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Update Draft</title>
<meta name="description" content="A Desk.com canvas app example that updates a draft.">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
<script src="//ajax.deskapi.com/libs/desk/canvas/1.0.0/desk-canvas-all.js"></script>
<script>
@tstachl
tstachl / create_case.rb
Created June 8, 2015 15:43
Create an outbound email case for a customer by email.
require 'desk_api' # @see https://github.com/forcedotcom/salesforce-deskcom-api
# authenticate `DeskApi` with your Desk.com instance
#####
# FIND OR CREATE CUSTOMER
#####
# you should get the customer data from your system
customer_data = {
first_name: 'John',
last_name: 'Smith',
@tstachl
tstachl / desk.pl
Last active August 29, 2015 14:21
Calling the Desk.com API in perl using Net::OAuth.
use strict;
use warnings;
use Net::OAuth 0.20;
use Data::Random qw(:all);
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A;
use HTTP::Request::Common;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new;
$ openssl s_client -connect desk.com:443
CONNECTED(00000003)
depth=1 /C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
verify error:num=20:unable to get local issuer certificate
verify return:0
---
Certificate chain
0 s:/C=US/ST=California/L=San Francisco/O=Salesforce.com, Inc./CN=*.desk.com
i:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
1 s:/C=US/O=DigiCert Inc/CN=DigiCert SHA2 Secure Server CA
{% if article.number_of_attachments > 0 %}
<div id='attachments'>
<strong>{{system.snippets.attachments}}</strong>
<ul>
{% for attachment in article.kb_article_attachments %}
<li>
<a href="{{ attachment.faq_download_url }}" class="kb_article_attachment_a" target="_blank">{{ attachment.name }}</a>
</li>
{% endfor %}
</ul>
<div class="agent_company_section">
<span class="agent_company_section_label">{{ LABEL }}</span>
<div class="agent_company_section_data field_company_name">
<input class="default customer_record_input_field" type="text" value="{{ company.custom_KEY }}" disabled>
</div>
</div>