showroom 0.3.0 → 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: 7805a1b540c985ccaa80393080ce970f09764990bd9a7a8471c3e3cd092827f2
4
- data.tar.gz: 261bcdbd50855a4761ff0b18f5b517c7acd1c533a835d1121914b7b23fc2db73
3
+ metadata.gz: 0cc1a3b85b751731df26df449ba38e35f6cbfd8a7d59391b3087948c6e8af2a4
4
+ data.tar.gz: 2b65bfa5e0032470cbd4eacbacc801f6c3b5849db5a161d9e91f5cd36e435e12
5
5
  SHA512:
6
- metadata.gz: 45cd85604c8244fb98f7d4c2d9950b486f2e05fb95ce72e334ef1b927c0578496f69745b5651ca32426cc2fe168548072e38de2c02cf27c3b8fa134561ab145e
7
- data.tar.gz: 1c2be840665a8c1dac605529d09218b7eb4f8663a07b0854548ae5dcf113296dc5e3921cf4154075e526431dc14b7a71ca708f0c4aec6486ece25c9a0c4ebbba
6
+ metadata.gz: 6c0d70335325cf5e4c98c89f9ba2683405503a5ce3cf4c340842f4020f436fe454e2e8e21197943e75b331cffbe2092bc420f07b0797895809c90aefb9aecaa8
7
+ data.tar.gz: 3c2a0a4709b830f694e6664956999a3618ed81de66c618a1d81656034cb74d66ea52d772317006e594d0e77feb2ef737b4469037ae5f9524bbcb8b8cf5a562e7
data/CHANGELOG.md CHANGED
@@ -7,6 +7,28 @@ 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
+
18
+ ## [0.3.1] - 2026-04-25
19
+
20
+ ### Changed
21
+
22
+ - `ProductVariant#available?` now returns `nil` (instead of `false`) when the source payload omits the `available` key — some Shopify storefronts do not expose it on `/products/{handle}.json`, so distinguishing "unknown" from "unavailable" is necessary to avoid silently reporting every variant as out of stock
23
+ - `Product#available?` now returns `true | false | nil`: it honours a top-level `available` key when present, otherwise aggregates variants — any `true` → `true`, all `false` → `false`, otherwise `nil`
24
+
25
+ ### Added
26
+
27
+ - `ProductVariant#availability_known?` — `true` when the payload included an `available` key
28
+ - `Product#availability_known?` — `true` when product-level availability can be determined from a top-level key or any variant
29
+
30
+ ## [0.3.0] - 2026-04-24
31
+
10
32
  ### Added
11
33
 
12
34
  - `Product#similar` — searches for products similar to the current one via the search suggest endpoint; strips variant SKU fragments from the handle before querying, and falls back to a title search when the stripped-handle query returns no results
data/README.md CHANGED
@@ -75,8 +75,9 @@ product = Showroom::Product.find('lorem-road-bike')
75
75
  product.title # => "Lorem Road Bike"
76
76
  product.handle # => "lorem-road-bike"
77
77
  product.vendor # => "Lorem Cycles"
78
- product.available? # => true (any variant in stock)
79
- product.price # => "749.00" (lowest variant price)
78
+ product.available? # => true | false | nil (nil when no variant exposes availability)
79
+ product.availability_known? # => true when availability can be determined
80
+ product.price # => "749.00" (lowest variant price)
80
81
  product.price_range # => "749.00–899.00"
81
82
  product.prices # => ["749.00", "899.00"] (unique prices from all variants)
82
83
  product.url # => "https://acme.myshopify.com/products/lorem-road-bike"
@@ -90,7 +91,7 @@ product.similar.first.load # => Showroom::Product (full record)
90
91
 
91
92
  # Variants
92
93
  product.variants.each do |v|
93
- puts "#{v.title} #{v.price} #{v.compare_at_price} on_sale=#{v.on_sale?} available=#{v.available?}"
94
+ puts "#{v.title} #{v.price} #{v.compare_at_price} on_sale=#{v.on_sale?} available=#{v.available?} availability_known=#{v.availability_known?}"
94
95
  end
95
96
 
96
97
  # All pages — returns an Enumerator
@@ -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.0'
7
+ VERSION = '0.3.2'
8
8
  end
9
9
  end
@@ -125,11 +125,32 @@ module Showroom
125
125
  prices.length == 1 ? prices.first : "#{prices.min} - #{prices.max}"
126
126
  end
127
127
 
128
- # Returns true when at least one variant is available for purchase.
128
+ # Returns true when the product is available for purchase, false when it
129
+ # is not, or nil when availability cannot be determined from the payload.
129
130
  #
130
- # @return [Boolean]
131
+ # If the response carries a top-level +available+ key, that value wins.
132
+ # Otherwise the result is aggregated from variants:
133
+ # any variant +true+ → +true+; all variants +false+ → +false+;
134
+ # otherwise (mix of +false+ and unknowns, or all unknown) → +nil+.
135
+ #
136
+ # @return [Boolean, nil]
131
137
  def available?
132
- variants.any?(&:available?)
138
+ return @attrs['available'] == true if @attrs.key?('available')
139
+
140
+ states = variants.map(&:available?)
141
+ return true if states.include?(true)
142
+ return false if states.all? { |s| s == false }
143
+
144
+ nil # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
145
+ end
146
+
147
+ # Returns true when product-level availability can be determined,
148
+ # either from a top-level +available+ key or from at least one variant
149
+ # whose own availability is known.
150
+ #
151
+ # @return [Boolean]
152
+ def availability_known?
153
+ @attrs.key?('available') || variants.any?(&:availability_known?)
133
154
  end
134
155
 
135
156
  # Returns the first image, or nil if there are no images.
@@ -10,13 +10,26 @@ module Showroom
10
10
  class ProductVariant < Resource
11
11
  main_attrs :id, :title, :price, :compare_at_price, :sku
12
12
 
13
- # Returns true when the variant is available for purchase.
13
+ # Returns true when the variant is available for purchase, false when
14
+ # explicitly unavailable, or nil when the source payload omits the
15
+ # +available+ key (some Shopify storefronts do not expose it on
16
+ # +/products/{handle}.json+).
14
17
  #
15
- # @return [Boolean]
18
+ # @return [Boolean, nil]
16
19
  def available?
20
+ return nil unless availability_known? # rubocop:disable Style/ReturnNilInPredicateMethodDefinition
21
+
17
22
  @attrs['available'] == true
18
23
  end
19
24
 
25
+ # Returns true when the source payload included an +available+ key,
26
+ # making {#available?} authoritative.
27
+ #
28
+ # @return [Boolean]
29
+ def availability_known?
30
+ @attrs.key?('available')
31
+ end
32
+
20
33
  # Returns true when +compare_at_price+ is present and greater than +price+.
21
34
  #
22
35
  # @return [Boolean]
@@ -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.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - 01max