Class: Awesomekit::Client

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/awesomekit/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_token) ⇒ Client

Returns a new instance of Client.



9
10
11
# File 'lib/awesomekit/client.rb', line 9

def initialize(api_token)
  self.class.headers('X-Typekit-Token' => api_token)
end

Instance Method Details

#get_kit(kit_id, published = false) ⇒ Object

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



32
33
34
35
36
37
38
39
40
41
42
# 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_kitsObject

PUBLIC: Returns a list of kits owned by the authenticating user Endpoint reference: typekit.com/docs/api/v1/:format/kits



15
16
17
18
19
20
21
22
23
24
25
# 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