sink-cool 0.2.0 → 0.2.1
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 +7 -1
- data/README.md +5 -1
- data/lib/sink/client.rb +7 -5
- data/lib/sink/link.rb +6 -3
- data/lib/sink/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 117661123578a6b91926715b23db4f780820b7cfe1f420e79a1afc37c962a01b
|
|
4
|
+
data.tar.gz: eb5bc2317aa7d9b6d973d811d0ed5ca938ddee0f6c445aadfed53fcfb8b34380
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ff112350ba6829bc44186218dd35cedf7f67e71fd8ae9ec3dd41213a56b35b038129e879f0f7f3230740629f42cc6725e003a7acfd71c71c89ee3f3408505cf0
|
|
7
|
+
data.tar.gz: c7d2cebbe780ea928b9e022caa8d24644f3b6525f063e24443d50ecf99e89a8a3e1f29a41b06dc4fe91b67b90224708c1fead5855e4f52f298c8fba582696a91
|
data/CHANGELOG.md
CHANGED
|
@@ -4,7 +4,13 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
-
## 0.2.
|
|
7
|
+
## 0.2.1 - 2026-07-25
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- Derive `Link#short_link` from `base_url` and the slug on the read endpoints, which the API only returns for writes. A `shortLink` in the response still wins.
|
|
12
|
+
|
|
13
|
+
## 0.2.0 - 2026-07-25
|
|
8
14
|
|
|
9
15
|
### Added
|
|
10
16
|
|
data/README.md
CHANGED
|
@@ -108,7 +108,11 @@ link.to_h # => { slug: "example", url: "https://example.com", .
|
|
|
108
108
|
link[:any_future_field] # raw access to fields without a reader
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
-
`
|
|
111
|
+
The API only returns `shortLink` for the write endpoints, where it builds the
|
|
112
|
+
value from the protocol and host of the request. `short_link` is therefore
|
|
113
|
+
derived from `base_url` and the slug for `link`, `links`, and `search_links`,
|
|
114
|
+
which matches the API as long as `base_url` is the Worker domain that serves the
|
|
115
|
+
short links.
|
|
112
116
|
|
|
113
117
|
`upsert_link` never overwrites an existing slug, so check which happened:
|
|
114
118
|
|
data/lib/sink/client.rb
CHANGED
|
@@ -35,15 +35,15 @@ module Sink
|
|
|
35
35
|
def verify = Keys.underscore_keys(request(:get, "/api/verify") || {})
|
|
36
36
|
|
|
37
37
|
def create_link(url:, **attributes)
|
|
38
|
-
|
|
38
|
+
build_link(request(:post, "/api/link/create", body: link_payload(attributes.merge(url: url))))
|
|
39
39
|
end
|
|
40
40
|
|
|
41
41
|
def edit_link(url:, slug:, **attributes)
|
|
42
|
-
|
|
42
|
+
build_link(request(:put, "/api/link/edit", body: link_payload(attributes.merge(url: url, slug: slug))))
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def upsert_link(url:, **attributes)
|
|
46
|
-
|
|
46
|
+
build_link(request(:post, "/api/link/upsert", body: link_payload(attributes.merge(url: url))))
|
|
47
47
|
end
|
|
48
48
|
|
|
49
49
|
def delete_link(slug)
|
|
@@ -51,7 +51,7 @@ module Sink
|
|
|
51
51
|
true
|
|
52
52
|
end
|
|
53
53
|
|
|
54
|
-
def link(slug) =
|
|
54
|
+
def link(slug) = build_link(request(:get, "/api/link/query", query: { slug: slug }))
|
|
55
55
|
|
|
56
56
|
def links(limit: nil, cursor: nil, sort: nil, tag: nil, status: nil)
|
|
57
57
|
body = request(:get, "/api/link/list", query: {
|
|
@@ -114,7 +114,9 @@ module Sink
|
|
|
114
114
|
raise ArgumentError, "expires_at must be a Time or a unix timestamp"
|
|
115
115
|
end
|
|
116
116
|
|
|
117
|
-
def
|
|
117
|
+
def build_link(body) = Link.from_response(body, base_url: @base_url)
|
|
118
|
+
|
|
119
|
+
def link_page(body) = page(body, "links") { |link| build_link(link) }
|
|
118
120
|
|
|
119
121
|
def page(body, key, &build)
|
|
120
122
|
records, cursor, complete = case body
|
data/lib/sink/link.rb
CHANGED
|
@@ -10,15 +10,18 @@ module Sink
|
|
|
10
10
|
|
|
11
11
|
attr_reader :attributes
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
# The API only builds `shortLink` for write endpoints, from the protocol and
|
|
14
|
+
# host of the request, so `base_url` reproduces it for the read endpoints.
|
|
15
|
+
def self.from_response(body, base_url: nil)
|
|
14
16
|
return nil unless body.is_a?(Hash)
|
|
15
17
|
|
|
16
18
|
link = body["link"].is_a?(Hash) ? body["link"] : body
|
|
17
19
|
attributes = Keys.underscore_keys(link)
|
|
18
|
-
attributes[:short_link] = body["shortLink"] if body.key?("shortLink")
|
|
19
20
|
attributes[:status] = body["status"] if body.key?("status")
|
|
21
|
+
attributes[:short_link] = body["shortLink"] ||
|
|
22
|
+
(base_url && attributes[:slug] && "#{base_url}/#{attributes[:slug]}")
|
|
20
23
|
|
|
21
|
-
new(attributes)
|
|
24
|
+
new(attributes.compact)
|
|
22
25
|
end
|
|
23
26
|
|
|
24
27
|
def initialize(attributes)
|
data/lib/sink/version.rb
CHANGED