class Kittastrophe::Client

Public Class Methods

new() click to toggle source
# File lib/kittastrophe/client.rb, line 10
def initialize()
  @api_key = read_api_key
end

Public Instance Methods

configure() click to toggle source
# File lib/kittastrophe/client.rb, line 59
def configure
  api_key = prompt "Please enter your TypeKit API key: "

  open(@@KEY_PATH, 'w') do |f|
    f.puts "#{api_key}".strip
    f.close
  end
end
key_path() click to toggle source
# File lib/kittastrophe/client.rb, line 15
def key_path
  @@KEY_PATH
end
list() click to toggle source
# File lib/kittastrophe/client.rb, line 25
def list
  http = Curl.get("https://typekit.com/api/v1/json/kits") do |http|
    http.headers['X-Typekit-Token'] = @api_key
  end

  body = JSON.parse(http.body_str)

  if http.response_code != 200
    process_error(body)
  else
    body
  end
end
process_error(body) click to toggle source
# File lib/kittastrophe/client.rb, line 54
def process_error(body)
  body["errors"]
end
prompt(*args) click to toggle source
# File lib/kittastrophe/client.rb, line 69
def prompt(*args)
    print(*args)
    gets
end
read_api_key() click to toggle source
# File lib/kittastrophe/client.rb, line 75
def read_api_key
  if File.exists?(@@KEY_PATH)
    file = File.open(@@KEY_PATH, "rb")
    contents = file.read
    file.close
    key = contents.strip
  end

  ENV['TYPEKIT_API_KEY'] || key
end
show(id) click to toggle source
# File lib/kittastrophe/client.rb, line 39
def show(id)
  http = Curl.get("https://typekit.com/api/v1/json/kits/#{id}") do |http|
    http.headers['X-Typekit-Token'] = @api_key
  end

  body = JSON.parse(http.body_str)

  if http.response_code != 200
    process_error(body)
  else
    body
  end
end
zoidberg() click to toggle source
# File lib/kittastrophe/client.rb, line 20
def zoidberg
  "Hooray, I'm useful!"
end