Skip to content

Instantly share code, notes, and snippets.

View tstachl's full-sized avatar

Thomas Stachl tstachl

  • Pilina
  • Remote
View GitHub Profile
{
"_links": {
"company": {
"href": "/api/v2/companies/1",
"class": "company"
}
}
}
@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 = '[email protected]'
config.password = '1234secret'
config.endpoint = 'https://example.desk.com'
end
# Create the case
@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 / ENV
Last active August 29, 2015 14:06
desk.com OAuth example using expressjs.
BASE_URL: https://desk-oauth-express.herokuapp.com
CONSUMER_KEY: MY_CONSUMER_KEY
CONSUMER_SECRET: MY_CONSUMER_SECRET
SESSION_SECRET: MY_SESSION_SECRET
@tstachl
tstachl / create.php
Created September 25, 2014 21:29
Creating a case using PHP and CURL in desk.com
<?php
$json = json_encode(array(
"subject" => "Test",
"description" => "testing",
"message" => array(
"subject" => "Test",
"body" => "Test",
"direction" => "in",
"to" => "[email protected]",
#!/usr/bin/perl
use strict;
use warnings;
use feature qw(say);
use JSON;
use WWW::Curl::Easy;
my $DeskSite = 'https://example.desk.com';
@tstachl
tstachl / assign_user.php
Created November 5, 2014 16:17
Assigning a user to a case written in PHP.
<?php
$json = json_encode(array(
'_links' => array(
'assigned_user' => array(
'href' => '/api/v2/users/16096734',
'class' => 'user'
)
)
));
@tstachl
tstachl / mycases.js
Created November 12, 2014 00:24
Load all cases without pagination on the My Cases page in the desk.com portal by adding this snippet of jquery code. It basically loads the next page of each page that has a next page specified and appends all the cases to the initial page.
(function($) {
function nextPage(url, callback) {
$.get(url, function(data, textStatus, jqXHR) {
var cases = $(data).find('.mycases tbody tr')
, nextUrl = $(data).find('#pagination a.next_page');
callback(cases);
if (nextUrl && nextUrl.attr('href')) nextPage(nextUrl.attr('href'), callback);
}, 'html');
# configure the client
client = DeskApi::Client.new username: '[email protected]', password: '$uper$ecretP@ssword', endpoint: 'https://example.desk.com'
# create the customer using a plain request
resp = client.post('/api/v2/customers', {
first_name: 'John',
last_name: 'Doe',
emails: [{ type: 'home', value: '[email protected]' }]
})
@tstachl
tstachl / multipass.pl
Created November 18, 2014 19:43
A desk.com multipass example written in perl.
#!/usr/bin/perl -w
use Digest::SHA qw( sha1 hmac_sha1 );
use Crypt::Random qw( makerandom_octet );
use DateTime;
use JSON;
use Crypt::CBC;
use Digest::HMAC;
use URL::Encode qw( url_encode_utf8 );
use MIME::Base64::Perl;