Skip to content

Instantly share code, notes, and snippets.

Thomas Stachl tstachl

Block or report user

Report or block tstachl

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@tstachl
tstachl / implementation.html
Created Aug 23, 2012
NodeProxy Desk.com implementation
View implementation.html
<script>
function callback() {
$.widget('desk.contact', $.ui.autocomplete, require('contact'));
$('.salesforce input').contact({
category: 'company',
username: 'username',
password: 'password',
clientId: 'SalesforceClientId',
clientSecret: 'SalesforceClientSecret',
mapping: {
@tstachl
tstachl / gist:4132052
Created Nov 22, 2012
SSEGeoService allows you to set the new Geolocation fields of any object by running an address string through the Google Geolocation API.
View gist:4132052
public class SSEGeoService
{
class GeoException extends Exception {}
@future (callout=true)
static public void setLocation(String sobj, String field, String id, String address)
{
if (String.isBlank(address)) {
throw new SSEGeoService.GeoException('Address can not be blank.');
}
@tstachl
tstachl / SSO.java
Created Apr 6, 2013
Desk.com Multipass SSO example.
View SSO.java
import org.json.JSONObject;
import org.apache.commons.codec.binary.Base64;
import java.util.Arrays;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.net.URLEncoder;
import java.security.MessageDigest;
@tstachl
tstachl / DeskSample.java
Created Apr 13, 2013
Example talking to the Desk.com API from Salesforce (Apex).
View DeskSample.java
public class DeskSample
{
private static String OAUTH_KEY = 'youroauthkey';
private static String OAUTH_SECRET = 'youroauthsecret';
private static String ACCESS_TOKEN = 'youraccesstoken';
private static String ACCESS_TOKEN_SECRET = 'youraccesstokensecret';
public static String DESK_SITENAME = 'yoursite';
public static Void doRequest()
@tstachl
tstachl / oauth.php
Created May 28, 2013
desk.com OAuth with php.
View oauth.php
<?php
$subdomain = 'your-sitename';
$req_url = 'https://'.$subdomain.'.desk.com/oauth/request_token';
$authurl = 'https://'.$subdomain.'.desk.com/oauth/authorize';
$acc_url = 'https://'.$subdomain.'.desk.com/oauth/access_token';
$api_url = 'https://'.$subdomain.'.desk.com/api/v2';
// SET YOUR CALLBACK URL
$callback = 'http://localhost:3000/auth/desk/callback';
@tstachl
tstachl / create_customer.ps1
Created Aug 13, 2013
This is a PowerShell v2 script that performs a simple customer creation action on the desk.com API and outputs the status text. Either "created" if the customer has been created or "Unprocessable Entity" if a customer with the same email already exists.
View create_customer.ps1
function createCustomer($first_name, $last_name, $title, $background, $email) {
$subdomain = "your-site-subdomain"
$username = "your@username.com"
$password = "YoUrPaSsWoRd"
$body = @"
{
"first_name": "$first_name",
"last_name": "$last_name",
"title": "$title",
"background": "$background",
@tstachl
tstachl / api_content_type.rb
Created Aug 18, 2013
This is a simple Rack Middleware to set the request content type for specific routes. It checks if a content type is set and does not override the existing one. The options allow you to specify the request methods, path (with a string or a regular expression) and the content type to be set.
View api_content_type.rb
module Rack
class ApiContentType
def initialize(app, methods = [:post, :patch], path = /^\/api\/v2+/, content_type = 'application/json')
@app = app
@methods = (methods.is_a?(Array) ? methods : [methods]).map{ |item| item.to_s.upcase }
@path = path
@content_type = content_type
end
def call(env)
@tstachl
tstachl / mongoid_encrypted.rb
Last active Dec 21, 2015
Monkey patch field encryption into Mongoid.
View mongoid_encrypted.rb
class Mongoid::Fields::Standard
# Is the field encrypted or not?
#
# @example Is the field encrypted?
# field.encrypted?
#
# @return [ true, false ] If the field is encrypted.
#
# @since 4.0.0
def encrypted?
@tstachl
tstachl / google_apps_post_request.js
Created Sep 12, 2013
Creating a new desk.com email case using Basic Auth from Google Apps Script.
View google_apps_post_request.js
var url = "https://yoursitename.desk.com/api/v2/cases";
var options = {
"method": "post",
"headers": {
"Authorization": "Basic " + Utilities.base64Encode("you@example.com:yourpassword")
},
"payload": {
"type": "email",
"subject": "Email Case Subject",
"priority": 4,
@tstachl
tstachl / multipass.py
Created Sep 24, 2013
desk.com Multipass script written in python.
View multipass.py
from Crypto import Random
from Crypto.Cipher import AES
from datetime import datetime, timedelta
from isodate import datetime_isoformat
import base64
import hashlib
import hmac
import urllib
import json
You can’t perform that action at this time.