Module: Showroom

Extended by:
Core::Configurable
Defined in:
lib/showroom.rb,
lib/showroom/client.rb,
lib/showroom/core/error.rb,
lib/showroom/core/default.rb,
lib/showroom/core/version.rb,
lib/showroom/models/search.rb,
lib/showroom/core/countable.rb,
lib/showroom/core/store_url.rb,
lib/showroom/models/product.rb,
lib/showroom/core/connection.rb,
lib/showroom/models/resource.rb,
lib/showroom/core/configurable.rb,
lib/showroom/models/collection.rb,
lib/showroom/models/product_image.rb,
lib/showroom/models/search/result.rb,
lib/showroom/models/product_option.rb,
lib/showroom/models/product_variant.rb,
lib/showroom/models/search/suggestion.rb,
lib/showroom/http/middleware/raise_error.rb,
lib/showroom/models/search/page_suggestion.rb,
lib/showroom/models/search/query_suggestion.rb,
lib/showroom/models/search/article_suggestion.rb,
lib/showroom/models/search/product_suggestion.rb,
lib/showroom/models/search/collection_suggestion.rb

Overview

Top-level namespace for the Showroom gem.

Acts as a module-level client with Core::Configurable mixed in, so you can configure and use Showroom directly without instantiating a Client.

Examples:

Global configuration

Showroom.configure do |c|
  c.store = 'example.myshopify.com'
end

Module-level request

Showroom.client.get('/products.json')

Defined Under Namespace

Modules: Core, Http, Search Classes: BadRequest, Client, ClientError, Collection, ConfigurationError, ConnectionError, Error, InvalidResponse, NotFound, Product, ProductImage, ProductOption, ProductVariant, Resource, ResponseError, ServerError, TooManyRequests, UnprocessableEntity

Constant Summary

Constants included from Core::Configurable

Core::Configurable::KEYS

Class Method Summary collapse

Methods included from Core::Configurable

configure, options, per_page=, reset!, same_options?, store, store=

Class Method Details

.clientClient

Returns the memoized module-level Client.

Returns:



33
34
35
# File 'lib/showroom.rb', line 33

def self.client
  @client ||= Client.new(**options)
end

.collection(handle) ⇒ Collection

Fetches a single collection by handle from the configured store.

Parameters:

  • handle (String)

    the collection handle

Returns:

Raises:



92
93
94
# File 'lib/showroom.rb', line 92

def self.collection(handle)
  Collection.find(handle)
end

.collections(**params) ⇒ Array<Collection>

Fetches collections from the configured store.

Parameters:

  • params (Hash)

    Shopify query parameters

Returns:



83
84
85
# File 'lib/showroom.rb', line 83

def self.collections(**params)
  Collection.where(**params)
end

.configure {|self| ... } ⇒ self

Configures the module and resets the memoized client so the next call to client picks up the new settings.

Yields:

  • (self)

Returns:

  • (self)


42
43
44
# File 'lib/showroom.rb', line 42

def self.configure
  super.tap { @client = nil }
end

.product(handle) ⇒ Product

Fetches a single product by handle from the configured store.

Parameters:

  • handle (String)

    the product handle

Returns:

Raises:



75
76
77
# File 'lib/showroom.rb', line 75

def self.product(handle)
  Product.find(handle)
end

.products(**params) ⇒ Array<Product>

Fetches products from the configured store.

Parameters:

  • params (Hash)

    Shopify query parameters

Returns:



66
67
68
# File 'lib/showroom.rb', line 66

def self.products(**params)
  Product.where(**params)
end

.reset!void

This method returns an undefined value.

Resets all configuration to defaults and clears the memoized client.



49
50
51
52
# File 'lib/showroom.rb', line 49

def self.reset!
  super
  @client = nil
end

.search(query_str) ⇒ Search::Result

Calls the Shopify search suggest endpoint and returns a Showroom::Search::Result.

All keyword arguments are forwarded verbatim to Showroom::Search.suggest (accepted keys: types:, limit:; see Showroom::Search.suggest for details).

Parameters:

  • query_str (String)

    the search query

Returns:



103
104
105
# File 'lib/showroom.rb', line 103

def self.search(query_str, **)
  Search.suggest(query_str, **)
end

.setup {|self| ... } ⇒ self

Alias for configure — yields self for block-style setup.

Yields:

  • (self)

Returns:

  • (self)


58
59
60
# File 'lib/showroom.rb', line 58

def self.setup(&)
  configure(&)
end