class Awesomekit::Client
Public Class Methods
new(api_token)
click to toggle source
# File lib/awesomekit/client.rb, line 9 def initialize(api_token) self.class.headers('X-Typekit-Token' => api_token) end
Public Instance Methods
get_kit(kit_id, published=false)
click to toggle source
PUBLIC: Returns information about a kit found by kit_id Endpoint reference: typekit.com/docs/api/v1/:format/kits/:kit
published=false returns the default, current draft version of the kit published=true returns the current published version of a kit
# File lib/awesomekit/client.rb, line 32 def get_kit(kit_id, published=false) if published response = self.class.get("/kits/#{kit_id}/published") else response = self.class.get("/kits/#{kit_id}") end return if process_errors(response) response['kit'] end
get_kits()
click to toggle source
PUBLIC: Returns a list of kits owned by the authenticating user Endpoint reference: typekit.com/docs/api/v1/:format/kits
# File lib/awesomekit/client.rb, line 15 def get_kits response = self.class.get("/kits") return if process_errors(response) # If no kits are found, an empty array is returned (not a Not Found error) kits = response['kits'] return not_found if kits.nil? || kits.empty? kits end
Private Instance Methods
not_found()
click to toggle source
# File lib/awesomekit/client.rb, line 65 def not_found puts('No kits found') end
process_errors(response)
click to toggle source
PRIVATE: Display any error messages returned by Typekit.
Automatically removes an invalid api_token if error is a 401 not authorized, so the user will be prompted to enter a new token on their next request.
# File lib/awesomekit/client.rb, line 50 def process_errors(response) if response['errors'] errors = 'The server responded with the following error(s): ' errors << response['errors'].join(',') if errors.include?('Not authorized') Awesomekit::Authenticator.clear_api_token end puts(errors) return true end end