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 / unzip.rb
Created August 25, 2014 17:38
Unzip to S3
Zip::ZipFile.open(zipfile) do |zip|
zip.each do |f|
path = File.join('/your/aws/path', f.name)
aws = AWS::S3.new.buckets['yourbucket'][path]
aws.write(file: zip.get_output_stream(f))
aws_url = aws.public_url(secure: true).to_s
end
end
end
@tstachl
tstachl / desk_api.rb
Created August 21, 2014 17:29
Creating a case with interactions using the desk_api gem.
require 'desk_api'
# Authentication
DeskApi.configure do |config|
config.username = 'jsmith@example.com'
config.password = '1234secret'
config.endpoint = 'https://example.desk.com'
end
# Create the case
{
"_links": {
"company": {
"href": "/api/v2/companies/1",
"class": "company"
}
}
}
new DESK.Widget({
id: 'test', // The ID of the element to place the button into
version: 1,
site: 'hecos.desk.com',
port: '80',
type: 'chat',
displayMode: 0, //0 for popup, 1 for lightbox
features: {
offerAlways: false,
offerAgentsOnline: true,
@tstachl
tstachl / script.rb
Created August 13, 2014 19:41
DeskApi Timeout fix
require 'desk_api'
DeskApi::Default::CONNECTION_OPTIONS[:request] = {
open_timeout: 45,
timeout: 45
}
client = DeskApi::Client.new({
token: 'TOKEN',
token_secret: 'TOKEN_SECRET',
@tstachl
tstachl / upload.rb
Created August 7, 2014 00:37
Example on how you can upload customers to desk.com using the desk_api gem.
require 'desk_api'
require 'csv'
DeskApi.configure do |config|
config.username = 'you@example.com'
config.password = 'Top$ecret1'
config.endpoint = 'https://example.desk.com'
end
CSV.foreach('./customers.csv', headers: true) do |csv|
<apex:page standardStylesheets="false" showHeader="false" sidebar="false" recordSetVar="macros" docType="html-5.0"
standardController="Macro__c" extensions="ApplyMacroControllerExtension" title="Select Macro" >
<apex:includeScript value=""/>
<apex:includeScript value="/support/console/30.0/integration.js"/>
<apex:includeScript value="/soap/ajax/30.0/connection.js"/>
<apex:includeScript value="/support/api/30.0/interaction.js"/>
<apex:includeScript value="/canvas/sdk/js/30.0/publisher.js"/>
<apex:stylesheet value="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css" />
ticket = DeskApi.cases.create({
external_id: 123456,
subject: 'Subject',
description: 'Description',
priority: 1,
status: 'resolved',
type: 'email',
labels: ['Label 1', 'Label 2'],
custom_fields: {
my_key: 'My Value'
@tstachl
tstachl / CaseThemeAddition.html
Created June 20, 2014 21:47
This is some javascript and css code that allows you to have tabbed email and note replies in desk.com.
<script>
$(function() {
var tid = $('#tabs .ui-state-active a').attr('href').replace('#tabs-tid_', '')
, sel = '#email_reply_div_tid_' + tid
setTimeout(function() {
$(sel).prepend([
'<div>',
' <ul class="reply-toggle">',
' <li class="active">',
@tstachl
tstachl / DeskTriggerHelper.class
Last active November 21, 2016 19:43
Fetch data trigger.
public class DeskTriggerHelper
{
private static DeskClient CLIENT = new DeskClient(new Map<String, String>{
'token' => 'TOKEN',
'tokenSecret' => 'TOKEN_SECRET',
'consumerKey' => 'CONSUMER_KEY',
'consumerSecret' => 'CONSUMER_SECRET',
'endpoint' => 'https://example.desk.com'
});