showroom 0.1.0 → 0.2.0
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 +18 -0
- data/README.md +36 -2
- data/lib/showroom/client.rb +8 -4
- data/lib/showroom/core/connection.rb +7 -0
- data/lib/showroom/core/version.rb +1 -1
- data/lib/showroom/models/collection.rb +12 -3
- data/lib/showroom/models/product.rb +32 -0
- data/lib/showroom/models/product_variant.rb +1 -1
- data/lib/showroom/models/resource.rb +3 -0
- 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: 022d47e06d5e246f2124d3297c029aadaa39e7c9004136590e3516d27390f7d7
|
|
4
|
+
data.tar.gz: ad735cba032078f6de522a012855aedbe1dcfdfb6f25104a62323f5428618331
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 829309cb01db6bfbaa0a7d0134c038e266f14340259058e16139b46a4431f44993a1720f81f32a36a6b4306b96b64664eed0fc9c4ba274f3f7095d6937515634
|
|
7
|
+
data.tar.gz: 96a9bcfcf7fe25a4950c49df8181ebaf77928e43e88f94630a914dbc3c082e4edd12e94f6db349af2723801a5b05256b0891510de14e7567bee59c4dd9d37813
|
data/CHANGELOG.md
CHANGED
|
@@ -7,6 +7,24 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
|
7
7
|
|
|
8
8
|
## [Unreleased]
|
|
9
9
|
|
|
10
|
+
## [0.2.0] - 2026-04-20
|
|
11
|
+
|
|
12
|
+
### Added
|
|
13
|
+
|
|
14
|
+
- `Product#url` — returns the canonical storefront URL for a product (`/products/:handle`)
|
|
15
|
+
- `Product#prices` — deduplicated list of raw price strings across all variants
|
|
16
|
+
- `Product#main_image` — returns the image with `position: 1`, distinct from `featured_image` (which returns `images.first`)
|
|
17
|
+
- `Collection#url` — returns the canonical storefront URL for a collection (`/collections/:handle`)
|
|
18
|
+
- `Client#base_url` — exposes the resolved HTTPS base URL for the configured store
|
|
19
|
+
- `Resource#client` accessor — models now carry a reference to the client that fetched them
|
|
20
|
+
- Ruby 4.0 added to CI matrix
|
|
21
|
+
- Dependabot configuration for automated dependency updates
|
|
22
|
+
|
|
23
|
+
### Changed
|
|
24
|
+
|
|
25
|
+
- All models returned by `Client` methods (`products`, `product`, `collections`, `collection`) now have their `client` attribute set automatically, enabling instance-scoped operations without relying on the global `Showroom.client`
|
|
26
|
+
- `Collection#products` uses the instance client when available, falling back to the global client
|
|
27
|
+
|
|
10
28
|
## [0.1.0] - 2026-04-11
|
|
11
29
|
|
|
12
30
|
### Added
|
data/README.md
CHANGED
|
@@ -55,6 +55,13 @@ globo = Showroom::Client.new(store: 'globo.myshopify.com')
|
|
|
55
55
|
|
|
56
56
|
acme.products(limit: 5).map(&:title)
|
|
57
57
|
globo.product('road-bike').price
|
|
58
|
+
|
|
59
|
+
# Models remember which client fetched them
|
|
60
|
+
product = acme.product('lorem-road-bike')
|
|
61
|
+
product.url # => "https://acme.myshopify.com/products/lorem-road-bike"
|
|
62
|
+
|
|
63
|
+
# base_url is available on any client
|
|
64
|
+
acme.base_url # => "https://acme.myshopify.com"
|
|
58
65
|
```
|
|
59
66
|
|
|
60
67
|
## Products
|
|
@@ -71,11 +78,14 @@ product.vendor # => "Lorem Cycles"
|
|
|
71
78
|
product.available? # => true (any variant in stock)
|
|
72
79
|
product.price # => "749.00" (lowest variant price)
|
|
73
80
|
product.price_range # => "749.00–899.00"
|
|
74
|
-
product.
|
|
81
|
+
product.prices # => ["749.00", "899.00"] (unique prices from all variants)
|
|
82
|
+
product.url # => "https://acme.myshopify.com/products/lorem-road-bike"
|
|
83
|
+
product.featured_image # => #<Showroom::ProductImage ...> (first image)
|
|
84
|
+
product.main_image # => #<Showroom::ProductImage ...> (image with position 1)
|
|
75
85
|
|
|
76
86
|
# Variants
|
|
77
87
|
product.variants.each do |v|
|
|
78
|
-
puts "#{v.title} #{v.price} on_sale=#{v.on_sale?} available=#{v.available?}"
|
|
88
|
+
puts "#{v.title} #{v.price} #{v.compare_at_price} on_sale=#{v.on_sale?} available=#{v.available?}"
|
|
79
89
|
end
|
|
80
90
|
|
|
81
91
|
# All pages — returns an Enumerator
|
|
@@ -94,6 +104,30 @@ Showroom.products(limit: 5) # => Array<Product>
|
|
|
94
104
|
Showroom.product('lorem-road-bike') # => Product
|
|
95
105
|
```
|
|
96
106
|
|
|
107
|
+
## Collections
|
|
108
|
+
|
|
109
|
+
```ruby
|
|
110
|
+
# List
|
|
111
|
+
Showroom::Collection.where(limit: 10)
|
|
112
|
+
|
|
113
|
+
# Single
|
|
114
|
+
collection = Showroom::Collection.find('lorem-helmets')
|
|
115
|
+
collection.title # => "Lorem Helmets"
|
|
116
|
+
collection.handle # => "lorem-helmets"
|
|
117
|
+
collection.products_count # => 12
|
|
118
|
+
collection.url # => "https://acme.myshopify.com/collections/lorem-helmets"
|
|
119
|
+
|
|
120
|
+
# Products in a collection
|
|
121
|
+
collection.products(limit: 5).each { |p| puts p.title }
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Module-level shortcuts
|
|
125
|
+
|
|
126
|
+
```ruby
|
|
127
|
+
Showroom.collections(limit: 5) # => Array<Collection>
|
|
128
|
+
Showroom.collection('lorem-helmets') # => Collection
|
|
129
|
+
```
|
|
130
|
+
|
|
97
131
|
## Search
|
|
98
132
|
|
|
99
133
|
Showroom wraps Shopify's `/search/suggest.json` endpoint via `Showroom.search`.
|
data/lib/showroom/client.rb
CHANGED
|
@@ -44,7 +44,7 @@ module Showroom
|
|
|
44
44
|
# @param params [Hash] Shopify query parameters
|
|
45
45
|
# @return [Array<Product>]
|
|
46
46
|
def products(**params)
|
|
47
|
-
get('/products.json', params).fetch('products', []).map { |h| Product.new(h) }
|
|
47
|
+
get('/products.json', params).fetch('products', []).map { |h| Product.new(h).tap { |r| r.client = self } }
|
|
48
48
|
end
|
|
49
49
|
|
|
50
50
|
# Fetches a single product by handle.
|
|
@@ -55,7 +55,7 @@ module Showroom
|
|
|
55
55
|
def product(handle)
|
|
56
56
|
get("/products/#{handle}.json")
|
|
57
57
|
.fetch('product') { raise Showroom::NotFound, handle }
|
|
58
|
-
.then { |h| Product.new(h) }
|
|
58
|
+
.then { |h| Product.new(h).tap { |r| r.client = self } }
|
|
59
59
|
end
|
|
60
60
|
|
|
61
61
|
# Fetches collections from the store.
|
|
@@ -63,7 +63,11 @@ module Showroom
|
|
|
63
63
|
# @param params [Hash] Shopify query parameters
|
|
64
64
|
# @return [Array<Collection>]
|
|
65
65
|
def collections(**params)
|
|
66
|
-
get('/collections.json', params).fetch('collections', []).map
|
|
66
|
+
get('/collections.json', params).fetch('collections', []).map do |h|
|
|
67
|
+
Collection.new(h).tap do |r|
|
|
68
|
+
r.client = self
|
|
69
|
+
end
|
|
70
|
+
end
|
|
67
71
|
end
|
|
68
72
|
|
|
69
73
|
# Fetches a single collection by handle.
|
|
@@ -74,7 +78,7 @@ module Showroom
|
|
|
74
78
|
def collection(handle)
|
|
75
79
|
get("/collections/#{handle}.json")
|
|
76
80
|
.fetch('collection') { raise Showroom::NotFound, handle }
|
|
77
|
-
.then { |h| Collection.new(h) }
|
|
81
|
+
.then { |h| Collection.new(h).tap { |r| r.client = self } }
|
|
78
82
|
end
|
|
79
83
|
|
|
80
84
|
# Calls the Shopify search suggest endpoint and returns a {Search::Result}.
|
|
@@ -13,6 +13,13 @@ module Showroom
|
|
|
13
13
|
# @return [Faraday::Response, nil] the last HTTP response object
|
|
14
14
|
attr_reader :last_response
|
|
15
15
|
|
|
16
|
+
# Returns the canonical HTTPS base URL for the configured store.
|
|
17
|
+
#
|
|
18
|
+
# @return [String]
|
|
19
|
+
def base_url
|
|
20
|
+
StoreUrl.resolve(store)
|
|
21
|
+
end
|
|
22
|
+
|
|
16
23
|
# Memoized Faraday connection built from the current configuration.
|
|
17
24
|
#
|
|
18
25
|
# @return [Faraday::Connection]
|
|
@@ -59,9 +59,18 @@ module Showroom
|
|
|
59
59
|
# @param params [Hash] Shopify query parameters (e.g. +limit:+, +page:+)
|
|
60
60
|
# @return [Array<Product>]
|
|
61
61
|
def products(**params)
|
|
62
|
-
Showroom.client
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
conn = client || Showroom.client
|
|
63
|
+
conn.get("/collections/#{handle}/products.json", params)
|
|
64
|
+
.fetch('products', [])
|
|
65
|
+
.map { |h| Product.new(h).tap { |r| r.client = conn } }
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
# Returns the canonical storefront URL for this collection.
|
|
69
|
+
#
|
|
70
|
+
# @return [String]
|
|
71
|
+
def url
|
|
72
|
+
conn = client || Showroom.client
|
|
73
|
+
"#{conn.base_url}/collections/#{handle}"
|
|
65
74
|
end
|
|
66
75
|
end
|
|
67
76
|
end
|
|
@@ -138,5 +138,37 @@ module Showroom
|
|
|
138
138
|
def featured_image
|
|
139
139
|
images.first
|
|
140
140
|
end
|
|
141
|
+
|
|
142
|
+
# Returns the canonical storefront URL for this product.
|
|
143
|
+
#
|
|
144
|
+
# @return [String]
|
|
145
|
+
def url
|
|
146
|
+
conn = client || Showroom.client
|
|
147
|
+
"#{conn.base_url}/products/#{handle}"
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
# Returns unique prices across all variants as an Array of Strings.
|
|
151
|
+
#
|
|
152
|
+
# Unlike {#price} (lowest single price) or {#price_range} (formatted string),
|
|
153
|
+
# this returns the raw deduplicated list useful for custom rendering.
|
|
154
|
+
#
|
|
155
|
+
# @return [Array<String>]
|
|
156
|
+
def prices
|
|
157
|
+
variants.map do |variant|
|
|
158
|
+
variant['price']
|
|
159
|
+
end.uniq
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
# Returns the image whose +position+ field equals 1, or nil if none match.
|
|
163
|
+
#
|
|
164
|
+
# Unlike {#featured_image} (which returns +images.first+ regardless of
|
|
165
|
+
# position), this explicitly matches on the +position+ attribute.
|
|
166
|
+
#
|
|
167
|
+
# @return [ProductImage, nil]
|
|
168
|
+
def main_image
|
|
169
|
+
images.find do |img|
|
|
170
|
+
img['position'] == 1
|
|
171
|
+
end
|
|
172
|
+
end
|
|
141
173
|
end
|
|
142
174
|
end
|
|
@@ -8,7 +8,7 @@ module Showroom
|
|
|
8
8
|
# variant.available? # => true
|
|
9
9
|
# variant.on_sale? # => false
|
|
10
10
|
class ProductVariant < Resource
|
|
11
|
-
main_attrs :id, :title, :price, :sku
|
|
11
|
+
main_attrs :id, :title, :price, :compare_at_price, :sku
|
|
12
12
|
|
|
13
13
|
# Returns true when the variant is available for purchase.
|
|
14
14
|
#
|
|
@@ -15,6 +15,9 @@ module Showroom
|
|
|
15
15
|
# @return [Hash] the normalized attribute hash
|
|
16
16
|
attr_reader :attrs
|
|
17
17
|
|
|
18
|
+
# @return [Showroom::Client, nil] the client that fetched this resource
|
|
19
|
+
attr_accessor :client
|
|
20
|
+
|
|
18
21
|
# Initializes a Resource from a Hash, normalizing all keys to strings.
|
|
19
22
|
#
|
|
20
23
|
# @param hash [Hash] attribute data
|