og_pilot_ruby 0.4.7 → 0.4.8

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7378c97e45ba7c02d8f8895b53614583443c0d393d56e0c8f4267941a65012d1
4
- data.tar.gz: ec37c266916a73ce5610d7a9a74137bd1771dddf9f368db910c2d8f36880a1e9
3
+ metadata.gz: 7337416e1651ceadf68ca9eba08b8a4a4945d62f30154391006b2dd11cd7e892
4
+ data.tar.gz: ebd7c609da7e75151f6f06741b82a19d244ca3953e7f563f496f7f268c3ec5cb
5
5
  SHA512:
6
- metadata.gz: b12fee2e4b63b2eb78942dfa301c7fdeaa44c205dacac2e505c05720370be0ca33da85ddcad5af19d64c9accca72098bc17942bb581ecc6492e14ca06d064fa1
7
- data.tar.gz: ceb27ff2523496441e15247740db9dbb446fe59aebfe242f3f81b127e033bb66b57e0f774a9e7f3d549c000c8066d3ea1f509267ce3ed9bdf2d0d10a4eb96784
6
+ metadata.gz: 06fcd6974ee8842cff3cb77747cb0c8a011207aecc5d0fced3f92ea049fd6109343d0bb9395fbe8798267a681b79a1d72dded42935c75e05c8e99b1d443c747f
7
+ data.tar.gz: 198f785e8486ebad307f5ca1f4c70d4743362e526bb9ff5978d65ad30a8878677f498f2c120317491319cf67183ffbffee0092432cfee65b359731e316e947dc
data/README.md CHANGED
@@ -29,6 +29,9 @@ OgPilotRuby.configure do |config|
29
29
  config.api_key = ENV.fetch("OG_PILOT_API_KEY")
30
30
  config.domain = ENV.fetch("OG_PILOT_DOMAIN")
31
31
  # config.strip_extensions = true
32
+ # config.image_type = "webp"
33
+ # config.quality = 82
34
+ # config.max_bytes = 220_000
32
35
  # config.cache_store = Rails.cache
33
36
  # config.cache_ttl = 86_400
34
37
  end
