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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2a7189eda4d5a284c80c198aeb86cfffb50a055a8ad3c9e2eec91b2dd9560f1c
4
- data.tar.gz: 5cbd0afad6e397979edeeb86f80d29f7bb85d17474163d5ffc60283a527b32ed
3
+ metadata.gz: 117661123578a6b91926715b23db4f780820b7cfe1f420e79a1afc37c962a01b
4
+ data.tar.gz: eb5bc2317aa7d9b6d973d811d0ed5ca938ddee0f6c445aadfed53fcfb8b34380
5
5
  SHA512:
6
- metadata.gz: 4ba8fd2a4f777dcbc73d70692e920627500fd6beea73fa9a1034fc4d714e97594118b254fd8d877f8c349755cedb98fcd7dbf15995e40bee0ee6b73fdd7aab92
7
- data.tar.gz: f195221d617d7135ac222079426989d48ebaa58ea98c83b0b77abc7dadc79b39d6de6717bc9692ed65aedfa1f3686ad6f99ac9f84c60c395656617005f4a7682
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.0 - 2026-07-24
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
- `link(slug)` responses carry no short URL, so `short_link` is `nil` there.
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
- Link.from_response(request(:post, "/api/link/create", body: link_payload(attributes.merge(url: url))))
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
- Link.from_response(request(:put, "/api/link/edit", body: link_payload(attributes.merge(url: url, slug: slug))))
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
- Link.from_response(request(:post, "/api/link/upsert", body: link_payload(attributes.merge(url: url))))
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) = Link.from_response(request(:get, "/api/link/query", query: { slug: 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 link_page(body) = page(body, "links") { |link| Link.from_response(link) }
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
- def self.from_response(body)
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Sink
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sink-cool
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sink Ruby contributors