Class: Fontist::Import::Google::Api

Inherits:
Object
  • Object
show all
Defined in:
lib/fontist/import/google/api.rb

Overview

Facade for accessing the unified Google Fonts database

This class provides a clean interface for accessing Google Fonts data by integrating data from three API endpoints (TTF, VF, WOFF2) into a unified database.

Examples:

Basic usage

fonts = Api.items
roboto = Api.font_by_name("Roboto")

Filtering

sans_serif = Api.by_category("sans-serif")
variable = Api.variable_fonts_only

Raw endpoint access

ttf_data = Api.ttf_data
vf_data = Api.vf_data

Class Method Summary collapse

Class Method Details

.by_category(category) ⇒ Array<Models::FontFamily>

Filter fonts by category

Parameters:

  • category (String)

    the category (e.g., “sans-serif”)

Returns:



65
66
67
# File 'lib/fontist/import/google/api.rb', line 65

def by_category(category)
  database.by_category(category)
end

.clear_cachevoid

This method returns an undefined value.

Clear all caches (clients + database)



114
115
116
117
118
119
# File 'lib/fontist/import/google/api.rb', line 114

def clear_cache
  ttf_client.clear_cache
  vf_client.clear_cache
  woff2_client.clear_cache
  @database = nil
end

.databaseFontDatabase

Get unified font database instance

Returns:



35
36
37
# File 'lib/fontist/import/google/api.rb', line 35

def database
  @database ||= build_database
end

.font_by_name(name) ⇒ Models::FontFamily?

Find a specific font family by name

Parameters:

  • name (String)

    the font family name

Returns:



57
58
59
# File 'lib/fontist/import/google/api.rb', line 57

def font_by_name(name)
  database.font_by_name(name)
end

.font_familiesArray<Models::FontFamily>

Alias for items

Returns:



49
50
51
# File 'lib/fontist/import/google/api.rb', line 49

def font_families
  items
end

.fonts_countHash

Get count of fonts by type

Returns:

  • (Hash)

    hash with counts of total, variable, and static



86
87
88
# File 'lib/fontist/import/google/api.rb', line 86

def fonts_count
  database.fonts_count
end

.itemsArray<Models::FontFamily>

Get all font families (main entry point)

Returns:



42
43
44
# File 'lib/fontist/import/google/api.rb', line 42

def items
  database.all_fonts
end

.static_fonts_onlyArray<Models::FontFamily>

Get only static fonts (fonts without axes)

Returns:



79
80
81
# File 'lib/fontist/import/google/api.rb', line 79

def static_fonts_only
  database.static_fonts_only
end

.ttf_dataArray<Models::FontFamily>

Get raw TTF endpoint data (for debugging)

Returns:



93
94
95
# File 'lib/fontist/import/google/api.rb', line 93

def ttf_data
  ttf_client.fetch
end

.variable_fonts_onlyArray<Models::FontFamily>

Get only variable fonts (fonts with axes)

Returns:



72
73
74
# File 'lib/fontist/import/google/api.rb', line 72

def variable_fonts_only
  database.variable_fonts_only
end

.vf_dataArray<Models::FontFamily>

Get raw VF endpoint data (for debugging)

Returns:



100
101
102
# File 'lib/fontist/import/google/api.rb', line 100

def vf_data
  vf_client.fetch
end

.woff2_dataArray<Models::FontFamily>

Get raw WOFF2 endpoint data (for debugging)

Returns:



107
108
109
# File 'lib/fontist/import/google/api.rb', line 107

def woff2_data
  woff2_client.fetch
end