Class: MerlinsConnector

merlins.MerlinsConnector()

A connector for www.merlinspotions.com, using screen-scraping.

Constructor

new MerlinsConnector()

Implements:
Source:

Methods

(static) fromConfig(config) → {module:types.MerlinsConnector}

Given a configuration in the form of a plain object, this method returns a new MerlinsConnector instance.

Parameters:
Name Type Description
config Object
Source:
Returns:

The new MerlinsConnector instance.

Type
module:types.MerlinsConnector

getCategories(ids, optsopt) → {Promise.<module:types.CategoryList>}

Returns multiple product Categories by their ids.

On supported backends this method will retrieve Categories in a single network call. Others may make a call per id to emulate the same behaviour.

Invalid ids are ignored and results are not guaranteed to be returned in the order requested.

Parameters:
Name Type Attributes Description
ids Array.<String>
opts Object <optional>

object

Implements:
Source:
Returns:
Type
Promise.<module:types.CategoryList>

getCategory(id, optsopt) → {Promise.<module:types.Category>}

Get a product Category by id.

Parameters:
Name Type Attributes Description
id String
opts Object <optional>

object

Implements:
Source:
Returns:
Type
Promise.<module:types.Category>

getCustomer(id, optsopt) → {Promise.<module:types.Customer>}

Return a customer's details by id.

Parameters:
Name Type Attributes Description
id String

Customer Id

opts Object <optional>

Options object

Implements:
Source:
Throws:

Throw generic error if server has error.

Type
module:errors/ServerError
Returns:
Type
Promise.<module:types.Customer>

getProduct(id, optsopt) → {Promise.<module:types.Product>}

Get a single product by id.

Parameters:
Name Type Attributes Description
id String

The product id.

opts Object <optional>

Options object

Implements:
Source:
Returns:

.

Type
Promise.<module:types.Product>

getProducts(ids, optsopt) → {Promise.<module:types.ProductList>}

Get multiple products by their ids.

On supported backends this method will retrieve products in a single network call. Others may make a call per id to emulate the same behaviour.

Invalid ids are ignored and results are not guaranteed to be returned in the order requested.

Parameters:
Name Type Attributes Description
ids Array.<String>

The product ids.

opts Object <optional>

Options object

Implements:
Source:
Returns:

.

Type
Promise.<module:types.ProductList>

getSearchUrl(productSearchRequest) → {String}

Takes commerce-integrations ProductSearchRequest type and returns the URL representation used to query the website.

Parameters:
Name Type Description
productSearchRequest module:types.ProductSearchRequest
Source:
Returns:
Type
String

getStore(id, optsopt) → {Promise.<module:types.Store>}

Get a Store (ie. a physical retail-outlet) by id. Includes addresses, opening hours, etc.

Parameters:
Name Type Attributes Description
id String

The id of the store

opts Object <optional>

Options object

Implements:
Source:
Returns:

.

Type
Promise.<module:types.Store>

login(username, password) → {Promise.<module:types/Customer>}

Log a customer in and return their details.

On backends which support "guest login", credentials can be omitted to give you a guest session.

Parameters:
Name Type Description
username String
password String
Implements:
Source:
Throws:
  • Will throw an error if the username or password aren't provided for type registered.

    Type
    module:errors/InvalidArgumentError
  • Will throw an error if the customer credentials are incorrect.

    Type
    module:errors/ForbiddenError
Returns:

.

Type
Promise.<module:types/Customer>

logout() → {Promise.<undefined>}

Log a custmer out.

Implements:
Source:
Throws:

Will throw an error if there was a server-side error.

Type
module:errors/ServerError
Returns:
Type
Promise.<undefined>

parseCategory(htmlDoc) → {Promise.<module:types.Category>}

Takes a html element that represents a category and parses it into a commerce-integrations Category type.

Parameters:
Name Type Description
htmlDoc Object

a Element object

Source:
Returns:
Type
Promise.<module:types.Category>

parseFilter(optionEl) → {module:types.Filter}

Takes a dom element representing a merlins filter and parses out an commerce-integrations Filter type.

Parameters:
Name Type Description
optionEl Object

a Element object

Source:
Returns:
Type
module:types.Filter

parseFilters(filterOptionsEl, currentUrl) → {Array.<module:types.Filter>}

Takes a dom element and parses out an array of commerce-integrations Filter type.

Parameters:
Name Type Description
filterOptionsEl Object

a Element object

currentUrl String

The current page url used to help determine filter values.

Source:
Returns:
Type
Array.<module:types.Filter>

parseProduct(data) → {Promise.<module:types.Store>}

Takes a OCAPI Product object and parses it into a commerce-integrations Product type.

Parameters:
Name Type Description
data Object

a OCAPI Product document

Source:
Returns:
Type
Promise.<module:types.Store>

parseProductSearchResult(productEl) → {module:types.ProductSearchResult}

Takes a dom element representing a merlins search result product tile and parses out an commerce-integrations ProductSearchResult type.

Parameters:
Name Type Description
productEl Object

a Element object

Source:
Returns:
Type
module:types.ProductSearchResult

parseSelectedFilter(selectedEl, currentUrl) → {module:types.Filter}

Takes a dom element representing a merlins selected filter and parses out a commerce-integrations Filter type.

Parameters:
Name Type Description
selectedEl Object

a Element object

currentUrl String

The current page url used to help determine filter values.

Source:
Returns:
Type
module:types.Filter

parseSelectedFilters(selectedFiltersEl, currentUrl) → {Array.<module:types.Filter>}

Takes a dom element and parses out an array of commerce-integrations Filter type representing those filters that are selected.

Parameters:
Name Type Description
selectedFiltersEl Object

a Element object

currentUrl String

The current page url used to help determine filter values.

Source:
Returns:
Type
Array.<module:types.Filter>

parseSortingOptions(sortEl) → {Array.<module:types.SortOption>}

Takes a dom element representing a merlins sorting select and parses out an array od commerce-integrations SortOption type.

Parameters:
Name Type Description
sortEl Object

a Element object

Source:
Returns:
Type
Array.<module:types.SortOption>

refreshSession() → {Promise.<module:types/Customer>}

Refresh a session token, on backends that support refresh.

Implements:
Source:
Throws:

Will throw an error if authorization credentials are incorrect

Type
module:errors/ForbiddenError
Returns:
Type
Promise.<module:types/Customer>

searchProducts(productSearchRequest, optsopt) → {Promise.<module:types.ProductSearch>}

Search for products, given a productSearchRequest object.

Parameters:
Name Type Attributes Description
productSearchRequest module:types.ProductSearchRequest

Search query

opts Object <optional>

Options object

Implements:
Source:
Returns:
Type
Promise.<module:types.ProductSearch>

searchStores(storeSearchRequest, optsopt) → {Promise.<module:types.StoreSearchResult>}

Searches for Stores (ie. physical retail-outlets).

Parameters:
Name Type Attributes Description
storeSearchRequest module:types.StoreSearchRequest
opts Object <optional>

Options object

Implements:
Source:
Returns:
Type
Promise.<module:types.StoreSearchResult>