Skip to content

Instantly share code, notes, and snippets.

@rcarver
Created August 5, 2010 18:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rcarver/510163 to your computer and use it in GitHub Desktop.
Save rcarver/510163 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
# A very simple script to republish all of your kits at Typekit. Just pass your
# api token as the first argument to this script.
#
# Sign up for Typekit http://typekit.com/
# Get an api token at https://typekit.com/account/tokens
require 'net/http'
require 'net/https'
require 'yaml'
api_token = ARGV.shift or abort "Usage: #{$0} api_token"
typekit_endpoint = "https://typekit.com/api/v1"
class TypekitApi
def initialize(token, endpoint)
@token = token
@endpoint = endpoint
end
def get(url)
request(:get, url)
end
def post(url)
request(:post, url, {})
end
protected
def request(method, path, data=nil)
url = URI.parse("#{@endpoint}/yaml#{path}?token=#{@token}")
parsed_url = url.path+"?"+url.query
req = case method
when :get: Net::HTTP::Get.new(parsed_url)
when :post: Net::HTTP::Post.new(parsed_url)
end
req.set_form_data(data) if data
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_PEER
res = http.start { |http| http.request(req) }
case res
when Net::HTTPSuccess
return YAML.load(res.body)
else
abort res.body
end
end
end
api = TypekitApi.new(api_token, typekit_endpoint)
api.get("/kits")["kits"].each { |kit|
kit_id = kit["id"]
kit_name = api.get("/kits/#{kit_id}")["kit"]["name"]
puts "Publising #{kit_name} (#{kit_id})"
api.post("/kits/#{kit_id}/publish")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment