Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
@tstachl
tstachl / implementation.html
Created August 23, 2012 11:57
NodeProxy Desk.com implementation
<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 November 22, 2012 16:40
SSEGeoService allows you to set the new Geolocation fields of any object by running an address string through the Google Geolocation API.
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 April 6, 2013 22:30
Desk.com Multipass SSO example.
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 April 13, 2013 02:07
Example talking to the Desk.com API from Salesforce (Apex).
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 22:10
desk.com OAuth with 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 August 13, 2013 23:21
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.
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 August 18, 2013 22:01
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.
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 December 21, 2015 23:49
Monkey patch field encryption into Mongoid.
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 September 12, 2013 17:13
Creating a new desk.com email case using Basic Auth from Google Apps Script.
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 September 24, 2013 00:21
desk.com Multipass script written in python.
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