Class: PartyProfileImageLookupService

Inherits:
Object
  • Object
show all
Defined in:
app/services/party_profile_image_lookup_service.rb

Overview

Service to lookup and attach profile images for Customers and Contacts.

For Customers (companies):
Uses Logo.dev API to fetch company logos based on domain

For Contacts (people):

  1. Tries Gravatar based on email
  2. Falls back to parent customer's company logo

Requires a Logo.dev API key stored in Rails credentials:
logo_dev:
publishable_key: pk_xxx...

Examples:

Basic usage

PartyProfileImageLookupService.new(customer).call

Force refresh

PartyProfileImageLookupService.new(customer, force: true).call

Constant Summary collapse

LOGO_DEV_URL =
'https://img.logo.dev'
GRAVATAR_URL =
'https://www.gravatar.com/avatar'
HTTP_TIMEOUT =

seconds

5

Instance Method Summary collapse

Constructor Details

#initialize(party, force: false, logger: nil) ⇒ PartyProfileImageLookupService

Returns a new instance of PartyProfileImageLookupService.

Parameters:

  • party (Customer, Contact)

    The party to lookup an image for

  • force (Boolean) (defaults to: false)

    Force refresh even if image already exists

  • logger (Logger) (defaults to: nil)

    Optional logger for debugging



30
31
32
33
34
# File 'app/services/party_profile_image_lookup_service.rb', line 30

def initialize(party, force: false, logger: nil)
  @party = party
  @force = force
  @logger = logger || Rails.logger
end

Instance Method Details

#callImage?

Perform the lookup and attach image if found

Returns:

  • (Image, nil)

    The attached image or nil if not found



38
39
40
41
42
43
44
45
46
# File 'app/services/party_profile_image_lookup_service.rb', line 38

def call
  return nil unless should_lookup?

  if party.is_a?(Contact)
    lookup_contact_image
  else
    
  end
end