Class: DesignHuddle::Font
- Inherits:
-
Object
- Object
- DesignHuddle::Font
- Defined in:
- lib/design_huddle/font.rb
Instance Attribute Summary collapse
-
#font_faces ⇒ Object
Returns the value of attribute font_faces.
-
#font_family_id ⇒ Object
Returns the value of attribute font_family_id.
-
#font_family_name ⇒ Object
Returns the value of attribute font_family_name.
-
#font_type ⇒ Object
Returns the value of attribute font_type.
Class Method Summary collapse
-
.assign_font(font_family_name:, regular: nil, bold: nil, italic: nil, boldItalic: nil) ⇒ Object
def self.create(file_path:, file_name: nil) todo: make this work for each font variation upload_url Fony.upload_font(file_path: file_path, file_name: file_name) end.
- .get_font_upload_url(file_name) ⇒ Object
- .list ⇒ Object
- .upload_font(file_path:, file_name: nil) ⇒ Object
Instance Method Summary collapse
- #fetch ⇒ Object
-
#initialize(font_family) ⇒ Font
constructor
A new instance of Font.
Constructor Details
#initialize(font_family) ⇒ Font
Returns a new instance of Font.
5 6 7 8 9 10 11 |
# File 'lib/design_huddle/font.rb', line 5 def initialize(font_family) @font_family_id = font_family["font_family_id"] @font_family_name = font_family["font_family_name"] @font_faces = font_family["font_faces"] @font_type = font_family["font_type"] self end |
Instance Attribute Details
#font_faces ⇒ Object
Returns the value of attribute font_faces.
3 4 5 |
# File 'lib/design_huddle/font.rb', line 3 def font_faces @font_faces end |
#font_family_id ⇒ Object
Returns the value of attribute font_family_id.
3 4 5 |
# File 'lib/design_huddle/font.rb', line 3 def font_family_id @font_family_id end |
#font_family_name ⇒ Object
Returns the value of attribute font_family_name.
3 4 5 |
# File 'lib/design_huddle/font.rb', line 3 def font_family_name @font_family_name end |
#font_type ⇒ Object
Returns the value of attribute font_type.
3 4 5 |
# File 'lib/design_huddle/font.rb', line 3 def font_type @font_type end |
Class Method Details
.assign_font(font_family_name:, regular: nil, bold: nil, italic: nil, boldItalic: nil) ⇒ Object
def self.create(file_path:, file_name: nil)
todo: make this work for each font variation
upload_url Fony.upload_font(file_path: file_path, file_name: file_name)
end
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/design_huddle/font.rb', line 28 def self.assign_font(font_family_name:, regular: nil, bold: nil, italic: nil, boldItalic: nil) DesignHuddle.client.call( method: :post, path: "/partners/api/fonts", payload: { font_type: "partner", font_family_name: font_family_name, font_faces: { Regular: regular, Bold: bold, Italic: italic, BoldItalic: boldItalic } }.to_json, headers: { 'Content-Type': "application/json" } ) end |
.get_font_upload_url(file_name) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/design_huddle/font.rb', line 48 def self.get_font_upload_url(file_name) DesignHuddle.client.call( method: :get, path: "/partners/api/font/upload/url", headers: { params: { file_name: file_name } } ) end |
.list ⇒ Object
17 18 19 20 21 |
# File 'lib/design_huddle/font.rb', line 17 def self.list DesignHuddle.client.call(path: "/partners/api/fonts")["data"]["items"].map do |font_family| Font.new(font_family) end end |
.upload_font(file_path:, file_name: nil) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/design_huddle/font.rb', line 60 def self.upload_font(file_path:, file_name: nil) file = file_path.split("/").last name, extension = file.split(".") name = file_name if file_name if (name.length + extension.length + 1) > 30 # +1 for the `.` shortened_name = name[0..29 - extension.length - 1] warn("Font name #{name}.#{extension} is too long. It will be truncated to 30 characters. (#{shortened_name}.#{extension})") name = shortened_name end name = name + "." + extension upload_url = Font.get_font_upload_url(name)["data"]["upload_url"] puts DesignHuddle.client.call( method: :put, url: upload_url, payload: File.read(file_path), headers: { 'Content-Type': "font/#{extension}" } ) upload_url end |
Instance Method Details
#fetch ⇒ Object
13 14 15 |
# File 'lib/design_huddle/font.rb', line 13 def fetch DesignHuddle.client.call(path: "/partners/api/fonts/#{@font_family_id}") end |