UNPKG

@eastsideco/escshopify

Version:

WIP JS library for Shopify, containing a variety of useful functionality.

231 lines (205 loc) 13.5 kB
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <base data-ice="baseUrl" href="../../../"> <title data-ice="title">src/geoservice/GeoService.js | @eastsideco/escshopify</title> <link type="text/css" rel="stylesheet" href="css/style.css"> <link type="text/css" rel="stylesheet" href="css/prettify-tomorrow.css"> <script src="script/prettify/prettify.js"></script> <script src="script/manual.js"></script> </head> <body class="layout-container" data-ice="rootContainer"> <header> <a href="./">Home</a> <a href="./manual/index.html" data-ice="manualHeaderLink">Manual</a> <a href="identifiers.html">Reference</a> <a href="source.html">Source</a> <div class="search-box"> <span> <img src="./image/search.png"> <span class="search-input-edge"></span><input class="search-input"><span class="search-input-edge"></span> </span> <ul class="search-result"></ul> </div> <a href="https://bitbucket.org/sigapps/escshopify.git">Repository</a></header> <nav class="navigation" data-ice="nav"><div> <ul> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-entities">entities</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-plugins">plugins</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-utils">utils</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-external">E</span><span data-ice="name"><span><a href="https://www.npmjs.com/package/promise-queue">promise-queue</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#easycurrency">easycurrency</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/EasyCurrency.js~EasyCurrency.html">EasyCurrency</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/MoneySpan.js~MoneySpan.html">MoneySpan</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/MoneySpanSet.js~MoneySpanSet.html">MoneySpanSet</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/Session.js~Session.html">Session</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/config.js~Config.html">Config</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/state.js~State.html">State</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#easycurrency-formatters">easycurrency/formatters</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/formatters/DefaultFormatter.js~DefaultFormatter.html">DefaultFormatter</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/formatters/Formatter.js~Formatter.html">Formatter</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#easycurrency-helpers">easycurrency/helpers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/helpers/SelectHelper.js~SelectHelper.html">SelectHelper</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#easycurrency-resolvers">easycurrency/resolvers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/resolvers/CurrencyResolver.js~CurrencyResolver.html">CurrencyResolver</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/easycurrency/resolvers/GeoserviceResolver.js~GeoserviceResolver.html">GeoserviceResolver</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#entities">entities</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/entities/Cart.js~Cart.html">Cart</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/entities/Shop.js~Shop.html">Shop</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-Cart">Cart</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-a">a</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyCart">ShopifyCart</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyCartLineItem">ShopifyCartLineItem</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyAddress">ShopifyAddress</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyPolicy">ShopifyPolicy</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-ShopifyShop">ShopifyShop</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#geoservice">geoservice</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/geoservice/API.js~API.html">API</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/geoservice/GeoService.js~GeoService.html">GeoService</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSContinent">GSContinent</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCountry">GSCountry</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCurrencyRates">GSCurrencyRates</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSCurrencyResponse">GSCurrencyResponse</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSGeoResponse">GSGeoResponse</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSLocation">GSLocation</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-typedef">T</span><span data-ice="name"><span><a href="typedef/index.html#static-typedef-GSTranslatedString">GSTranslatedString</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#http">http</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/http/RequestQueuable.js~RequestQueuable.html">RequestQueuable</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils">utils</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/Log.js~Log.html">Log</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/general.js~GeneralUtils.html">GeneralUtils</a></span></span></li> <li data-ice="doc"><a data-ice="dirPath" class="nav-dir-path" href="identifiers.html#utils-loggers">utils/loggers</a><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/ConsoleLogger.js~ConsoleLogger.html">ConsoleLogger</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/Logger.js~Logger.html">Logger</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-class">C</span><span data-ice="name"><span><a href="class/src/utils/loggers/logLevel.js~LogLevel.html">LogLevel</a></span></span></li> <li data-ice="doc"><span data-ice="kind" class="kind-variable">V</span><span data-ice="name"><span><a href="variable/index.html#static-variable-logLevel">logLevel</a></span></span></li> </ul> </div> </nav> <div class="content" data-ice="content"><h1 data-ice="title">src/geoservice/GeoService.js</h1> <pre class="source-code line-number raw-source-code"><code class="prettyprint linenums" data-ice="content">import Evee from &apos;evee&apos;; import API from &apos;./API&apos;; /** * @typedef {Object} GSGeoResponse * @property {GSContinent} continent * @property {GSCountry} country * @property {GSLocation} location * @property {GSCountry} registered_country * @property {String} currency */ /** * @typedef {Object} GSTranslatedString * @property {String} de * @property {String} en * @property {String} es * @property {String} fr * @property {String} ja * @property {String} pt-BR * @property {String} ru * @property {String} zh-CN */ /** * @typedef {Object} GSContinent * @property {String} code * @property {Number} geoname_id * @property {GSTranslatedString} names */ /** * @typedef {Object} GSCountry * @property {Number} geoname_id * @property {String} iso_code * @property {GSTranslatedString} names */ /** * @typedef {Object} GSLocation * @property {Number} accuracy_radius * @property {Number} latitude * @property {Number} longitude */ /** * @typedef {Object} GSCurrencyResponse * @property {String} base * @property {String} date - Update date in Y-M-D format * @property {GSCurrencyRates} rates */ /** * @typedef {Object} GSCurrencyRates * @property {Number} AUD * @property {Number} BGN * @property {Number} BRL * @property {Number} CAD * @property {Number} CHF * @property {Number} CNY * @property {Number} CZK * @property {Number} DKK * @property {Number} GBP * @property {Number} HKD * @property {Number} HUF * @property {Number} IDR * @property {Number} ILD * @property {Number} INR * @property {Number} JPY * @property {Number} KRW * @property {Number} MXN * @property {Number} MYR * @property {Number} NOK * @property {Number} NZD * @property {Number} PHP * @property {Number} PLN * @property {Number} RON * @property {Number} RUB * @property {Number} SEK * @property {Number} SGD * @property {Number} THB * @property {Number} TRY * @property {Number} ZAR * @property {Number} EUR */ /** * Provides access to the ESC Geoservice. */ export default class GeoService extends Evee { /** * Create a new instance of GeoService. */ constructor() { super(); /** @type {src/geoservice/API.js~API} */ this.api = new API(); /** @type {Boolean} */ this.cacheLookups = true; /** @type {Object&lt;String, Object&gt;} */ this._cachedLookups = {}; } /** * Retrieves geolocation information. * @param {String} [ip] - IP address to get information on. If not supplied, uses local IP. * @return {Promise&lt;GSGeoResponse|Error&gt;} */ async lookupGeo(ip) { if (!ip) { ip = &apos;&apos;; } if (this.cacheLookups &amp;&amp; this._cachedLookups[ip]) { return this._cachedLookups[ip]; } var result = await this.api.geoip(ip); if (this.cacheLookups) { this._cachedLookups[ip] = result; } return result; } /** * Retrieves currency info. * @return {Promise&lt;GSCurrencyResponse, Error&gt;} */ async getCurrencyInfo() { return await this.api.currency(); } } </code></pre> </div> <footer class="footer"> Generated by <a href="https://esdoc.org">ESDoc<span data-ice="esdocVersion">(1.0.4)</span><img src="./image/esdoc-logo-mini-black.png"></a> </footer> <script src="script/search_index.js"></script> <script src="script/search.js"></script> <script src="script/pretty-print.js"></script> <script src="script/inherited-summary.js"></script> <script src="script/test-summary.js"></script> <script src="script/inner-link.js"></script> <script src="script/patch-for-local.js"></script> </body> </html>