rerout 0.6.0 → 0.7.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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +15 -0
- data/lib/rerout/create_link_input.rb +6 -2
- data/lib/rerout/models.rb +13 -3
- data/lib/rerout/risk_report.rb +144 -0
- data/lib/rerout/version.rb +1 -1
- data/lib/rerout.rb +1 -0
- metadata +4 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: cd1c03ec5a7c2a67ace85a5ee82286d48ab3fbb8b78899ebbc67a173c03023be
|
|
4
|
+
data.tar.gz: 96532142041469856e94a99d762ccd7a411200b041b5359659f07bd9994aacbb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 22c78607cd3b3c0eecaeba7807292b2576701116ac60a386033e312baa17096cfb99fd39fe488d6c39df3bf33200c5576ab018624096e3d60363755f38162b5f
|
|
7
|
+
data.tar.gz: c9e4ca8e9b6157574fd7200096a664bf6d0f82ddca6f7c95fed077db5cd1e5607cf90b0d17e9e421a7ebc10ba0aebc881c9f20e7e3cd7262d754b217624b35f0
|
data/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,18 @@ All notable changes to the `rerout` gem are documented in this file. The
|
|
|
4
4
|
format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
5
5
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
6
|
|
|
7
|
+
## [0.7.0] - 2026-11-18
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- `CreateLinkInput` `risk_report:` option — pass `true` to have the API scan
|
|
12
|
+
every destination before responding. Sent as `"risk_report": true` only
|
|
13
|
+
when set.
|
|
14
|
+
- Optional `Link#risk_report` (`Rerout::Models::RiskReport`) with typed
|
|
15
|
+
`RiskScanEntry`, `RiskScan`, `RiskFinding`, `RiskRedirectHop`,
|
|
16
|
+
`RiskScanLink`, and `RiskPreviousScan` models. Status and level values are
|
|
17
|
+
plain strings so new values never break parsing.
|
|
18
|
+
|
|
7
19
|
## [0.6.0] - 2026-07-13
|
|
8
20
|
|
|
9
21
|
### Added
|
data/README.md
CHANGED
|
@@ -149,6 +149,21 @@ rerout.links.update('q4', Rerout::UpdateLinkInput.new(routing_rules: [], ab_vari
|
|
|
149
149
|
|
|
150
150
|
Routing rules and A/B variants also accept plain Hashes.
|
|
151
151
|
|
|
152
|
+
### Link safety report on create
|
|
153
|
+
|
|
154
|
+
Pass `risk_report: true` to `CreateLinkInput` to have the API scan every
|
|
155
|
+
destination before responding. The returned `link.risk_report`
|
|
156
|
+
(`Rerout::Models::RiskReport`) carries the overall `status` (`"completed"`,
|
|
157
|
+
`"incomplete"`, or `"unavailable"` — the result then arrives by webhook),
|
|
158
|
+
`warning_level`, and per-destination `scans`.
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
link = rerout.links.create(
|
|
162
|
+
Rerout::CreateLinkInput.new(target_url: 'https://example.com', risk_report: true)
|
|
163
|
+
)
|
|
164
|
+
warn 'risky link' if %w[high critical].include?(link.risk_report&.warning_level)
|
|
165
|
+
```
|
|
166
|
+
|
|
152
167
|
## Batch link creation
|
|
153
168
|
|
|
154
169
|
```ruby
|
|
@@ -8,7 +8,7 @@ module Rerout
|
|
|
8
8
|
:seo_title, :seo_description, :seo_image_url,
|
|
9
9
|
:seo_canonical_url, :seo_noindex,
|
|
10
10
|
:password, :max_clicks, :track_conversions,
|
|
11
|
-
:routing_rules, :ab_variants
|
|
11
|
+
:routing_rules, :ab_variants, :risk_report
|
|
12
12
|
|
|
13
13
|
# @param target_url [String] required, the destination URL.
|
|
14
14
|
# @param domain_hostname [String, nil] verified custom domain (e.g. `go.brand.com`).
|
|
@@ -26,11 +26,13 @@ module Rerout
|
|
|
26
26
|
# Smart Link routing rules.
|
|
27
27
|
# @param ab_variants [Array<Rerout::Models::AbVariant, Hash>, nil]
|
|
28
28
|
# A/B-test variants — each `{ target_url:, weight? }`.
|
|
29
|
+
# @param risk_report [Boolean] scan every destination before responding and
|
|
30
|
+
# attach the result as `Link#risk_report`. Sent only when `true`.
|
|
29
31
|
def initialize(target_url:, domain_hostname: nil, code: nil, expires_at: nil,
|
|
30
32
|
seo_title: nil, seo_description: nil, seo_image_url: nil,
|
|
31
33
|
seo_canonical_url: nil, seo_noindex: nil,
|
|
32
34
|
password: nil, max_clicks: nil, track_conversions: nil,
|
|
33
|
-
routing_rules: nil, ab_variants: nil)
|
|
35
|
+
routing_rules: nil, ab_variants: nil, risk_report: false)
|
|
34
36
|
raise ArgumentError, 'target_url is required' if target_url.nil? || target_url.to_s.empty?
|
|
35
37
|
|
|
36
38
|
@target_url = target_url
|
|
@@ -47,6 +49,7 @@ module Rerout
|
|
|
47
49
|
@track_conversions = track_conversions
|
|
48
50
|
@routing_rules = routing_rules
|
|
49
51
|
@ab_variants = ab_variants
|
|
52
|
+
@risk_report = risk_report
|
|
50
53
|
freeze
|
|
51
54
|
end
|
|
52
55
|
|
|
@@ -66,6 +69,7 @@ module Rerout
|
|
|
66
69
|
hash['track_conversions'] = track_conversions unless track_conversions.nil?
|
|
67
70
|
hash['routing_rules'] = routing_rules.map { |r| InputSerialization.rule_hash(r) } unless routing_rules.nil?
|
|
68
71
|
hash['ab_variants'] = ab_variants.map { |v| InputSerialization.variant_hash(v) } unless ab_variants.nil?
|
|
72
|
+
hash['risk_report'] = true if risk_report
|
|
69
73
|
hash
|
|
70
74
|
end
|
|
71
75
|
end
|
data/lib/rerout/models.rb
CHANGED
|
@@ -186,7 +186,7 @@ module Rerout
|
|
|
186
186
|
is_active seo_title seo_description seo_image_url seo_canonical_url
|
|
187
187
|
seo_noindex seo_updated_at tags created_at updated_at
|
|
188
188
|
password_protected max_clicks click_count track_conversions
|
|
189
|
-
routing_rules ab_variants
|
|
189
|
+
routing_rules ab_variants risk_report
|
|
190
190
|
].freeze
|
|
191
191
|
|
|
192
192
|
attr_reader(*ATTRS)
|
|
@@ -217,14 +217,23 @@ module Rerout
|
|
|
217
217
|
tags: (hash['tags'] || []).map { |t| Tag.from_hash(t) },
|
|
218
218
|
created_at: hash['created_at'],
|
|
219
219
|
updated_at: hash['updated_at'],
|
|
220
|
+
**smart_attrs(hash)
|
|
221
|
+
)
|
|
222
|
+
end
|
|
223
|
+
|
|
224
|
+
# Smart Link fields plus the optional create-time risk report.
|
|
225
|
+
def self.smart_attrs(hash)
|
|
226
|
+
{
|
|
220
227
|
password_protected: hash.fetch('password_protected', false),
|
|
221
228
|
max_clicks: hash['max_clicks'],
|
|
222
229
|
click_count: hash.fetch('click_count', 0),
|
|
223
230
|
track_conversions: hash.fetch('track_conversions', false),
|
|
224
231
|
routing_rules: (hash['routing_rules'] || []).map { |r| RoutingRule.from_hash(r) },
|
|
225
|
-
ab_variants: (hash['ab_variants'] || []).map { |v| AbVariant.from_hash(v) }
|
|
226
|
-
|
|
232
|
+
ab_variants: (hash['ab_variants'] || []).map { |v| AbVariant.from_hash(v) },
|
|
233
|
+
risk_report: RiskReport.parse(hash['risk_report'])
|
|
234
|
+
}
|
|
227
235
|
end
|
|
236
|
+
private_class_method :smart_attrs
|
|
228
237
|
|
|
229
238
|
def to_h
|
|
230
239
|
ATTRS.to_h do |k|
|
|
@@ -232,6 +241,7 @@ module Rerout
|
|
|
232
241
|
when :tags then tags.map(&:to_h)
|
|
233
242
|
when :routing_rules then routing_rules.map(&:to_h)
|
|
234
243
|
when :ab_variants then ab_variants.map(&:to_h)
|
|
244
|
+
when :risk_report then risk_report&.to_h
|
|
235
245
|
else public_send(k)
|
|
236
246
|
end]
|
|
237
247
|
end
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rerout
|
|
4
|
+
module Models
|
|
5
|
+
# Shared plumbing for the link-safety report value objects. Every field is
|
|
6
|
+
# optional and enum-like values stay plain strings, so unknown values from
|
|
7
|
+
# newer API versions never break parsing.
|
|
8
|
+
class RiskValue
|
|
9
|
+
def initialize(**attrs)
|
|
10
|
+
self.class::ATTRS.each { |k| instance_variable_set(:"@#{k}", attrs[k]) }
|
|
11
|
+
freeze
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def self.hash_list(value)
|
|
15
|
+
value.is_a?(Array) ? value.grep(Hash) : []
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def to_h
|
|
19
|
+
self.class::ATTRS.to_h do |k|
|
|
20
|
+
v = public_send(k)
|
|
21
|
+
[k, if v.is_a?(Array) then v.map(&:to_h)
|
|
22
|
+
elsif v.is_a?(RiskValue) then v.to_h
|
|
23
|
+
else v
|
|
24
|
+
end]
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
def ==(other)
|
|
29
|
+
other.instance_of?(self.class) && other.to_h == to_h
|
|
30
|
+
end
|
|
31
|
+
alias eql? ==
|
|
32
|
+
|
|
33
|
+
def hash
|
|
34
|
+
[self.class, to_h].hash
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# One hop in the redirect chain followed while scanning — `{ url:, status: }`.
|
|
39
|
+
class RiskRedirectHop < RiskValue
|
|
40
|
+
ATTRS = %i[url status].freeze
|
|
41
|
+
attr_reader(*ATTRS)
|
|
42
|
+
|
|
43
|
+
def self.from_hash(hash)
|
|
44
|
+
new(url: hash['url'], status: hash['status'])
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# A single finding raised by a scan.
|
|
49
|
+
class RiskFinding < RiskValue
|
|
50
|
+
ATTRS = %i[code category level confidence description].freeze
|
|
51
|
+
attr_reader(*ATTRS)
|
|
52
|
+
|
|
53
|
+
def self.from_hash(hash)
|
|
54
|
+
new(**ATTRS.to_h { |k| [k, hash[k.to_s]] })
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# The result of scanning one destination.
|
|
59
|
+
class RiskScan < RiskValue
|
|
60
|
+
ATTRS = %i[
|
|
61
|
+
id trigger final_url redirect_chain status warning_level confidence
|
|
62
|
+
coverage verdict summary findings engine_version completed_at report_url
|
|
63
|
+
].freeze
|
|
64
|
+
attr_reader(*ATTRS)
|
|
65
|
+
|
|
66
|
+
def initialize(**attrs)
|
|
67
|
+
super(**attrs.merge(redirect_chain: (attrs[:redirect_chain] || []).freeze,
|
|
68
|
+
findings: (attrs[:findings] || []).freeze))
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def self.from_hash(hash)
|
|
72
|
+
attrs = ATTRS.to_h { |k| [k, hash[k.to_s]] }
|
|
73
|
+
attrs[:redirect_chain] = hash_list(hash['redirect_chain']).map { |h| RiskRedirectHop.from_hash(h) }
|
|
74
|
+
attrs[:findings] = hash_list(hash['findings']).map { |f| RiskFinding.from_hash(f) }
|
|
75
|
+
new(**attrs)
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
# Which link and destination a scan covered.
|
|
80
|
+
class RiskScanLink < RiskValue
|
|
81
|
+
ATTRS = %i[code short_url revision destination_kind destination_index destination_url].freeze
|
|
82
|
+
attr_reader(*ATTRS)
|
|
83
|
+
|
|
84
|
+
def self.from_hash(hash)
|
|
85
|
+
new(**ATTRS.to_h { |k| [k, hash[k.to_s]] })
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# The previous scan of the same destination — `{ scan_id:, warning_level: }`.
|
|
90
|
+
class RiskPreviousScan < RiskValue
|
|
91
|
+
ATTRS = %i[scan_id warning_level].freeze
|
|
92
|
+
attr_reader(*ATTRS)
|
|
93
|
+
|
|
94
|
+
def self.from_hash(hash)
|
|
95
|
+
new(scan_id: hash['scan_id'], warning_level: hash['warning_level'])
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
# One entry of `RiskReport#scans`: the scan, the destination it covered,
|
|
100
|
+
# and the previous scan (or `nil`).
|
|
101
|
+
class RiskScanEntry < RiskValue
|
|
102
|
+
ATTRS = %i[scan link previous].freeze
|
|
103
|
+
attr_reader(*ATTRS)
|
|
104
|
+
|
|
105
|
+
def self.from_hash(hash)
|
|
106
|
+
scan = hash['scan'].is_a?(Hash) ? hash['scan'] : {}
|
|
107
|
+
link = hash['link'].is_a?(Hash) ? hash['link'] : {}
|
|
108
|
+
previous = hash['previous']
|
|
109
|
+
new(
|
|
110
|
+
scan: RiskScan.from_hash(scan),
|
|
111
|
+
link: RiskScanLink.from_hash(link),
|
|
112
|
+
previous: previous.is_a?(Hash) ? RiskPreviousScan.from_hash(previous) : nil
|
|
113
|
+
)
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Synchronous link-safety report, returned by `links.create` when
|
|
118
|
+
# `risk_report: true` was requested. `status` is `"completed"`,
|
|
119
|
+
# `"incomplete"` or `"unavailable"`; `message` is only set when the
|
|
120
|
+
# scanner was unavailable and the result will arrive by webhook.
|
|
121
|
+
class RiskReport < RiskValue
|
|
122
|
+
ATTRS = %i[status warning_level message scans].freeze
|
|
123
|
+
attr_reader(*ATTRS)
|
|
124
|
+
|
|
125
|
+
def initialize(**attrs)
|
|
126
|
+
super(**attrs.merge(scans: (attrs[:scans] || []).freeze))
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
# Parse the `risk_report` field of a link, or `nil` when absent.
|
|
130
|
+
def self.parse(value)
|
|
131
|
+
value.is_a?(Hash) ? from_hash(value) : nil
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
def self.from_hash(hash)
|
|
135
|
+
new(
|
|
136
|
+
status: hash['status'],
|
|
137
|
+
warning_level: hash['warning_level'],
|
|
138
|
+
message: hash['message'],
|
|
139
|
+
scans: hash_list(hash['scans']).map { |e| RiskScanEntry.from_hash(e) }
|
|
140
|
+
)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
end
|
data/lib/rerout/version.rb
CHANGED
data/lib/rerout.rb
CHANGED
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require_relative 'rerout/version'
|
|
4
4
|
require_relative 'rerout/error'
|
|
5
5
|
require_relative 'rerout/models'
|
|
6
|
+
require_relative 'rerout/risk_report'
|
|
6
7
|
require_relative 'rerout/input_serialization'
|
|
7
8
|
require_relative 'rerout/create_link_input'
|
|
8
9
|
require_relative 'rerout/update_link_input'
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rerout
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.7.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Codecraft Solutions
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: faraday
|
|
@@ -120,6 +119,7 @@ files:
|
|
|
120
119
|
- lib/rerout/project.rb
|
|
121
120
|
- lib/rerout/qr.rb
|
|
122
121
|
- lib/rerout/qr_options.rb
|
|
122
|
+
- lib/rerout/risk_report.rb
|
|
123
123
|
- lib/rerout/tags_resource.rb
|
|
124
124
|
- lib/rerout/update_link_input.rb
|
|
125
125
|
- lib/rerout/update_tag_input.rb
|
|
@@ -136,7 +136,6 @@ metadata:
|
|
|
136
136
|
bug_tracker_uri: https://github.com/ModestNerds-Co/rerout-sdks/issues
|
|
137
137
|
documentation_uri: https://rerout.co/docs
|
|
138
138
|
rubygems_mfa_required: 'true'
|
|
139
|
-
post_install_message:
|
|
140
139
|
rdoc_options: []
|
|
141
140
|
require_paths:
|
|
142
141
|
- lib
|
|
@@ -151,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
151
150
|
- !ruby/object:Gem::Version
|
|
152
151
|
version: '0'
|
|
153
152
|
requirements: []
|
|
154
|
-
rubygems_version: 3.
|
|
155
|
-
signing_key:
|
|
153
|
+
rubygems_version: 3.6.9
|
|
156
154
|
specification_version: 4
|
|
157
155
|
summary: Official Ruby SDK for the Rerout branded-link API.
|
|
158
156
|
test_files: []
|