Class: LogoDev::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/logo_dev/client.rb

Constant Summary collapse

API_BASE =
"https://api.logo.dev"
IMG_BASE =
"https://img.logo.dev"

Instance Method Summary collapse

Constructor Details

#initialize(secret_key: nil, publishable_key: nil) ⇒ Client

Returns a new instance of Client.



12
13
14
15
# File 'lib/logo_dev/client.rb', line 12

def initialize(secret_key: nil, publishable_key: nil)
  @secret_key = secret_key
  @publishable_key = publishable_key
end

Instance Method Details

#brand(domain) ⇒ Object

Brand API Retrieves a full brand profile for a given domain.

Parameters:

  • domain (String)


48
49
50
# File 'lib/logo_dev/client.rb', line 48

def brand(domain)
  get("/brand/#{domain}")
end

#describe(domain) ⇒ Object

Describe API Enriches a domain into structured company data.

Parameters:

  • domain (String)


41
42
43
# File 'lib/logo_dev/client.rb', line 41

def describe(domain)
  get("/describe/#{domain}")
end

#logo_url(identifier, **options) ⇒ Object

Logo API Generates a URL for a logo image.

Parameters:

  • identifier (String)

    domain, ticker, ISIN, or crypto symbol

  • options (Hash)

    size, format, etc.



21
22
23
24
25
26
27
28
29
# File 'lib/logo_dev/client.rb', line 21

def logo_url(identifier, **options)
  token = options.delete(:token) || @publishable_key
  
  params = options.dup
  params[:token] = token if token

  query = URI.encode_www_form(params)
  "#{IMG_BASE}/#{identifier}#{query.empty? ? "" : "?#{query}"}"
end

#search(query) ⇒ Object

Search API Resolves a human-typed company name to its canonical domain.

Parameters:

  • query (String)

    company name



34
35
36
# File 'lib/logo_dev/client.rb', line 34

def search(query)
  get("/search", q: query)
end

#transaction(transaction, country_code: nil) ⇒ Object

Transaction API Identifies and cleans raw card-transaction descriptors.

Parameters:

  • transaction (String)

    raw transaction string

  • country_code (String) (defaults to: nil)

    optional ISO 3166-1 alpha-2 code



56
57
58
59
60
# File 'lib/logo_dev/client.rb', line 56

def transaction(transaction, country_code: nil)
  body = { transaction: transaction }
  body[:country_code] = country_code if country_code
  post("/transaction", body)
end