Skip to content

Instantly share code, notes, and snippets.

View cburnette's full-sized avatar

Chad Burnette cburnette

View GitHub Profile
@cburnette
cburnette / Read event stream in Ruby
Last active August 29, 2015 14:01
Read event stream in Ruby
require 'ruby-box'
require 'lru_redux'
BOX_CLIENT_ID = 'YOUR_CLIENT_ID'
BOX_CLIENT_SECRET = 'YOUR_CLIENT_SECRET'
BOX_DEV_TOKEN = 'YOUR_DEV_TOKEN'
def box_client
box_session = RubyBox::Session.new({
@cburnette
cburnette / Call the Box API without using the Box .NET SDK (i.e. you only have VS 2010)
Last active August 29, 2015 14:10
Call the Box API without using the Box .NET SDK (i.e. you only have VS 2010)
using Newtonsoft.Json.Linq;
using RestSharp;
using System;
using System.Collections.Generic;
using System.Dynamic;
using System.Linq;
using System.Text;
//install NuGet package 'RestSharp'
//install NuGet package Json.NET'
@cburnette
cburnette / Iterate Box folders in Ruby
Last active April 27, 2016 08:18
This code snippet will connect to a Box account and loop through all the folders recursively, printing out all the filenames, while highlighting in red files that have a modified_at date older than the specified threshold. In other words, it highlights files that haven't been changed in a while.
require 'ruby-box' #gem install ruby-box
require 'term/ansicolor' #gem install term-ansicolor
include Term::ANSIColor
MODIFIED_AT_CUTOFF = Time.new(2013,7,1)
session = RubyBox::Session.new({
client_id: "YOUR_CLIENT_ID",
client_secret: "YOUR_CLIENT_SECRET",
POST https://upload.box.com/api/2.0/files/content HTTP/1.1
Host: upload.box.com
Connection: keep-alive
Content-Length: 2368
Pragma: no-cache
Cache-Control: no-cache
Accept: */*
Origin: http://localhost:1655
Authorization: Bearer H9Wv8Ttyzwdn6ovziM8fGOBtrkmnbCFC
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36
public static async Task PrepareBoxAppUser(ClaimsIdentity externalIdentity)
{
var auth0UserId = externalIdentity.Claims.FirstOrDefault(c => c.Type == "user_id").Value;
var boxId = GetBoxIdFromAuth0(auth0UserId);
if (boxId == null)
{
//create a new app user in Box
<add key="boxClientId" value="59oj4w7tft85e3t43v1dk4fbqub2e7bo" />
<add key="boxClientSecret" value="MdSMRvyNNBkTAYZmFTgPXJuVfxf2af5s" />
<add key="boxEnterpriseId" value="653871" />
<add key="boxPrivateKeyPassword" value="BoxTraining1234" />
<add key="boxPublicKeyId" value="eq2emlah" />
using Box.V2;
using Box.V2.Auth;
using Box.V2.Config;
using Box.V2.JWTAuth;
using Box.V2.Models;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.IO;
using System.Linq;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
namespace BasicMvcSample.Helpers
{
public static class CacheHelper
{
// The Box Auth Header. Add your access token.
var headers = { Authorization: 'Bearer @ViewBag.AccessToken'};
var uploadUrl = 'https://upload.box.com/api/2.0/files/content';
var files = fileSelect.files;
var formData = new FormData();
formData.append('files', files[0], files[0].name);
// Add the destination folder for the upload to the form
public async Task<FileStreamResult> Thumbnail(string id)
{
var thumbBytes = await BoxHelper.UserClient().FilesManager.GetThumbnailAsync(id, minHeight: 256, minWidth: 256, maxHeight: 256, maxWidth: 256);
return new FileStreamResult(thumbBytes, "image/png");
}