Class: Typekit::Kit
- Inherits:
-
Object
- Object
- Typekit::Kit
- Includes:
- MassAssignment
- Defined in:
- lib/typekit/kit.rb
Overview
Get information for a specific family in the kit (/kits/:kit/families/:family)
Constant Summary collapse
- @@defaults =
TODO:
Allow users to change defaults easily
{ :badge => false, :segmented_css_names => false }
Instance Attribute Summary collapse
-
#badge ⇒ Object
Detailed information about a kit.
-
#domains ⇒ Object
Detailed information about a kit.
-
#families ⇒ Object
Detailed information about a kit.
-
#id ⇒ Object
readonly
Typekit-defined kit id.
-
#name ⇒ Object
Detailed information about a kit.
-
#segmented_css_names ⇒ Object
Detailed information about a kit.
Class Method Summary collapse
-
.all ⇒ Object
Get a list of all of the kits available for this Typekit account.
-
.create(params) ⇒ Typekit::Kit
Create a new kit.
-
.find(id) ⇒ Object
Find a kit by id (not by name).
Instance Method Summary collapse
-
#add_family(id, params = {}) ⇒ Boolean
Add a family to this kit (does not publish changes).
-
#delete ⇒ Object
(also: #destroy)
Delete this kit from Typekit.
-
#delete_family(id) ⇒ Boolean
(also: #remove_family)
Delete a family from this kit (does not publish changes).
-
#fetch(attribute = nil) ⇒ Object
(also: #reload)
Get detailed information about this kit from Typekit.
-
#publish ⇒ Time
Typekit maintains the changes you have made to a Kit in a “working” state until you specify that it is ready to be published.
-
#save(publish_after_save = true) ⇒ Boolean
Save kit attributes like name and domains.
-
#update_family(id) {|family| ... } ⇒ Boolean
Update a family on this kit (does not publish changes).
Methods included from MassAssignment
Instance Attribute Details
#badge ⇒ Object
Detailed information about a kit. Lazy loaded when accessed unless the data already exists.
9 10 11 |
# File 'lib/typekit/kit.rb', line 9 def badge @badge end |
#domains ⇒ Object
Detailed information about a kit. Lazy loaded when accessed unless the data already exists.
9 10 11 |
# File 'lib/typekit/kit.rb', line 9 def domains @domains end |
#families ⇒ Object
Detailed information about a kit. Lazy loaded when accessed unless the data already exists.
9 10 11 |
# File 'lib/typekit/kit.rb', line 9 def families @families end |
#id ⇒ Object
Typekit-defined kit id
12 13 14 |
# File 'lib/typekit/kit.rb', line 12 def id @id end |
#name ⇒ Object
Detailed information about a kit. Lazy loaded when accessed unless the data already exists.
9 10 11 |
# File 'lib/typekit/kit.rb', line 9 def name @name end |
#segmented_css_names ⇒ Object
Detailed information about a kit. Lazy loaded when accessed unless the data already exists.
9 10 11 |
# File 'lib/typekit/kit.rb', line 9 def segmented_css_names @segmented_css_names end |
Class Method Details
.all ⇒ Object
Support pagination
Get a list of all of the kits available for this Typekit account
32 33 34 35 36 |
# File 'lib/typekit/kit.rb', line 32 def all Client.get('/kits').inject([]) do |kits, attributes| kits << Kit.new(attributes) end end |
.create(params) ⇒ Typekit::Kit
Create a new kit
45 46 47 48 49 |
# File 'lib/typekit/kit.rb', line 45 def create(params) params = @@defaults.merge(params) response = Client.post("/kits", :query => params) Kit.new(response) end |
Instance Method Details
#add_family(id, params = {}) ⇒ Boolean
Add a family to this kit (does not publish changes)
113 114 115 116 |
# File 'lib/typekit/kit.rb', line 113 def add_family(id, params = {}) params = { :variations => [], :subset => 'default' }.merge(params) !!Client.post("/kits/#{@id}/families/#{id}", :query => params) end |
#delete ⇒ Object Also known as: destroy
Delete this kit from Typekit
102 103 104 |
# File 'lib/typekit/kit.rb', line 102 def delete Client.delete("/kits/#{@id}") end |
#delete_family(id) ⇒ Boolean Also known as: remove_family
Delete a family from this kit (does not publish changes)
139 140 141 |
# File 'lib/typekit/kit.rb', line 139 def delete_family(id) !!Client.delete("/kits/#{@id}/families/#{id}") end |
#fetch(attribute = nil) ⇒ Object Also known as: reload
This is called lazily when you access any non-loaded attribute and doesn’t need to be called manually unless you want to reload the data. This means we can return an array of Kit objects for all without making N+1 requests to the API.
Get detailed information about this kit from Typekit
71 72 73 74 |
# File 'lib/typekit/kit.rb', line 71 def fetch(attribute = nil) mass_assign Client.get("/kits/#{@id}") attribute ? instance_variable_get("@#{attribute}") : self end |
#publish ⇒ Time
Typekit maintains the changes you have made to a Kit in a “working” state until you specify that it is ready to be published. After the state has been changed to “published” your kit will be queued to be pushed out to their CDN and served to new requests. This can take up to 5 minutes when they are under heavy load.
97 98 99 |
# File 'lib/typekit/kit.rb', line 97 def publish Client.post("/kits/#{@id}/publish") end |
#save(publish_after_save = true) ⇒ Boolean
Save kit attributes like name and domains. This does not alter the families added to the kit.
81 82 83 84 85 86 87 88 89 |
# File 'lib/typekit/kit.rb', line 81 def save(publish_after_save = true) attributes = [:name, :badge, :domains].inject({}) { |attributes, x| attributes[x] = instance_variable_get("@#{x}"); attributes } result = mass_assign Client.post("/kits/#{@id}", :query => attributes) published = publish if publish_after_save # For the parenthesized statement, true && true or false && false are acceptable. # but xor does the exact opposite, so we negate it. result && !(publish_after_save ^ published) end |
#update_family(id) {|family| ... } ⇒ Boolean
Update a family on this kit (does not publish changes)
128 129 130 131 132 133 134 |
# File 'lib/typekit/kit.rb', line 128 def update_family(id) raise 'Block required' unless block_given? family = Client.get("/kits/#{@id}/families/#{id}") yield family family.keep_if { |k,v| %w{variations subset}.include? k } !!Client.post("/kits/#{@id}/families/#{id}", :query => family) end |