Skip to content

Instantly share code, notes, and snippets.

View dpawluk's full-sized avatar

Daniel Pawluk dpawluk

  • Zendesk
  • Wisconsin
View GitHub Profile
@dpawluk
dpawluk / ZendeskCurlAlternative
Created June 6, 2014 06:35
This is a request to Zendesk using the PHP Requests library, so much easier and less painful than PHP's built-in cURL crappery. Maybe can incorporate into wrapper, who knows...
<?php
include("vendor/autoload.php");
$subdomain = "subdomain";
$username = "[email protected]";
$password = "password";
$headers = array('Content-Type' => 'application/json');
$options = array('auth' => array($username, $password));
$newTicket = array (
'ticket' => array (
@dpawluk
dpawluk / show_diff_forms
Created June 9, 2014 17:12
form selection based on orgs
$('span.nesty-input').detach();
var formOptions = $("#request_issue_type_select option");
var nullOption = $("<option value>-</option>");
var externalOptions = _.chain(formOptions)
.filter(function(option) {
return option.value == 33297;
})
.value();
var internalOptions = _.chain(formOptions)
@dpawluk
dpawluk / threadedtickets.py
Created June 9, 2014 22:13
threading tickets is toooooo fast for Zendesk
import thread
import threading
import requests
s = requests.Session()
s.headers.update({'Content-Type': 'application/json'})
s.auth = ('USERNAME/token','TOKEN')
#r = s.post("http://requestb.in/1hjs6jw1", data=payload)
ticketCount = 4000
@dpawluk
dpawluk / aeng_get.php
Created July 22, 2014 21:41
PHP Google AppEngine Example
<?php
$username = '__USERNAME__';
$password = '__PASSWORD__';
$url = 'https://__SUBDOMAIN__.zendesk.com/api/v2/tickets.json';
//$data = http_build_query($data); //use if sending data, ticket object or whatnot
$context_opts = [
'http' => [
'method' => 'GET',
'header' => "Content-Type: application/json\r\n" .
@dpawluk
dpawluk / app.js
Last active August 29, 2015 14:04
Abstracting and extending portions of ZAF using commonJS
(function() {
var Client = require('client.js');
return {
requests: {
requestOne: function() {
return {
url: '/api/v2/tickets.json'
};
}
@dpawluk
dpawluk / submission_permission.js
Created August 1, 2014 22:38
Snippet for Zendesk Help Center - permission for ticket submission based on user tag.
var req_link = $('.submit-a-request'); // class selector for submit request link, now we can req_link.hide() and req_link.show()
var sub_tag = 'tix_sub_approved'; // sub_tag variable essentially holds the 'approved tag' value, whatever you decide
var hc_user = HelpCenter.user; // Just a shortcut to type less later
var user_path = window.location.pathname; // user's current path (everything after the tld, HC home pathname is "/hc/en-us/")
var is_approved = false;
if (hc_user.hasOwnProperty('tags')) { // anonymous user objects don't have a 'tags' property, first check if it exists...no? then no link
if(hc_user.tags.indexOf(sub_tag) > -1) {
req_link.show(); // if tags[] exists and one of them matches approved tag, show link
is_approved = true; // since this is the only case where we approve a user, lets make a shortcut for future checking...
var currentPath = window.location.pathname;
if (currentPath.indexOf('/hc/en-us') > -1) {
$.get('/api/v2/users.json?role[]=admin&role[]=agent')
.done(function(data){
var select = [];
console.log(data);
_.each(data.users, function(user){
select.push("<option value=\"" + user.id + "\">" + user.name + "</option>");
});
console.log(select);
@dpawluk
dpawluk / servo.py
Created August 23, 2014 00:15
python servo control
# Servo Control
import time
def set(property, value):
try:
f = open("/sys/class/rpi-pwm/pwm0/" + property, 'w')
f.write(value)
f.close()
except:
print("Error writing to: " + property + " value: " + value)
@dpawluk
dpawluk / verify_py_zd.py
Created August 29, 2014 00:28
Verifying that httplib works with ZD api.
import httplib
import base64
import string
connection = httplib.HTTPSConnection('SUBDOMAIN.zendesk.com', 443, timeout = 30)
auth = base64.encodestring('%s:%s' % ("EMAIL/token", "APITOKEN")).replace('\n', '')
headers = {"Authorization":"Basic " + auth}
connection.request('GET', '/api/v2/users/me.json', None, headers)
try:
response = connection.getresponse()
content = response.read()
@dpawluk
dpawluk / delete_hc_articles.py
Created August 29, 2014 05:17
Stupid random utility I wrote to play with paging requests in pythons. Gets all and deletes HC articles...still not up to par for pagination. Flattening needs better list comprehension logic.
import requests
from requests.auth import HTTPBasicAuth
import json
auth = HTTPBasicAuth('EMAIL_ADDR/token', 'TOKEN')
headers = {'content-type': 'application/json'}
s = requests.Session()