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:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7337416e1651ceadf68ca9eba08b8a4a4945d62f30154391006b2dd11cd7e892
|
|
4
|
+
data.tar.gz: ebd7c609da7e75151f6f06741b82a19d244ca3953e7f563f496f7f268c3ec5cb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
|
data/lib/og_pilot_ruby/client.rb
CHANGED
|
@@ -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,
|
|
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
|
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
|