@@ -63,6 +66,19 @@ image_url = OgPilotRuby.create_image(
63
66
  If you omit `iat`, OG Pilot will cache the image indefinitely. Provide an `iat` to
64
67
  refresh the cache daily.
65
68
 
69
+ For the same delivery settings on every request, configure them once:
70
+
71
+ ```ruby
72
+ OgPilotRuby.configure do |config|
73
+ config.image_type = "webp"
74
+ config.quality = 82
75
+ config.max_bytes = 220_000
76
+ end
77
+ ```
78
+
79
+ Per-call `image_type`, `quality`, and `max_bytes` values still override those
80
+ defaults when you need a one-off delivery profile.
81
+
66
82
  When `config.cache_store` is set, the client can also cache generated responses
67
83
  locally:
68
84
 
@@ -553,6 +569,9 @@ The gem handles `iss` (domain) and `sub` (API key prefix) automatically.
553
569
  | `image_url` | No | — | Hero image URL |
554
570
  | `bg_color` | No | — | Background color (hex format) |
555
571
  | `text_color` | No | — | Text color (hex format) |
572
+ | `image_type` | No | — | Delivered image format: `jpeg`, `png`, `webp`, or `gif` |
573
+ | `quality` | No | — | Delivered image quality from `1` to `100` |
574
+ | `max_bytes` | No | — | Maximum delivered image size in bytes |
556
575
  | `iat` | No | — | Issued-at timestamp for daily cache busting |
557
576
  | `path` | No | auto-set | Request path for image rendering context. When provided, it overrides auto-resolution (see [Path handling](#path-handling)) |
558
577
 
@@ -567,6 +586,9 @@ The gem handles `iss` (domain) and `sub` (API key prefix) automatically.
567
586
  | `read_timeout` | `10` | Read timeout in seconds |
568
587
  | `strip_extensions` | `true` | When `true`, file extensions are stripped from resolved paths (see [Strip extensions](#strip-extensions)) |
569
588
  | `strip_query_parameters` | `false` | When `true`, query strings are removed from resolved paths before signing (see [Strip query parameters](#strip-query-parameters)) |
589
+ | `image_type` | `nil` | Default delivered image format: `jpeg`, `png`, `webp`, or `gif` |
590
+ | `quality` | `nil` | Default delivered image quality from `1` to `100` |
591
+ | `max_bytes` | `nil` | Default maximum delivered image size in bytes |
570
592
  | `cache_store` | `nil` | Optional cache backend with `read`/`write` (for example `Rails.cache`) |
571
593
  | `cache_ttl` | `86400` | Cache TTL in seconds when `cache_store` is enabled |
572
594
 
@@ -10,4 +10,7 @@ OgPilotRuby.configure do |config|
10
10
  # config.read_timeout = 10
11
11
  # config.strip_extensions = true
12
12
  # config.strip_query_parameters = true
13
+ # config.image_type = "webp"
14
+ # config.quality = 82
15
+ # config.max_bytes = 220_000
13
16
  end
@@ -20,7 +20,7 @@ module OgPilotRuby
20
20
 
21
21
  def create_image(params = {}, json: false, iat: nil, headers: {}, default: false)
22
22
  params ||= {}
23
- params = params.dup
23
+ params = apply_configured_image_defaults(params.dup)
24
24
  # Always include a path; manual overrides win, otherwise resolve from the current request.
25
25
  manual_path = params.key?(:path) ? params[:path] : params["path"]
26
26
  params.delete("path") if params.key?("path")
@@ -178,6 +178,21 @@ module OgPilotRuby
178
178
  symbolized
179
179
  end
180
180
 
181
+ def apply_configured_image_defaults(params)
182
+ {
183
+ image_type: config.image_type,
184
+ quality: config.quality,
185
+ max_bytes: config.max_bytes
186
+ }.each do |key, value|
187
+ next if value.nil?
188
+ next if params.key?(key) || params.key?(key.to_s)
189
+
190
+ params[key] = value
191
+ end
192
+
193
+ params
194
+ end
195
+
181
196
  def validate_payload!(payload)
182
197
  raise OgPilotRuby::ConfigurationError, "OG Pilot domain is missing" if payload[:iss].nil? || payload[:iss].empty?
183
198
  raise OgPilotRuby::ConfigurationError, "OG Pilot API key prefix is missing" if payload[:sub].nil? || payload[:sub].empty?
@@ -5,7 +5,9 @@ module OgPilotRuby
5
5
  DEFAULT_BASE_URL = "https://ogpilot.com"
6
6
  private_constant :DEFAULT_BASE_URL
7
7
 
8
- attr_accessor :api_key, :domain, :base_url, :open_timeout, :read_timeout, :strip_extensions, :strip_query_parameters, :cache_store, :cache_ttl
8
+ attr_accessor :api_key, :domain, :base_url, :open_timeout, :read_timeout,
9
+ :strip_extensions, :strip_query_parameters, :image_type,
10
+ :quality, :max_bytes, :cache_store, :cache_ttl
9
11
 
10
12
  def initialize
11
13
  @api_key = ENV.fetch("OG_PILOT_API_KEY", nil)
@@ -15,6 +17,9 @@ module OgPilotRuby
15
17
  @read_timeout = 10
16
18
  @strip_extensions = true
17
19
  @strip_query_parameters = false
20
+ @image_type = nil
21
+ @quality = nil
22
+ @max_bytes = nil
18
23
  @cache_store = nil
19
24
  @cache_ttl = 86400
20
25
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OgPilotRuby
4
- VERSION = "0.4.7"
4
+ VERSION = "0.4.8"
5
5
  end
data/lib/og_pilot_ruby.rb CHANGED
@@ -59,6 +59,9 @@ module OgPilotRuby
59
59
  # image_url - String hero image URL.
60
60
  # bg_color - String background color (hex format).
61
61
  # text_color - String text color (hex format).
62
+ # image_type - String delivered image format (jpeg/png/webp/gif).
63
+ # quality - Integer delivered image quality (1-100).
64
+ # max_bytes - Integer maximum delivered image size in bytes.
62
65
  # path - String request path for analytics context.
63
66
  #
64
67
  # == Request options
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: og_pilot_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.7
4
+ version: 0.4.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sunergos IT LLC