recapi 0.1.13 → 0.1.15
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/README.md +42 -14
- data/lib/recapi.rb +135 -61
- metadata +6 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 955bf1ce3f0c03191af7c2292d51f26a8c27ecd5eabd92ae8fb0b95e21d36c07
|
|
4
|
+
data.tar.gz: f5ce6c0d310e8a307cf1a8db3563d0184a4c6e00cc41c05575c17ba690f78580
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c94cb8d86868e975e5ef63594b957b439feaf4880cbc1c2acfa3ecccb4d61fbfca70aaafe804c6c2419f315e9ebbfe78ab7ad61a9c6bcbcfc5af9fc4f48e87f1
|
|
7
|
+
data.tar.gz: dc57e8e7a0cc117b54bdc3543a616b80b035b4573ca98cd6a9d02dd0e752355045cba66849b8cfbea84da6efd94d60189b6f98bcc45bffbcd53aef5c68b238f3
|
data/README.md
CHANGED
|
@@ -5,20 +5,18 @@ and background jobs. Ruby 3.1 or newer (tested on 3.1 and 4.0), standard
|
|
|
5
5
|
library only (`net/http`, `json`), one file, no dependency: it requires only
|
|
6
6
|
default gems, so it loads in a Bundler app whose Gemfile lists nothing else.
|
|
7
7
|
|
|
8
|
-
Like the
|
|
9
|
-
|
|
10
|
-
([docs/history-spec.md](../../docs/history-spec.md)) and sends it with every
|
|
8
|
+
Like the Python and Go libraries, it keeps each user's decayed **history**
|
|
9
|
+
and sends it with every
|
|
11
10
|
recommendation request, **sends events in the background** in batches of up
|
|
12
11
|
to 1,000 with **retries**, **falls back to popular items** when recapi is
|
|
13
12
|
slow or failing, and **attributes** events on recommended items to the
|
|
14
13
|
recommendation that showed them (the dashboard's clicks and conversions). It
|
|
15
|
-
passes
|
|
14
|
+
passes recapi's shared test vectors.
|
|
16
15
|
|
|
17
16
|
## Install
|
|
18
17
|
|
|
19
|
-
The library is the gem `recapi` on RubyGems
|
|
20
|
-
|
|
21
|
-
add `gem "recapi"` to your Gemfile, or
|
|
18
|
+
The library is the gem `recapi` on RubyGems: add `gem "recapi"` to your
|
|
19
|
+
Gemfile, or
|
|
22
20
|
|
|
23
21
|
```sh
|
|
24
22
|
bundle add recapi
|
|
@@ -30,7 +28,7 @@ line with your address): save it as `lib/recapi.rb` and
|
|
|
30
28
|
`require Rails.root.join("lib/recapi").to_s` instead.
|
|
31
29
|
|
|
32
30
|
```sh
|
|
33
|
-
curl -fLo lib/recapi.rb https://api.<your-domain>/sdk/ruby/recapi-0.1.
|
|
31
|
+
curl -fLo lib/recapi.rb https://api.<your-domain>/sdk/ruby/recapi-0.1.15.rb
|
|
34
32
|
```
|
|
35
33
|
|
|
36
34
|
## Quick start
|
|
@@ -53,13 +51,29 @@ recs.items.each do |item|
|
|
|
53
51
|
item.item_id # a String, as every id recapi returns
|
|
54
52
|
item.metadata # the item's stored object (a Hash), or nil
|
|
55
53
|
# why it is listed ("for_you", "similar", "trending"...), safe to show anyone: map the codes you
|
|
56
|
-
# want to your own label (docs/api
|
|
54
|
+
# want to your own label (https://recapi.io/docs/api#reason-codes), and show none for a code you don't map.
|
|
57
55
|
label = LABELS[item.why]
|
|
58
56
|
end
|
|
59
57
|
```
|
|
60
58
|
|
|
61
59
|
Ids may be strings or integers (an ActiveRecord id): they travel as strings.
|
|
62
60
|
|
|
61
|
+
### Several rows in one call
|
|
62
|
+
|
|
63
|
+
A page with several rows asks them in one call, billed as one recommendation;
|
|
64
|
+
an item appears on one row only unless `allow_repeats: true`:
|
|
65
|
+
|
|
66
|
+
```ruby
|
|
67
|
+
# One Recapi::Recommendations per list, in order.
|
|
68
|
+
similar, accessories = RECAPI.recommend_lists(user_id: current_user.id, exclude: cart_ids, lists: [
|
|
69
|
+
{ placement: "product", count: 4, context_item_id: product.id },
|
|
70
|
+
{ placement: "cart", count: 6, tags_any: ["accessories"] }
|
|
71
|
+
])
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
Each list takes `recommend`'s `placement`, `count`, `tags_any`, `tags_all`,
|
|
75
|
+
`exclude`, `context_item_id` and `discovery`; it fails and falls back as `recommend` does, row by row.
|
|
76
|
+
|
|
63
77
|
## Calls
|
|
64
78
|
|
|
65
79
|
A refused argument (an invalid id or level) raises `ArgumentError`, except an
|
|
@@ -78,7 +92,7 @@ and a log line.
|
|
|
78
92
|
| `recommend(user_id:, anon_id:, count:, placement:, tags_any:, tags_all:, exclude:, context_item_id:, discovery:)` | A `Recapi::Recommendations` (`recommendation_id`, `fallback?`, `items`). At most 1.5 s; on a network error, timeout, 5xx or 429 it returns popular items (`fallback?`, no id), or no item when those fail too: hide the slot; on a 401 or 403 no item at once. A `context_item_id` the API would refuse (also an Array or a Hash, as `params[:id]` gives for `?id[]=a`) isn't sent: you get the same popular list and a log line, with no recommendation request. Any other failure (a bad request, a reply that isn't the API's) raises. |
|
|
79
93
|
| `identify(anon_id, user_id)` | At login: the visitor's history and shown items become the user's. The user's first restore from recapi then leaves that visitor's browsing out, so it doesn't count twice. |
|
|
80
94
|
| `popular(count:, tags_any:, tags_all:)` | Popular items, for pages without a user. On a network error, timeout, 5xx, 429, 401 or 403: an empty list and a log line. Other failures as in `recommend`. |
|
|
81
|
-
| `upsert_items(items, merge:)` | Creates or replaces items (hashes of `item_id`, `title`, `tags`, `metadata`…), 1,000 per request, retried like events. Returns how many were stored. With `merge: true` each item changes only the fields it sends and the others keep their stored values (a tags-only sync keeps the title and metadata); to clear
|
|
95
|
+
| `upsert_items(items, merge:)` | Creates or replaces items (hashes of `item_id`, `title`, `tags`, `metadata`…), 1,000 per request, retried like events. Returns how many were stored. With `merge: true` each item changes only the fields it sends and the others keep their stored values (a tags-only sync keeps the title and metadata), and `metadata` merges key by key: keys sent are set, the others kept, a key set to `nil` is removed (`"metadata" => { "old_price" => nil }`) and `"metadata" => nil` removes them all; to clear another field, replace the item. A bad item doesn't keep the others out: once every request is sent, `Recapi::RejectedItems` (an `invalid_request` `Recapi::Error`) is raised with `upserted` and `rejected`, `[index in items, message]` pairs. |
|
|
82
96
|
| `delete_user(user_id)` | Erases a user's events in recapi and their state in the store, retried like events. |
|
|
83
97
|
|
|
84
98
|
`Recapi::Client.new(api_key, base_url, store:, timeout:, flush_interval:,
|
|
@@ -124,6 +138,10 @@ so a visitor who never returns stays on disk (about 8 KB each): run
|
|
|
124
138
|
|
|
125
139
|
## Changes
|
|
126
140
|
|
|
141
|
+
- 2026-11-19: version 0.1.15. This page's links lead to recapi.io's public docs,
|
|
142
|
+
and the gem lists its homepage, docs and support address. No code change.
|
|
143
|
+
- 2026-11-15: version 0.1.14. `recommend_lists` asks a page's rows in one call,
|
|
144
|
+
billed as one recommendation.
|
|
127
145
|
- 2026-11-14: version 0.1.13. `upsert_items(items, merge: true)` changes only the
|
|
128
146
|
fields sent. A bad item no longer fails its batch of 1,000: the others are stored,
|
|
129
147
|
and `Recapi::RejectedItems` lists the refused ones once every request is sent.
|
|
@@ -142,10 +160,20 @@ so a visitor who never returns stays on disk (about 8 KB each): run
|
|
|
142
160
|
stalled each page for 5 s. The hook now starts with the sender, at the first
|
|
143
161
|
`track`.
|
|
144
162
|
|
|
163
|
+
## Errors and troubleshooting
|
|
164
|
+
|
|
165
|
+
`recommend` and `popular` answer an outage, a limit or a refused key (401, 403)
|
|
166
|
+
with popular items or an empty list and a log line; a bad request raises a
|
|
167
|
+
`Recapi::Error` (`code`, `status`), and a bad argument an `ArgumentError`.
|
|
168
|
+
|
|
169
|
+
- [Errors](https://recapi.io/docs/errors): each error code, its cause and fix.
|
|
170
|
+
- [Troubleshooting](https://recapi.io/docs/troubleshooting): no lists yet,
|
|
171
|
+
empty lists, only popular items, key errors.
|
|
172
|
+
|
|
145
173
|
## Development
|
|
146
174
|
|
|
147
|
-
|
|
148
|
-
test-sdk` does) against a fake API on a local socket. The autopilot
|
|
175
|
+
From the repository's root, `scripts/ruby.sh -w sdk/ruby/test/run.rb [filter]`
|
|
176
|
+
runs the tests (`make test-sdk` does) against a fake API on a local socket. The autopilot
|
|
149
177
|
containers have no Ruby: `scripts/ruby.sh` then fetches Debian's ruby3.1
|
|
150
178
|
once and runs it without RubyGems, so the tests have their own small runner
|
|
151
179
|
(`test/test_case.rb`), no minitest; `test/gem_test.rb` loads RubyGems itself
|
|
@@ -155,7 +183,7 @@ serves it (`server/internal/rubysdk`): any change to it needs a new
|
|
|
155
183
|
`Recapi::VERSION` and the line `go test ./internal/rubysdk` (in `server/`)
|
|
156
184
|
prints for `published.json`.
|
|
157
185
|
|
|
158
|
-
`RECAPI_KEY=rk_sec_…
|
|
159
|
-
|
|
186
|
+
`RECAPI_KEY=rk_sec_… scripts/ruby.sh sdk/ruby/sample.rb [item ids]` runs
|
|
187
|
+
`sample.rb` against staging (`RECAPI_URL` picks another API):
|
|
160
188
|
it tracks views for a new visitor, then prints their recommendations and the
|
|
161
189
|
popular items.
|
data/lib/recapi.rb
CHANGED
|
@@ -25,7 +25,7 @@ rescue LoadError
|
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
module Recapi
|
|
28
|
-
VERSION = "0.1.
|
|
28
|
+
VERSION = "0.1.15"
|
|
29
29
|
|
|
30
30
|
# Decayed user history, exactly as docs/history-spec.md (times in unix ms).
|
|
31
31
|
# A port of sdk/python's history.py, snapshot merging included.
|
|
@@ -423,6 +423,8 @@ module Recapi
|
|
|
423
423
|
CLICK_WINDOW_MS = 24 * 60 * 60 * 1000
|
|
424
424
|
# Shown items remembered per user.
|
|
425
425
|
MAX_SHOWN_ITEMS = 100
|
|
426
|
+
# What a list of recommend_lists may give.
|
|
427
|
+
LIST_FIELDS = %i[placement count tags_any tags_all exclude context_item_id discovery].freeze
|
|
426
428
|
PUBLIC_KEY_PREFIX = "rk_pub_"
|
|
427
429
|
# How long a recognised shared store keeps a user's state after its last
|
|
428
430
|
# write. Far beyond the 24 hours of click credit, and by then a score has
|
|
@@ -592,64 +594,29 @@ module Recapi
|
|
|
592
594
|
# a deploy.
|
|
593
595
|
def recommend(user_id: nil, anon_id: nil, count: 0, placement: nil, tags_any: nil, tags_all: nil,
|
|
594
596
|
exclude: nil, context_item_id: nil, discovery: nil)
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
"POST", "/v1/recommendations",
|
|
617
|
-
timeout: deadline - monotonic,
|
|
618
|
-
body: compact(
|
|
619
|
-
"user_id" => user_id, "anon_id" => anon_id, "placement" => placement,
|
|
620
|
-
"count" => count.to_i.zero? ? nil : count, "tags_any" => non_empty(tags_any),
|
|
621
|
-
"tags_all" => non_empty(tags_all), "exclude" => excluded, "context_item_id" => context_item_id,
|
|
622
|
-
"history" => history, "recent" => recent, "discovery" => discovery
|
|
623
|
-
)
|
|
624
|
-
)
|
|
625
|
-
rec_id, items = parse_recommendations(response)
|
|
626
|
-
rescue Error => e
|
|
627
|
-
raise unless spare_the_page?(e)
|
|
628
|
-
|
|
629
|
-
return fallback(e, count, excluded, context_item_id, tags_any, tags_all)
|
|
597
|
+
row = { placement: placement, count: count, tags_any: tags_any, tags_all: tags_all, exclude: exclude,
|
|
598
|
+
context_item_id: context_item_id, discovery: discovery }
|
|
599
|
+
recommend_rows(user_id, anon_id, nil, [row], false, false)[0]
|
|
600
|
+
end
|
|
601
|
+
|
|
602
|
+
# One Recommendations per entry of lists (hashes of recommend's placement,
|
|
603
|
+
# count, tags_any, tags_all, exclude, context_item_id and discovery), in
|
|
604
|
+
# order, from one call: a page's rows send the history once and are billed
|
|
605
|
+
# as one recommendation. exclude applies to every list. A list holds none
|
|
606
|
+
# of the items of the lists before it unless allow_repeats. It fails and
|
|
607
|
+
# falls back as recommend does: each list then holds popular items, asked
|
|
608
|
+
# list by list, and once popular fails the lists after it are empty.
|
|
609
|
+
def recommend_lists(lists:, user_id: nil, anon_id: nil, exclude: nil, allow_repeats: false)
|
|
610
|
+
raise ArgumentError, "at least one list is required" if lists.nil? || lists.empty?
|
|
611
|
+
|
|
612
|
+
rows = lists.map do |list|
|
|
613
|
+
row = list.to_h.transform_keys(&:to_sym)
|
|
614
|
+
unknown = row.keys - LIST_FIELDS
|
|
615
|
+
raise ArgumentError, "unknown list field: #{unknown.first}" unless unknown.empty?
|
|
616
|
+
|
|
617
|
+
row
|
|
630
618
|
end
|
|
631
|
-
|
|
632
|
-
unless key.nil?
|
|
633
|
-
with_locks(key) do
|
|
634
|
-
state = load(key)
|
|
635
|
-
items.each do |item|
|
|
636
|
-
state.shown.delete(item.item_id)
|
|
637
|
-
state.shown[item.item_id] = [rec_id, t]
|
|
638
|
-
end
|
|
639
|
-
state.shown.delete(state.shown.first[0]) while state.shown.size > MAX_SHOWN_ITEMS
|
|
640
|
-
# Only trusted when we sent nothing; merged, never replacing what
|
|
641
|
-
# was tracked while the request was in flight, and only once: a
|
|
642
|
-
# concurrent first call may have merged it already.
|
|
643
|
-
snapshot = response["history"]
|
|
644
|
-
done = state.restored && !state.history.empty?
|
|
645
|
-
if history.empty? && recent.empty? && snapshot.is_a?(Hash) && !done
|
|
646
|
-
state.history = state.history.merge_snapshot(History.from_snapshot(snapshot), t)
|
|
647
|
-
state.restored = true
|
|
648
|
-
end
|
|
649
|
-
save(key, state, t)
|
|
650
|
-
end
|
|
651
|
-
end
|
|
652
|
-
Recommendations.new(recommendation_id: rec_id, fallback: false, items: items)
|
|
619
|
+
recommend_rows(user_id, anon_id, exclude, rows, allow_repeats, true)
|
|
653
620
|
end
|
|
654
621
|
|
|
655
622
|
# Call at login: the visitor's history and shown items become the user's.
|
|
@@ -1026,10 +993,117 @@ module Recapi
|
|
|
1026
993
|
[401, 403].include?(error.status)
|
|
1027
994
|
end
|
|
1028
995
|
|
|
996
|
+
# recommend (one row, several false) and recommend_lists. shared is the
|
|
997
|
+
# call's own exclude, sent once for every row.
|
|
998
|
+
def recommend_rows(user_id, anon_id, shared, rows, repeats, several)
|
|
999
|
+
deadline = monotonic + recommend_timeout
|
|
1000
|
+
user_id, anon_id = check_ids(user_id: user_id, anon_id: anon_id)
|
|
1001
|
+
shared = shared&.map { |item| id_string(item) }
|
|
1002
|
+
rows = rows.map do |row|
|
|
1003
|
+
row.merge(context_item_id: id_string(row[:context_item_id]),
|
|
1004
|
+
exclude: row[:exclude]&.map { |item| id_string(item) })
|
|
1005
|
+
end
|
|
1006
|
+
# One list sends its exclude as the call's.
|
|
1007
|
+
shared, rows = rows[0][:exclude], [rows[0].merge(exclude: nil)] unless several
|
|
1008
|
+
key = key_for(user_id, anon_id)
|
|
1009
|
+
t = now_ms
|
|
1010
|
+
state = key.nil? ? UserState.new : load(key)
|
|
1011
|
+
bad = rows.index do |row|
|
|
1012
|
+
!(row[:context_item_id].nil? || row[:context_item_id] == "" || History.id?(row[:context_item_id]))
|
|
1013
|
+
end
|
|
1014
|
+
unless bad.nil?
|
|
1015
|
+
_, _, rejected = state.history.wire(t)
|
|
1016
|
+
# The message never quotes the id: a visitor may have written it. nil:
|
|
1017
|
+
# not skipped in the list either, as no item can have this id.
|
|
1018
|
+
rows[bad] = rows[bad].merge(context_item_id: nil)
|
|
1019
|
+
cause = Error.new("invalid_request", "context_item_id #{ID_RULE}")
|
|
1020
|
+
return fallbacks(cause, rows, with_rejected(shared, rejected), repeats)
|
|
1021
|
+
end
|
|
1022
|
+
if user_id && !state.restored && !state.history.empty? && !@api_key.start_with?(PUBLIC_KEY_PREFIX)
|
|
1023
|
+
state = restore(key, user_id, state, deadline, t)
|
|
1024
|
+
end
|
|
1025
|
+
history, recent, rejected = state.history.wire(t)
|
|
1026
|
+
excluded = with_rejected(shared, rejected)
|
|
1027
|
+
fields = if several
|
|
1028
|
+
placements = rows.map { |row| compact(row_fields(row, row[:exclude]).merge("discovery" => row[:discovery])) }
|
|
1029
|
+
{ "placements" => placements, "exclude" => excluded, "allow_repeats" => repeats ? true : nil }
|
|
1030
|
+
else
|
|
1031
|
+
row_fields(rows[0], excluded)
|
|
1032
|
+
end
|
|
1033
|
+
begin
|
|
1034
|
+
response = request(
|
|
1035
|
+
"POST", "/v1/recommendations",
|
|
1036
|
+
timeout: deadline - monotonic,
|
|
1037
|
+
body: compact(
|
|
1038
|
+
"user_id" => user_id, "anon_id" => anon_id, **fields, "history" => history, "recent" => recent,
|
|
1039
|
+
"discovery" => several ? nil : rows[0][:discovery]
|
|
1040
|
+
)
|
|
1041
|
+
)
|
|
1042
|
+
lists = several ? (response["lists"] if response.is_a?(Hash)) : [response]
|
|
1043
|
+
unless lists.is_a?(Array) && lists.size == rows.size
|
|
1044
|
+
raise Error.new("invalid_response", "malformed recommendations response")
|
|
1045
|
+
end
|
|
1046
|
+
|
|
1047
|
+
results = lists.map { |list| parse_recommendations(list) }
|
|
1048
|
+
rescue Error => e
|
|
1049
|
+
raise unless spare_the_page?(e)
|
|
1050
|
+
|
|
1051
|
+
return fallbacks(e, rows, excluded, repeats)
|
|
1052
|
+
end
|
|
1053
|
+
|
|
1054
|
+
unless key.nil?
|
|
1055
|
+
with_locks(key) do
|
|
1056
|
+
state = load(key)
|
|
1057
|
+
results.each do |rec_id, items|
|
|
1058
|
+
items.each do |item|
|
|
1059
|
+
state.shown.delete(item.item_id)
|
|
1060
|
+
state.shown[item.item_id] = [rec_id, t]
|
|
1061
|
+
end
|
|
1062
|
+
end
|
|
1063
|
+
state.shown.delete(state.shown.first[0]) while state.shown.size > MAX_SHOWN_ITEMS
|
|
1064
|
+
# Only trusted when we sent nothing; merged, never replacing what
|
|
1065
|
+
# was tracked while the request was in flight, and only once: a
|
|
1066
|
+
# concurrent first call may have merged it already.
|
|
1067
|
+
snapshot = response["history"]
|
|
1068
|
+
done = state.restored && !state.history.empty?
|
|
1069
|
+
if history.empty? && recent.empty? && snapshot.is_a?(Hash) && !done
|
|
1070
|
+
state.history = state.history.merge_snapshot(History.from_snapshot(snapshot), t)
|
|
1071
|
+
state.restored = true
|
|
1072
|
+
end
|
|
1073
|
+
save(key, state, t)
|
|
1074
|
+
end
|
|
1075
|
+
end
|
|
1076
|
+
results.map { |rec_id, items| Recommendations.new(recommendation_id: rec_id, fallback: false, items: items) }
|
|
1077
|
+
end
|
|
1078
|
+
|
|
1079
|
+
# A list's own fields: the request itself for one list, a placements entry for several.
|
|
1080
|
+
def row_fields(row, exclude)
|
|
1081
|
+
{ "placement" => row[:placement], "count" => row[:count].to_i.zero? ? nil : row[:count],
|
|
1082
|
+
"tags_any" => non_empty(row[:tags_any]), "tags_all" => non_empty(row[:tags_all]), "exclude" => exclude,
|
|
1083
|
+
"context_item_id" => row[:context_item_id] }
|
|
1084
|
+
end
|
|
1085
|
+
|
|
1086
|
+
# Each row of a failed call answered with popular items, a call per row:
|
|
1087
|
+
# excluded and the row's own exclude are skipped, and so, unless repeats,
|
|
1088
|
+
# are the items of the rows before it. Once popular fails (or the key is
|
|
1089
|
+
# refused), the rows after it are empty without asking.
|
|
1090
|
+
def fallbacks(error, rows, excluded, repeats)
|
|
1091
|
+
shown = []
|
|
1092
|
+
failed = false
|
|
1093
|
+
rows.map do |row|
|
|
1094
|
+
next Recommendations.new(recommendation_id: nil, fallback: true, items: []) if failed
|
|
1095
|
+
|
|
1096
|
+
result, failed = fallback(error, row[:count], (excluded || []) + (row[:exclude] || []) + shown,
|
|
1097
|
+
row[:context_item_id], row[:tags_any], row[:tags_all])
|
|
1098
|
+
shown.concat(result.items.map(&:item_id)) unless repeats
|
|
1099
|
+
result
|
|
1100
|
+
end
|
|
1101
|
+
end
|
|
1102
|
+
|
|
1029
1103
|
def fallback(error, count, excluded, context_item_id, tags_any, tags_all)
|
|
1030
1104
|
if key_refused?(error)
|
|
1031
1105
|
log_list(error, "recapi: recommendations refused, served no items: #{error.code}: #{error.message}")
|
|
1032
|
-
return Recommendations.new(recommendation_id: nil, fallback: true, items: [])
|
|
1106
|
+
return Recommendations.new(recommendation_id: nil, fallback: true, items: []), true
|
|
1033
1107
|
end
|
|
1034
1108
|
# The requested length without the excluded items, so a few more are
|
|
1035
1109
|
# asked for. 0 is the recommendations default; popular refuses it.
|
|
@@ -1043,11 +1117,11 @@ module Recapi
|
|
|
1043
1117
|
# can hide beats an exception that fails the whole page.
|
|
1044
1118
|
log_list(error, "recapi: recommendations failed (#{error.code}: #{error.message}), popular too, " \
|
|
1045
1119
|
"served no items: #{e.code}: #{e.message}")
|
|
1046
|
-
return Recommendations.new(recommendation_id: nil, fallback: true, items: [])
|
|
1120
|
+
return Recommendations.new(recommendation_id: nil, fallback: true, items: []), true
|
|
1047
1121
|
end
|
|
1048
1122
|
log_list(error, "recapi: recommendations failed, served popular items: #{error.code}: #{error.message}")
|
|
1049
1123
|
items = popular.reject { |item| skip.key?(item.item_id) }.first(n)
|
|
1050
|
-
Recommendations.new(recommendation_id: nil, fallback: true, items: items)
|
|
1124
|
+
[Recommendations.new(recommendation_id: nil, fallback: true, items: items), false]
|
|
1051
1125
|
end
|
|
1052
1126
|
|
|
1053
1127
|
# Merges recapi's stored history into a local one that lacks it (a fresh
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: recapi
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.15
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- recapi
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2026-11-
|
|
11
|
+
date: 2026-11-19 00:00:00.000000000 Z
|
|
12
12
|
dependencies: []
|
|
13
13
|
description: 'Ruby client for the recapi recommendation API: per-user history, event
|
|
14
14
|
batching, retries, popular fallback. Standard library only.'
|
|
@@ -23,7 +23,10 @@ files:
|
|
|
23
23
|
homepage: https://recapi.io
|
|
24
24
|
licenses:
|
|
25
25
|
- MIT
|
|
26
|
-
metadata:
|
|
26
|
+
metadata:
|
|
27
|
+
homepage_uri: https://recapi.io/docs
|
|
28
|
+
documentation_uri: https://recapi.io/docs
|
|
29
|
+
bug_tracker_uri: https://recapi.io/contact
|
|
27
30
|
post_install_message:
|
|
28
31
|
rdoc_options: []
|
|
29
32
|
require_paths:
|