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 +4 -4
- data/CHANGELOG.md +8 -0
- data/lib/showroom/client.rb +1 -1
- data/lib/showroom/core/version.rb +1 -1
- data/lib/showroom/models/search/collection_suggestion.rb +8 -0
- data/lib/showroom/models/search/product_suggestion.rb +8 -0
- data/lib/showroom/models/search/result.rb +12 -6
- 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: 0cc1a3b85b751731df26df449ba38e35f6cbfd8a7d59391b3087948c6e8af2a4
|
|
4
|
+
data.tar.gz: 2b65bfa5e0032470cbd4eacbacc801f6c3b5849db5a161d9e91f5cd36e435e12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
|
data/lib/showroom/client.rb
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
|
|
@@ -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
|
-
|
|
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 =
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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)
|