Class: BrandLogo::Strategies::DuckduckgoStrategy

Inherits:
BaseStrategy
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/brand_logo/strategies/duckduckgo_strategy.rb

Overview

Fetches brand logos from DuckDuckGo’s public icon service. Used as a last-resort fallback when scraping finds nothing.

Constant Summary collapse

DUCKDUCKGO_URL =
T.let('https://icons.duckduckgo.com/ip3/%s.ico', String)

Constants inherited from BaseStrategy

BaseStrategy::UNKNOWN_DIMENSION_SCORE

Instance Method Summary collapse

Methods inherited from BaseStrategy

#fetch

Constructor Details

#initialize(config:, http_client:, image_analyzer:) ⇒ DuckduckgoStrategy

Returns a new instance of DuckduckgoStrategy.



22
23
24
25
26
# File 'lib/brand_logo/strategies/duckduckgo_strategy.rb', line 22

def initialize(config:, http_client:, image_analyzer:)
  super(config: config)
  @http_client    = T.let(http_client, HttpClient)
  @image_analyzer = T.let(image_analyzer, ImageAnalyzer)
end

Instance Method Details

#fetch_all(domain) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/brand_logo/strategies/duckduckgo_strategy.rb', line 29

def fetch_all(domain)
  url = format(DUCKDUCKGO_URL, domain)
  return [] unless @http_client.head_success?(url)

  icon = Icon.new(
    url: url,
    dimensions: @image_analyzer.dimensions(url),
    format: 'ico'
  )
  [icon]
rescue StandardError => e
  BrandLogo::Logging.logger.error("DuckduckgoStrategy error for #{domain}: #{e.message}")
  []
end