fireimg 1.0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5250ba61c2e4e5c42e372bf3947a710a941eb6d1a3c208e466f3a42185931056
4
+ data.tar.gz: bf9ec77b5168637ad0ca494cc74038b83b37a4b45c82810ab9dcc345b85a6571
5
+ SHA512:
6
+ metadata.gz: 6632550c999b8450549eeda9214af9c853c2e49b29931eb2e25be227c86fd579e40f5fcf73a2ecc063e11121cb5e336d2ecb4169e41ea646b201c7d47bac899d
7
+ data.tar.gz: f50017794cf2dfd83bfc463850d972eb8f7807356b40c0a59ee5d5c501486d856b3ffeb897513507eb0be6d3d0b6432a5c12fa6fb3afad59f7fefd93ea43174e
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0
4
+
5
+ - Presign uploads (folder keys, optional `sizes` to pre-generate variants)
6
+ - Moderate and delete images via the API-key HTTP API
7
+ - Build public and query-parameter CDN URLs
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Firelit Studio
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,73 @@
1
+ # fireimg
2
+
3
+ Ruby client for [FireImg](https://fireimg.com): API-key uploads, optional
4
+ moderation, and CDN URLs.
5
+
6
+ Source of truth is developed in the private FireImg repo and mirrored here.
7
+
8
+ ## Install
9
+
10
+ ```ruby
11
+ gem 'fireimg', '~> 1.0'
12
+ ```
13
+
14
+ ```bash
15
+ bundle add fireimg
16
+ ```
17
+
18
+ ## Configure
19
+
20
+ ```ruby
21
+ Fireimg.configure do |c|
22
+ c.api_key = ENV.fetch('FIREIMG_API_KEY')
23
+ c.project = ENV.fetch('FIREIMG_PROJECT')
24
+ c.api_base = ENV.fetch('FIREIMG_API_BASE', 'https://api.fireimg.com')
25
+ c.cdn_base = ENV.fetch('FIREIMG_CDN_BASE', 'https://img.fireimg.com')
26
+ end
27
+ ```
28
+
29
+ `FIREIMG_API_KEY` and `FIREIMG_PROJECT` are also read automatically if you skip
30
+ the block. `FIREIMG_API_BASE` and `FIREIMG_CDN_BASE` have the defaults above.
31
+
32
+ ## Upload
33
+
34
+ ```ruby
35
+ result = Fireimg.presign(
36
+ filename: 'feed_items/43/uuid.jpg',
37
+ content_type: 'image/jpeg',
38
+ sizes: [
39
+ { width: 800, quality: 'medium' },
40
+ { width: 160, height: 160, fit: 'cover', pos: 'center' }
41
+ ]
42
+ )
43
+
44
+ # PUT raw bytes to result.upload_url with the same Content-Type.
45
+ ```
46
+
47
+ `filename` may include folders. Optional `sizes` (up to 20) are generated
48
+ asynchronously after the `PUT` and **replace** the project's default image
49
+ params for that upload. Omit `sizes` to keep project defaults. Pass `sizes: []`
50
+ to pre-generate only FireImg's 80px dashboard thumbnail.
51
+
52
+ ## Moderate and delete
53
+
54
+ ```ruby
55
+ labels = Fireimg.moderate('feed_items/43/uuid.jpg')
56
+ Fireimg.delete('feed_items/43/uuid.jpg')
57
+ ```
58
+
59
+ Moderation returns FireImg labels; your app applies policy.
60
+
61
+ ## URLs
62
+
63
+ ```ruby
64
+ Fireimg.public_url('feed_items/43/uuid.jpg')
65
+ # => https://img.fireimg.com/{project}/images/feed_items/43/uuid.jpg
66
+
67
+ Fireimg.url('feed_items/43/uuid.jpg', width: 800, quality: 'medium', fmt: 'webp')
68
+ # => …/images/feed_items/43/uuid.jpg?width=800&quality=medium&fmt=webp
69
+ ```
70
+
71
+ ## License
72
+
73
+ MIT
@@ -0,0 +1,149 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ module Fireimg
8
+ class Client
9
+ def initialize(config = Fireimg.configuration)
10
+ @config = config
11
+ end
12
+
13
+ def configured?
14
+ @config.configured?
15
+ end
16
+
17
+ def project
18
+ @config.project
19
+ end
20
+
21
+ def api_base
22
+ @config.api_base
23
+ end
24
+
25
+ def cdn_base
26
+ @config.cdn_base
27
+ end
28
+
29
+ def public_url(image_key)
30
+ key = image_key.to_s.sub(%r{\A/+}, '')
31
+ "#{cdn_base}/#{project}/images/#{key}"
32
+ end
33
+
34
+ # CDN URL with query-parameter transforms, matching @fireimg/js getUrl.
35
+ def url(image_key, **options)
36
+ key = image_key.to_s.sub(%r{\A/+}, '')
37
+ qs = query_string(options)
38
+ base = "#{cdn_base}/#{project}/images/#{key}"
39
+ qs.empty? ? base : "#{base}?#{qs}"
40
+ end
41
+
42
+ def presign(filename:, content_type:, sizes: nil)
43
+ rows = presign_many(files: [{ filename: filename, content_type: content_type }], sizes: sizes)
44
+ raise Error, 'FireImg presign returned no URLs' if rows.empty?
45
+
46
+ rows.first
47
+ end
48
+
49
+ def presign_many(files:, sizes: nil)
50
+ payload = {
51
+ 'slug' => project,
52
+ 'files' => Array(files).map { |file| file_payload(file) }
53
+ }
54
+ payload['sizes'] = Array(sizes).map { |size| Size.from(size).to_h } unless sizes.nil?
55
+
56
+ body = post_json('/v1/api/presigned-upload-urls', payload)
57
+ Array(body['urls']).map { |row| parse_presign_row(row) }
58
+ end
59
+
60
+ def moderate(image_key)
61
+ post_json("/v1/api/projects/#{project}/images/moderation/#{image_key}", {})
62
+ end
63
+
64
+ def delete(image_key)
65
+ request_json(Net::HTTP::Delete, "/v1/api/projects/#{project}/images/#{image_key}", nil)
66
+ true
67
+ end
68
+
69
+ private
70
+
71
+ def file_payload(file)
72
+ h = stringify_keys(file)
73
+ filename = h['filename'] || h[:filename]
74
+ content_type = h['content_type'] || h['contentType'] || h[:content_type]
75
+ raise Error, 'filename is required' if filename.to_s.strip.empty?
76
+ raise Error, 'content_type is required' if content_type.to_s.strip.empty?
77
+
78
+ { 'filename' => filename, 'contentType' => content_type }
79
+ end
80
+
81
+ def parse_presign_row(row)
82
+ h = stringify_keys(row)
83
+ PresignResult.new(
84
+ upload_url: h['uploadUrl'] || h['upload_url'],
85
+ s3_key: h['s3Key'] || h['s3_key'],
86
+ filename: h['filename'],
87
+ expires_in_secs: h['expiresInSecs'] || h['expires_in_secs']
88
+ )
89
+ end
90
+
91
+ def query_string(options)
92
+ params = []
93
+ w = options[:width]
94
+ h = options[:height]
95
+ params << ['width', w] if w && w.to_i > 0
96
+ params << ['height', h] if h && h.to_i > 0
97
+ q = options[:quality]
98
+ params << ['quality', q] unless q.nil? || q.to_s.empty?
99
+ fmt = options[:fmt] || options[:format]
100
+ params << ['fmt', fmt] unless fmt.nil? || fmt.to_s.empty?
101
+ fit = options[:fit]
102
+ params << ['fit', fit] unless fit.nil? || fit.to_s.empty?
103
+ pos = options[:pos] || options[:position]
104
+ params << ['pos', pos] unless pos.nil? || pos.to_s.empty?
105
+ fill = options[:fill]
106
+ params << ['fill', fill] unless fill.nil? || fill.to_s.empty?
107
+ params.map { |k, v| "#{k}=#{URI.encode_www_form_component(v.to_s)}" }.join('&')
108
+ end
109
+
110
+ def post_json(path, body)
111
+ request_json(Net::HTTP::Post, path, body)
112
+ end
113
+
114
+ def request_json(method_class, path, body)
115
+ raise Error, 'FireImg is not configured (set api_key and project)' unless configured?
116
+
117
+ uri = URI.parse("#{api_base}#{path}")
118
+ http = Net::HTTP.new(uri.host, uri.port)
119
+ http.use_ssl = uri.scheme == 'https'
120
+ http.open_timeout = 5
121
+ http.read_timeout = 20
122
+ req = method_class.new(uri.request_uri)
123
+ req['Content-Type'] = 'application/json'
124
+ req['Accept'] = 'application/json'
125
+ req['X-Api-Key'] = @config.api_key
126
+ req.body = JSON.generate(body) unless body.nil?
127
+ res = http.request(req)
128
+ parsed = parse_json(res.body)
129
+ unless res.is_a?(Net::HTTPSuccess)
130
+ message = parsed['error'] || parsed['message'] || res.message
131
+ raise Error, "FireImg #{res.code}: #{message}"
132
+ end
133
+ parsed
134
+ end
135
+
136
+ def parse_json(raw)
137
+ JSON.parse(raw.to_s.empty? ? '{}' : raw)
138
+ rescue JSON::ParserError
139
+ {}
140
+ end
141
+
142
+ def stringify_keys(value)
143
+ return {} if value.nil?
144
+ return value.transform_keys(&:to_s) if value.respond_to?(:transform_keys)
145
+
146
+ value.to_h.transform_keys(&:to_s)
147
+ end
148
+ end
149
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireimg
4
+ class Configuration
5
+ DEFAULT_API_BASE = 'https://api.fireimg.com'
6
+ DEFAULT_CDN_BASE = 'https://img.fireimg.com'
7
+
8
+ attr_accessor :api_key, :project, :api_base, :cdn_base
9
+
10
+ def initialize
11
+ @api_key = ENV['FIREIMG_API_KEY'].to_s.strip
12
+ @project = (ENV['FIREIMG_PROJECT'] || '').to_s.strip
13
+ @api_base = strip_slash(ENV['FIREIMG_API_BASE'].to_s.strip)
14
+ @api_base = DEFAULT_API_BASE if @api_base.empty?
15
+ @cdn_base = strip_slash(ENV['FIREIMG_CDN_BASE'].to_s.strip)
16
+ @cdn_base = DEFAULT_CDN_BASE if @cdn_base.empty?
17
+ end
18
+
19
+ def configured?
20
+ !api_key.to_s.strip.empty? && !project.to_s.strip.empty?
21
+ end
22
+
23
+ def api_base=(value)
24
+ @api_base = strip_slash(value.to_s)
25
+ @api_base = DEFAULT_API_BASE if @api_base.empty?
26
+ end
27
+
28
+ def cdn_base=(value)
29
+ @cdn_base = strip_slash(value.to_s)
30
+ @cdn_base = DEFAULT_CDN_BASE if @cdn_base.empty?
31
+ end
32
+
33
+ private
34
+
35
+ def strip_slash(value)
36
+ value.to_s.sub(%r{/\z}, '')
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireimg
4
+ class Error < StandardError; end
5
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireimg
4
+ PresignResult = Struct.new(:upload_url, :s3_key, :filename, :expires_in_secs, keyword_init: true) do
5
+ def to_h
6
+ {
7
+ 'upload_url' => upload_url,
8
+ 's3_key' => s3_key,
9
+ 'filename' => filename,
10
+ 'expires_in_secs' => expires_in_secs
11
+ }
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireimg
4
+ # A variant to pre-generate after upload. Matches FireImg `sizes` JSON
5
+ # (`width`/`height`, `quality`, `fmt`, `fit`, `pos`, `fill`).
6
+ class Size
7
+ attr_reader :width, :height, :quality, :fmt, :fit, :pos, :fill
8
+
9
+ def initialize(width: nil, height: nil, quality: nil, fmt: nil, fit: nil, pos: nil, fill: nil)
10
+ @width = width
11
+ @height = height
12
+ @quality = quality
13
+ @fmt = fmt
14
+ @fit = fit
15
+ @pos = pos
16
+ @fill = fill
17
+ end
18
+
19
+ def self.from(value)
20
+ case value
21
+ when Size
22
+ value
23
+ when Hash
24
+ h = value.transform_keys { |k| k.to_s.tr('-', '_') }
25
+ new(
26
+ width: h['width'],
27
+ height: h['height'],
28
+ quality: h['quality'],
29
+ fmt: h['fmt'] || h['format'],
30
+ fit: h['fit'],
31
+ pos: h['pos'] || h['position'],
32
+ fill: h['fill']
33
+ )
34
+ else
35
+ raise ArgumentError, "expected Fireimg::Size or Hash, got #{value.class}"
36
+ end
37
+ end
38
+
39
+ def to_h
40
+ out = {}
41
+ out[:width] = Integer(width) if width && Integer(width) > 0
42
+ out[:height] = Integer(height) if height && Integer(height) > 0
43
+ out[:quality] = quality.to_s unless quality.nil? || quality.to_s.empty?
44
+ out[:fmt] = fmt.to_s unless fmt.nil? || fmt.to_s.empty?
45
+ out[:fit] = fit.to_s unless fit.nil? || fit.to_s.empty?
46
+ out[:pos] = pos.to_s unless pos.nil? || pos.to_s.empty?
47
+ out[:fill] = fill.to_s unless fill.nil? || fill.to_s.empty?
48
+ out
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Fireimg
4
+ VERSION = '1.0.0'
5
+ end
data/lib/fireimg.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'fireimg/version'
4
+ require_relative 'fireimg/error'
5
+ require_relative 'fireimg/configuration'
6
+ require_relative 'fireimg/size'
7
+ require_relative 'fireimg/presign_result'
8
+ require_relative 'fireimg/client'
9
+
10
+ module Fireimg
11
+ class << self
12
+ def configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def configure
17
+ yield configuration
18
+ @client = nil
19
+ configuration
20
+ end
21
+
22
+ def reset!
23
+ @configuration = Configuration.new
24
+ @client = nil
25
+ end
26
+
27
+ def client
28
+ @client ||= Client.new(configuration)
29
+ end
30
+
31
+ def configured?
32
+ configuration.configured?
33
+ end
34
+
35
+ def public_url(image_key)
36
+ client.public_url(image_key)
37
+ end
38
+
39
+ def url(image_key, **options)
40
+ client.url(image_key, **options)
41
+ end
42
+
43
+ def presign(...)
44
+ client.presign(...)
45
+ end
46
+
47
+ def presign_many(...)
48
+ client.presign_many(...)
49
+ end
50
+
51
+ def moderate(image_key)
52
+ client.moderate(image_key)
53
+ end
54
+
55
+ def delete(image_key)
56
+ client.delete(image_key)
57
+ end
58
+ end
59
+ end
metadata ADDED
@@ -0,0 +1,61 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fireimg
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Firelit Studio
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-08-25 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: |
14
+ Server-side Ruby client for FireImg. Request presigned uploads (including
15
+ folder keys and optional pre-generated sizes), run content moderation, and
16
+ build CDN URLs. Matches the FireImg API-key HTTP API and @fireimg/js URL
17
+ query parameters.
18
+ email:
19
+ - hello@firelit.studio
20
+ executables: []
21
+ extensions: []
22
+ extra_rdoc_files: []
23
+ files:
24
+ - CHANGELOG.md
25
+ - LICENSE
26
+ - README.md
27
+ - lib/fireimg.rb
28
+ - lib/fireimg/client.rb
29
+ - lib/fireimg/configuration.rb
30
+ - lib/fireimg/error.rb
31
+ - lib/fireimg/presign_result.rb
32
+ - lib/fireimg/size.rb
33
+ - lib/fireimg/version.rb
34
+ homepage: https://github.com/FirelitStudio/fireimg-ruby
35
+ licenses:
36
+ - MIT
37
+ metadata:
38
+ homepage_uri: https://github.com/FirelitStudio/fireimg-ruby
39
+ source_code_uri: https://github.com/FirelitStudio/fireimg-ruby
40
+ changelog_uri: https://github.com/FirelitStudio/fireimg-ruby/blob/main/CHANGELOG.md
41
+ allowed_push_host: https://rubygems.org
42
+ post_install_message:
43
+ rdoc_options: []
44
+ require_paths:
45
+ - lib
46
+ required_ruby_version: !ruby/object:Gem::Requirement
47
+ requirements:
48
+ - - ">="
49
+ - !ruby/object:Gem::Version
50
+ version: '3.1'
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ requirements: []
57
+ rubygems_version: 3.5.3
58
+ signing_key:
59
+ specification_version: 4
60
+ summary: Ruby client for FireImg uploads, moderation, and CDN URLs
61
+ test_files: []