Skip to content

Instantly share code, notes, and snippets.

View wadewegner's full-sized avatar

Wade Wegner wadewegner

View GitHub Profile
@wadewegner
wadewegner / AssociationUriMapper.cs
Created January 29, 2014 21:23
Code used by the WindowsPhoneOAuth sample.
class AssociationUriMapper : UriMapperBase
{
public override Uri MapUri(Uri uri)
{
var tempUri = System.Net.HttpUtility.UrlDecode(uri.ToString());
if (tempUri.Contains("sfdc://success"))
{
var querystring = tempUri.Substring(tempUri.IndexOf("#") + 1);
var split = querystring.Split('&');
@wadewegner
wadewegner / WebAuthenticationBroker.cs
Last active August 29, 2015 13:55
Sample code for using the WebAuthorizationBroker to authenticate with Salesforce.com using the User Agent auth flow.
private const string AuthorizationEndpointUrl =
"https://login.salesforce.com/services/oauth2/authorize";
private const string ConsumerKey = "YOURCONSUMERKEY";
private const string CallbackUrl = "sfdc://success";
async private void Page_Loaded(object sender, RoutedEventArgs e)
{
var startUrl = Common.FormatAuthUrl(AuthorizationEndpointUrl, ResponseTypes.Token, ConsumerKey,
WebUtility.UrlEncode(CallbackUrl), DisplayTypes.Popup);
var startUri = new Uri(startUrl);
@wadewegner
wadewegner / JekyllLinterUpdate.sh
Created February 3, 2014 18:21
I needed a way to refresh the Facebook meta data for all my Jekyll blog posts. This solution provided the easiest (and fastest) solution.
---
layout: nil
---
#!/bin/bash
{% for post in site.posts %}$(/usr/bin/open -a "/Applications/Google Chrome.app" 'https://developers.facebook.com/tools/debug/og/object?q=http://www.wadewegner.com{{ post.url }}')
{% endfor %}
@wadewegner
wadewegner / CallTokenRefreshAsync.cs
Created February 5, 2014 16:49
Code used by the Salesforce Toolkits for .NET to perform a token refresh
var auth = new AuthenticationClient();
await auth.TokenRefreshAsync(ConsumerKey, _token.RefreshToken);
@wadewegner
wadewegner / TestRefreshToken.cs
Created February 5, 2014 20:12
A simple demonstration of retry logic to simulate handling an invalid token and using the refresh token
_token.AccessToken = "GARBAGE"; // simulates the same behavior as expiration
var refreshToken = false;
do
{
if (refreshToken)
{
var auth = new AuthenticationClient();
await auth.TokenRefreshAsync(ConsumerKey, _token.RefreshToken);
private async void btnExpireToken_Click(object sender, RoutedEventArgs e)
{
_token.AccessToken = "GARBAGE";
var response = await RetryMethod<dynamic>(GetAccounts, 3, 0, RefreshToken);
}
private async Task RefreshToken()
{
var auth = new AuthenticationClient();
@wadewegner
wadewegner / amqp.py
Last active January 17, 2022 09:25
Code used to turn the IoT Thermal Printer into a lunch menu & text message receiver
import pika, os, urlparse, sys
from Adafruit_Thermal import *
printer = Adafruit_Thermal("/dev/ttyAMA0", 19200, timeout=5)
url_str = os.environ.get('CLOUDAMQP_URL','amqp://YOUR_CLOUDAMQP_URL')
url = urlparse.urlparse(url_str)
params = pika.ConnectionParameters(host=url.hostname, virtual_host=url.path[1:],
credentials=pika.PlainCredentials(url.username, url.password))
@wadewegner
wadewegner / Login.cs
Created February 20, 2014 01:34
Async login against either the Partner or Enterprise SOAP API
static async Task<T> Login<T>(string userName, string password, string orgId)
{
string url;
string soap;
string wsdlType;
if (typeof(T) == typeof(Enterprise.LoginResult))
{
url = "https://login.salesforce.com/services/Soap/c/29.0/" + orgId;
soap = string.Format(@"<s:Envelope xmlns:s=""http://schemas.xmlsoap.org/soap/envelope/""><s:Body xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance"" xmlns:xsd=""http://www.w3.org/2001/XMLSchema""><login xmlns=""urn:enterprise.soap.sforce.com""><username>{0}</username><password>{1}</password></login></s:Body></s:Envelope>", userName, password);
@wadewegner
wadewegner / CreateCustomField.xml
Created February 21, 2014 17:58
Examples of HTTP requests and responses for Salesforce SOAP and Metadata API calls.
POST https://na15.salesforce.com/services/Soap/m/29.0/00Di0000000icUB HTTP/1.1
SOAPAction: create
Content-Type: text/xml; charset=utf-8
Host: na15.salesforce.com
Content-Length: 894
Expect: 100-continue
<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:apex="http://soap.sforce.com/2006/08/apex" xmlns:cmd="http://soap.sforce.com/2006/04/metadata" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Header>
@wadewegner
wadewegner / CreateCustom.cs
Last active March 19, 2021 04:18
.NET code used for interacting with the SOAP and Metadata APIs without using proxy classes generated by WSDLs
private static async Task<string> Create(string query, string sessionId, string metadataServerUrl)
{
var wsdlNamespace = "http://soap.sforce.com/2006/04/metadata";
var header = "";
var action = "create";
var soap = string.Format(
@"<soapenv:Envelope xmlns:xsd=""http://www.w3.org/2001/XMLSchema""
xmlns:xsi=""http://www.w3.org/2001/XMLSchema-instance""
xmlns:soapenv=""http://schemas.xmlsoap.org/soap/envelope/""