logo_dev 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.md +137 -0
- data/lib/logo_dev/client.rb +114 -0
- data/lib/logo_dev/error.rb +15 -0
- data/lib/logo_dev/version.rb +5 -0
- data/lib/logo_dev.rb +35 -0
- data/logo_dev.gemspec +29 -0
- metadata +52 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 70d310347a2eaf2243832d898b27179440609f3ccf31dc97cbe13c0cffc1731f
|
|
4
|
+
data.tar.gz: 8386beddfc6de8ef1f133c3a0d3be9cfbfd66da6d58232c322ce93d055f1e6d7
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 523644141a060c960e2caf890da5064fd6a01538a806955fbcf2bf0ae4e6bb0d9b20adfee6b69cd45859d4677896c6e7ec298dbfb90a960c2614f8a4169f3a61
|
|
7
|
+
data.tar.gz: 725bc53ef7c3171880b2664d85dae5d4fcb5ddc85748ecd20aec39748b726a6a12fcbad03435adf05b873f7705dc98f01a2e320a0a98e33343e70494d96f1ef5
|
data/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 swlkr
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# LogoDev
|
|
2
|
+
|
|
3
|
+
A lightweight, zero-dependency Ruby client for [Logo.dev](https://www.logo.dev).
|
|
4
|
+
|
|
5
|
+
## Features
|
|
6
|
+
|
|
7
|
+
- **Zero Dependencies**: Uses only Ruby standard library (`net/http`, `json`).
|
|
8
|
+
- **Complete Coverage**: Supports Logo, Brand, Search, Transactions, and Describe APIs.
|
|
9
|
+
- **Easy to Use**: Clean and intuitive API.
|
|
10
|
+
- **Secure**: Handles authentication via secret and publishable keys.
|
|
11
|
+
|
|
12
|
+
## Installation
|
|
13
|
+
|
|
14
|
+
Add this line to your application's Gemfile:
|
|
15
|
+
|
|
16
|
+
```ruby
|
|
17
|
+
gem 'logo_dev'
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
And then execute:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
bundle install
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Or install it yourself as:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
gem install logo_dev
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Usage
|
|
33
|
+
|
|
34
|
+
### Configuration
|
|
35
|
+
|
|
36
|
+
You can configure the client globally (e.g., in a Rails initializer):
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
require 'logo_dev'
|
|
40
|
+
|
|
41
|
+
LogoDev.configure do |config|
|
|
42
|
+
config.secret_key = ENV["LOGODEV_SECRET_KEY"]
|
|
43
|
+
config.publishable_key = ENV["LOGODEV_PUBLISHABLE_KEY"]
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Then you can initialize a client without arguments
|
|
47
|
+
client = LogoDev.new
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Alternatively, you can pass keys directly when initializing a client:
|
|
51
|
+
|
|
52
|
+
```ruby
|
|
53
|
+
client = LogoDev.new(
|
|
54
|
+
secret_key: 'sk_...', # Required for REST APIs
|
|
55
|
+
publishable_key: 'pk_...' # Optional, used for Logo URL generation
|
|
56
|
+
)
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
### Logo API
|
|
61
|
+
|
|
62
|
+
Generate a URL for a company logo. This doesn't make an API call; it simply constructs a signed URL.
|
|
63
|
+
|
|
64
|
+
```ruby
|
|
65
|
+
# By domain
|
|
66
|
+
client.logo_url('google.com')
|
|
67
|
+
# => "https://img.logo.dev/google.com?token=pk_..."
|
|
68
|
+
|
|
69
|
+
# With options
|
|
70
|
+
client.logo_url('stripe.com', size: 128, format: 'png')
|
|
71
|
+
# => "https://img.logo.dev/stripe.com?size=128&format=png&token=pk_..."
|
|
72
|
+
|
|
73
|
+
# By ticker, ISIN, or crypto symbol
|
|
74
|
+
client.logo_url('AAPL')
|
|
75
|
+
client.logo_url('US0378331005')
|
|
76
|
+
client.logo_url('BTC')
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
### Search API
|
|
80
|
+
|
|
81
|
+
Resolve a human-typed company name to its canonical domain.
|
|
82
|
+
|
|
83
|
+
```ruby
|
|
84
|
+
client.search('Apple')
|
|
85
|
+
# => [{"name"=>"Apple", "domain"=>"apple.com", ...}, ...]
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### Describe API
|
|
89
|
+
|
|
90
|
+
Enrich a domain into structured company data (name, description, brand colors, social profiles).
|
|
91
|
+
|
|
92
|
+
```ruby
|
|
93
|
+
client.describe('apple.com')
|
|
94
|
+
# => {"name"=>"Apple Inc.", "description"=>"...", "colors"=>[...], "social"=>[...]}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
### Brand API
|
|
98
|
+
|
|
99
|
+
Retrieve a full brand profile for a given domain, including banners and brandmarks.
|
|
100
|
+
|
|
101
|
+
```ruby
|
|
102
|
+
client.brand('airbnb.com')
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Transaction API
|
|
106
|
+
|
|
107
|
+
Normalize and clean raw card-transaction descriptors.
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
client.transaction('SQ *BLUE BOTTLE 1523 OAKLAND CA', country_code: 'US')
|
|
111
|
+
# => {"name"=>"Blue Bottle Coffee", "domain"=>"bluebottlecoffee.com", ...}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
## Error Handling
|
|
115
|
+
|
|
116
|
+
The gem defines the following error classes:
|
|
117
|
+
|
|
118
|
+
- `LogoDev::AuthenticationError`: Raised when the API key is missing or invalid.
|
|
119
|
+
- `LogoDev::ResponseError`: Raised when the API returns an error status code.
|
|
120
|
+
- `LogoDev::RequestError`: Raised when a network error occurs.
|
|
121
|
+
|
|
122
|
+
```ruby
|
|
123
|
+
begin
|
|
124
|
+
client.describe('invalid.com')
|
|
125
|
+
rescue LogoDev::ResponseError => e
|
|
126
|
+
puts "API Error: #{e.message}"
|
|
127
|
+
puts "Response Code: #{e.response.code}"
|
|
128
|
+
end
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
## Development
|
|
132
|
+
|
|
133
|
+
After checking out the repo, run `bundle install` to install dependencies. Then, run `rake test` to run the tests.
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "json"
|
|
5
|
+
require "uri"
|
|
6
|
+
|
|
7
|
+
module LogoDev
|
|
8
|
+
class Client
|
|
9
|
+
API_BASE = "https://api.logo.dev"
|
|
10
|
+
IMG_BASE = "https://img.logo.dev"
|
|
11
|
+
|
|
12
|
+
def initialize(secret_key: nil, publishable_key: nil)
|
|
13
|
+
@secret_key = secret_key
|
|
14
|
+
@publishable_key = publishable_key
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
# Logo API
|
|
18
|
+
# Generates a URL for a logo image.
|
|
19
|
+
# @param identifier [String] domain, ticker, ISIN, or crypto symbol
|
|
20
|
+
# @param options [Hash] size, format, etc.
|
|
21
|
+
def logo_url(identifier, **options)
|
|
22
|
+
token = options.delete(:token) || @publishable_key
|
|
23
|
+
|
|
24
|
+
params = options.dup
|
|
25
|
+
params[:token] = token if token
|
|
26
|
+
|
|
27
|
+
query = URI.encode_www_form(params)
|
|
28
|
+
"#{IMG_BASE}/#{identifier}#{query.empty? ? "" : "?#{query}"}"
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Search API
|
|
32
|
+
# Resolves a human-typed company name to its canonical domain.
|
|
33
|
+
# @param query [String] company name
|
|
34
|
+
def search(query)
|
|
35
|
+
get("/search", q: query)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Describe API
|
|
39
|
+
# Enriches a domain into structured company data.
|
|
40
|
+
# @param domain [String]
|
|
41
|
+
def describe(domain)
|
|
42
|
+
get("/describe/#{domain}")
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# Brand API
|
|
46
|
+
# Retrieves a full brand profile for a given domain.
|
|
47
|
+
# @param domain [String]
|
|
48
|
+
def brand(domain)
|
|
49
|
+
get("/brand/#{domain}")
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Transaction API
|
|
53
|
+
# Identifies and cleans raw card-transaction descriptors.
|
|
54
|
+
# @param transaction [String] raw transaction string
|
|
55
|
+
# @param country_code [String] optional ISO 3166-1 alpha-2 code
|
|
56
|
+
def transaction(transaction, country_code: nil)
|
|
57
|
+
body = { transaction: transaction }
|
|
58
|
+
body[:country_code] = country_code if country_code
|
|
59
|
+
post("/transaction", body)
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
private
|
|
63
|
+
|
|
64
|
+
def get(path, params = {})
|
|
65
|
+
uri = URI("#{API_BASE}#{path}")
|
|
66
|
+
uri.query = URI.encode_www_form(params) unless params.empty?
|
|
67
|
+
|
|
68
|
+
request = Net::HTTP::Get.new(uri)
|
|
69
|
+
perform_request(uri, request)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
def post(path, body = {})
|
|
73
|
+
uri = URI("#{API_BASE}#{path}")
|
|
74
|
+
|
|
75
|
+
request = Net::HTTP::Post.new(uri)
|
|
76
|
+
request["Content-Type"] = "application/json"
|
|
77
|
+
request.body = JSON.generate(body)
|
|
78
|
+
|
|
79
|
+
perform_request(uri, request)
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def perform_request(uri, request)
|
|
83
|
+
raise AuthenticationError, "Secret key is required for this API" unless @secret_key
|
|
84
|
+
|
|
85
|
+
request["Authorization"] = "Bearer #{@secret_key}"
|
|
86
|
+
request["Accept"] = "application/json"
|
|
87
|
+
|
|
88
|
+
response = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
|
|
89
|
+
http.request(request)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
handle_response(response)
|
|
93
|
+
rescue SocketError, Net::OpenTimeout => e
|
|
94
|
+
raise RequestError, "Failed to connect to Logo.dev: #{e.message}"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def handle_response(response)
|
|
98
|
+
case response.code.to_i
|
|
99
|
+
when 200..299
|
|
100
|
+
JSON.parse(response.body)
|
|
101
|
+
when 401
|
|
102
|
+
raise AuthenticationError, "Invalid secret key"
|
|
103
|
+
else
|
|
104
|
+
begin
|
|
105
|
+
error_data = JSON.parse(response.body)
|
|
106
|
+
message = error_data["error"] || error_data["message"] || response.message
|
|
107
|
+
rescue JSON::ParserError
|
|
108
|
+
message = response.message
|
|
109
|
+
end
|
|
110
|
+
raise ResponseError.new("Logo.dev API error: #{message}", response)
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
end
|
|
114
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module LogoDev
|
|
4
|
+
class Error < StandardError; end
|
|
5
|
+
class AuthenticationError < Error; end
|
|
6
|
+
class RequestError < Error; end
|
|
7
|
+
class ResponseError < Error
|
|
8
|
+
attr_reader :response
|
|
9
|
+
|
|
10
|
+
def initialize(message, response = nil)
|
|
11
|
+
super(message)
|
|
12
|
+
@response = response
|
|
13
|
+
end
|
|
14
|
+
end
|
|
15
|
+
end
|
data/lib/logo_dev.rb
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "logo_dev/version"
|
|
4
|
+
require_relative "logo_dev/error"
|
|
5
|
+
require_relative "logo_dev/client"
|
|
6
|
+
|
|
7
|
+
module LogoDev
|
|
8
|
+
class Configuration
|
|
9
|
+
attr_accessor :secret_key, :publishable_key
|
|
10
|
+
|
|
11
|
+
def initialize
|
|
12
|
+
@secret_key = ENV["LOGODEV_SECRET_KEY"]
|
|
13
|
+
@publishable_key = ENV["LOGODEV_PUBLISHABLE_KEY"]
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
class << self
|
|
18
|
+
attr_writer :configuration
|
|
19
|
+
|
|
20
|
+
def configuration
|
|
21
|
+
@configuration ||= Configuration.new
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def configure
|
|
25
|
+
yield(configuration)
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def new(secret_key: nil, publishable_key: nil)
|
|
29
|
+
secret_key ||= configuration.secret_key
|
|
30
|
+
publishable_key ||= configuration.publishable_key
|
|
31
|
+
Client.new(secret_key: secret_key, publishable_key: publishable_key)
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
data/logo_dev.gemspec
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
Gem::Specification.new do |spec|
|
|
4
|
+
spec.name = "logo_dev"
|
|
5
|
+
spec.version = "0.1.0"
|
|
6
|
+
spec.authors = ["swlkr"]
|
|
7
|
+
spec.email = ["me@swlkr.com"]
|
|
8
|
+
|
|
9
|
+
spec.summary = "A Ruby client for the Logo.dev API"
|
|
10
|
+
spec.description = "Wrap the Logo.dev API with zero dependencies. Support for Logo, Brand, Search, Transactions, and Describe APIs."
|
|
11
|
+
spec.homepage = "https://github.com/swlkr/logodev"
|
|
12
|
+
spec.license = "MIT"
|
|
13
|
+
spec.required_ruby_version = ">= 2.6.0"
|
|
14
|
+
|
|
15
|
+
spec.metadata["allowed_push_host"] = "https://rubygems.org"
|
|
16
|
+
|
|
17
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
|
18
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
|
19
|
+
spec.metadata["changelog_uri"] = "#{spec.homepage}/blob/main/CHANGELOG.md"
|
|
20
|
+
|
|
21
|
+
# Specify which files should be added to the gem when it is released.
|
|
22
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
|
23
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
|
24
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{\A(?:test|spec|features)/}) }
|
|
25
|
+
end
|
|
26
|
+
spec.bindir = "exe"
|
|
27
|
+
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
|
|
28
|
+
spec.require_paths = ["lib"]
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: logo_dev
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.0
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- swlkr
|
|
8
|
+
bindir: exe
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies: []
|
|
12
|
+
description: Wrap the Logo.dev API with zero dependencies. Support for Logo, Brand,
|
|
13
|
+
Search, Transactions, and Describe APIs.
|
|
14
|
+
email:
|
|
15
|
+
- me@swlkr.com
|
|
16
|
+
executables: []
|
|
17
|
+
extensions: []
|
|
18
|
+
extra_rdoc_files: []
|
|
19
|
+
files:
|
|
20
|
+
- LICENSE
|
|
21
|
+
- README.md
|
|
22
|
+
- lib/logo_dev.rb
|
|
23
|
+
- lib/logo_dev/client.rb
|
|
24
|
+
- lib/logo_dev/error.rb
|
|
25
|
+
- lib/logo_dev/version.rb
|
|
26
|
+
- logo_dev.gemspec
|
|
27
|
+
homepage: https://github.com/swlkr/logodev
|
|
28
|
+
licenses:
|
|
29
|
+
- MIT
|
|
30
|
+
metadata:
|
|
31
|
+
allowed_push_host: https://rubygems.org
|
|
32
|
+
homepage_uri: https://github.com/swlkr/logodev
|
|
33
|
+
source_code_uri: https://github.com/swlkr/logodev
|
|
34
|
+
changelog_uri: https://github.com/swlkr/logodev/blob/main/CHANGELOG.md
|
|
35
|
+
rdoc_options: []
|
|
36
|
+
require_paths:
|
|
37
|
+
- lib
|
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ">="
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: 2.6.0
|
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
44
|
+
requirements:
|
|
45
|
+
- - ">="
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '0'
|
|
48
|
+
requirements: []
|
|
49
|
+
rubygems_version: 3.7.2
|
|
50
|
+
specification_version: 4
|
|
51
|
+
summary: A Ruby client for the Logo.dev API
|
|
52
|
+
test_files: []
|