showroom 0.3.1 → 0.3.2

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: 0a879aafd609e03c490716579f3051e97ca92108252ac53cf63256db2ccb8ae5
4
- data.tar.gz: fbfea4d3ce7580bfbb131a1643e0000f6d7c4a8a7865289337cfabcf8ee0a7fe
3
+ metadata.gz: 0cc1a3b85b751731df26df449ba38e35f6cbfd8a7d59391b3087948c6e8af2a4
4
+ data.tar.gz: 2b65bfa5e0032470cbd4eacbacc801f6c3b5849db5a161d9e91f5cd36e435e12
5
5
  SHA512:
6
- metadata.gz: c523a5ff93f4931a403c9b59a6104e0c014d17742977a7c3c786f8276f7892f2ff751e96d18643463f9efca5fae3acbb0c36213325675896c7a24a67ea45f7f3
7
- data.tar.gz: 858be74b2a6d8fa7429cd014e04a332699cf5c99edd7afc2485617d95b5e3e43d897a8809bf7f419297d93b55b41cdd3a150348d8ae1805134a3ceec89836df8
6
+ metadata.gz: 6c0d70335325cf5e4c98c89f9ba2683405503a5ce3cf4c340842f4020f436fe454e2e8e21197943e75b331cffbe2092bc420f07b0797895809c90aefb9aecaa8
7
+ data.tar.gz: 3c2a0a4709b830f694e6664956999a3618ed81de66c618a1d81656034cb74d66ea52d772317006e594d0e77feb2ef737b4469037ae5f9524bbcb8b8cf5a562e7
data/CHANGELOG.md CHANGED
@@ -7,6 +7,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [0.3.2] - 2026-04-25
11
+
12
+ ### Added
13
+
14
+ - `Search::ProductSuggestion#url` — returns the canonical storefront URL (`/products/:handle`), matching the existing `Product#url` API
15
+ - `Search::CollectionSuggestion#url` — returns the canonical storefront URL (`/collections/:handle`), matching the existing `Collection#url` API
16
+ - `Search::Result.new` now accepts a `client:` keyword and propagates it onto every suggestion it builds, so suggestions can resolve their store-specific URL without falling back to the global client
17
+
10
18
  ## [0.3.1] - 2026-04-25
11
19
 
12
20
  ### Changed
@@ -93,7 +93,7 @@ module Showroom
93
93
  query['resources[type]'] = types.join(',') unless types.empty?
94
94
  query.merge!(params)
95
95
  raw = get('/search/suggest.json', query)
96
- Search::Result.new(raw.dig('resources', 'results') || {})
96
+ Search::Result.new(raw.dig('resources', 'results') || {}, client: self)
97
97
  end
98
98
  end
99
99
  end
@@ -4,6 +4,6 @@ module Showroom
4
4
  # Internal gem infrastructure (configuration, connection, errors, versioning).
5
5
  module Core
6
6
  # Current gem version.
7
- VERSION = '0.3.1'
7
+ VERSION = '0.3.2'
8
8
  end
9
9
  end
@@ -14,6 +14,14 @@ module Showroom
14
14
  def self.complete_model_class
15
15
  Collection
16
16
  end
17
+
18
+ # Returns the canonical storefront URL for this collection suggestion.
19
+ #
20
+ # @return [String]
21
+ def url
22
+ conn = client || Showroom.client
23
+ "#{conn.base_url}/collections/#{handle}"
24
+ end
17
25
  end
18
26
  end
19
27
  end
@@ -15,6 +15,14 @@ module Showroom
15
15
  def self.complete_model_class
16
16
  Product
17
17
  end
18
+
19
+ # Returns the canonical storefront URL for this product suggestion.
20
+ #
21
+ # @return [String]
22
+ def url
23
+ conn = client || Showroom.client
24
+ "#{conn.base_url}/products/#{handle}"
25
+ end
18
26
  end
19
27
  end
20
28
  end
@@ -12,8 +12,10 @@ module Showroom
12
12
  # result.queries # => [Array<QuerySuggestion>]
13
13
  class Result
14
14
  # @param results_hash [Hash] the +resources.results+ hash from the API response
15
- def initialize(results_hash)
15
+ # @param client [Showroom::Client, nil] the client to propagate onto suggestions
16
+ def initialize(results_hash, client: nil)
16
17
  @data = results_hash
18
+ @client = client
17
19
  end
18
20
 
19
21
  PRODUCT_ORDER_ATTRS = %w[id title handle price].freeze
@@ -28,7 +30,7 @@ module Showroom
28
30
  # @raise [ArgumentError] when an unsupported order attribute is given
29
31
  def products(order: nil)
30
32
  validate_order!(order)
31
- suggestions = @data.fetch('products', []).map { |h| ProductSuggestion.new(h) }
33
+ suggestions = build_suggestions('products', ProductSuggestion)
32
34
  return suggestions unless order
33
35
 
34
36
  sort_product_suggestions(suggestions, order)
@@ -38,32 +40,36 @@ module Showroom
38
40
  #
39
41
  # @return [Array<CollectionSuggestion>]
40
42
  def collections
41
- @data.fetch('collections', []).map { |h| CollectionSuggestion.new(h) }
43
+ build_suggestions('collections', CollectionSuggestion)
42
44
  end
43
45
 
44
46
  # Returns page suggestions from the search result.
45
47
  #
46
48
  # @return [Array<PageSuggestion>]
47
49
  def pages
48
- @data.fetch('pages', []).map { |h| PageSuggestion.new(h) }
50
+ build_suggestions('pages', PageSuggestion)
49
51
  end
50
52
 
51
53
  # Returns article suggestions from the search result.
52
54
  #
53
55
  # @return [Array<ArticleSuggestion>]
54
56
  def articles
55
- @data.fetch('articles', []).map { |h| ArticleSuggestion.new(h) }
57
+ build_suggestions('articles', ArticleSuggestion)
56
58
  end
57
59
 
58
60
  # Returns query suggestions from the search result.
59
61
  #
60
62
  # @return [Array<QuerySuggestion>]
61
63
  def queries
62
- @data.fetch('queries', []).map { |h| QuerySuggestion.new(h) }
64
+ build_suggestions('queries', QuerySuggestion)
63
65
  end
64
66
 
65
67
  private
66
68
 
69
+ def build_suggestions(key, klass)
70
+ @data.fetch(key, []).map { |h| klass.new(h).tap { |s| s.client = @client } }
71
+ end
72
+
67
73
  def validate_order!(order)
68
74
  return unless order
69
75
  return if PRODUCT_ORDER_ATTRS.include?(order.to_s)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: showroom
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 01max