Skip to content

Instantly share code, notes, and snippets.

@cedricpinson
Created July 13, 2012 11:01
Show Gist options
  • Save cedricpinson/3104276 to your computer and use it in GitHub Desktop.
Save cedricpinson/3104276 to your computer and use it in GitHub Desktop.
sketchfab api
#!/usr/bin/ruby
# -*- coding: utf-8 -*-
require "uri"
require "net/https"
require "base64"
require 'rubygems'
require "json"
screenshot="../data/thumbnail.png"
filename="../data/model.dae"
description="Test of the api with a simple model"
token_api="FF00FF"
title="Uber Glasses"
tags="test collada glasses"
url="https://api.sketchfab.com/model"
model_contents = Base64.encode64(File.read(filename))
model_thumbnail = Base64.encode64(File.read(screenshot))
data = {
'title'=> title,
'description'=> description,
'contents'=> model_contents,
'filename'=> filename,
'tags'=> tags,
'thumbnail'=> model_thumbnail,
'token'=> token_api
}
uri = URI.parse(url)
p uri
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
request = Net::HTTP::Post.new(uri.request_uri, initheader = {'Content-Type' =>'application/json'})
request.body = data.to_json
#data.to_json
response = http.request(request)
p response.body
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment