recapi 0.1.14 → 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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +24 -14
  3. data/lib/recapi.rb +1 -1
  4. metadata +6 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c186cf0df3db7d2776e851d0f4658a85808efaa8502374b95affe38142c99cd5
4
- data.tar.gz: b14927279881bd3799bb8caed8203c7c9389869f999eaf980983b847b67e7ed8
3
+ metadata.gz: 955bf1ce3f0c03191af7c2292d51f26a8c27ecd5eabd92ae8fb0b95e21d36c07
4
+ data.tar.gz: f5ce6c0d310e8a307cf1a8db3563d0184a4c6e00cc41c05575c17ba690f78580
5
5
  SHA512:
6
- metadata.gz: 0b42e390927a5e6b3d9d6bd85df4d45d0e8ce59081ae64a215f2174da1da42e45ed08855bdb47a41f3bec3c5e1f778a9ef51413f602d69afcfb733295c609a9c
7
- data.tar.gz: 29fb702a44c2eed7dbda2c4a374c9919acc0874d7fe6482150189b5099958c76594c3f56c002f575dd74e8af24d75388f0b86fbe28db741442c3d8c7b40a69a0
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 [Python](../python/README.md) and [Go](../go/README.md) libraries,
9
- it keeps each user's decayed **history**
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 the shared vectors in [`spec/`](../../spec).
14
+ passes recapi's shared test vectors.
16
15
 
17
16
  ## Install
18
17
 
19
- The library is the gem `recapi` on RubyGems (production releases publish it:
20
- [docs/deployment.md](../../docs/deployment.md#publishing-the-ruby-library)):
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.14.rb
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,7 +51,7 @@ 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.md, "Reason codes"), and show none for a code you don't map.
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
  ```
@@ -94,7 +92,7 @@ and a log line.
94
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. |
95
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. |
96
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`. |
97
- | `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 a 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. |
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. |
98
96
  | `delete_user(user_id)` | Erases a user's events in recapi and their state in the store, retried like events. |
99
97
 
100
98
  `Recapi::Client.new(api_key, base_url, store:, timeout:, flush_interval:,
@@ -140,6 +138,8 @@ so a visitor who never returns stays on disk (about 8 KB each): run
140
138
 
141
139
  ## Changes
142
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
143
  - 2026-11-15: version 0.1.14. `recommend_lists` asks a page's rows in one call,
144
144
  billed as one recommendation.
145
145
  - 2026-11-14: version 0.1.13. `upsert_items(items, merge: true)` changes only the
@@ -160,10 +160,20 @@ so a visitor who never returns stays on disk (about 8 KB each): run
160
160
  stalled each page for 5 s. The hook now starts with the sender, at the first
161
161
  `track`.
162
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
+
163
173
  ## Development
164
174
 
165
- `../../scripts/ruby.sh -w test/run.rb [filter]` runs the tests (`make
166
- 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
167
177
  containers have no Ruby: `scripts/ruby.sh` then fetches Debian's ruby3.1
168
178
  once and runs it without RubyGems, so the tests have their own small runner
169
179
  (`test/test_case.rb`), no minitest; `test/gem_test.rb` loads RubyGems itself
@@ -173,7 +183,7 @@ serves it (`server/internal/rubysdk`): any change to it needs a new
173
183
  `Recapi::VERSION` and the line `go test ./internal/rubysdk` (in `server/`)
174
184
  prints for `published.json`.
175
185
 
176
- `RECAPI_KEY=rk_sec_… ../../scripts/ruby.sh sample.rb [item ids]` runs
177
- [`sample.rb`](sample.rb) against staging (`RECAPI_URL` picks another API):
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):
178
188
  it tracks views for a new visitor, then prints their recommendations and the
179
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.14"
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.
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.14
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-15 00:00:00.000000000 Z
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: