Skip to content

Commit 84c9a0e

Browse files
Rest api url builder
0 parents  commit 84c9a0e

File tree

8 files changed

+173
-0
lines changed

8 files changed

+173
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
1.0.0
2+
* module initialization
3+
* rest api js url builder

LICENSE.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2020 Bartosz Kubicki
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# BKubicki Magento 2 Ui #
2+
3+
4+
## Overview ##
5+
Module extending module Magento_Ui and adding new components and utils
6+
7+
8+
## Features ##
9+
* rest api js url builder
10+
11+
12+
## Prerequisites
13+
* Magento 2.3/2.4+
14+
* PHP 7.3/7.4
15+
16+
17+
## Installation ###
18+
19+
To install the extension use the following commands:
20+
21+
```bash
22+
composer require bkubicki/module-magento2-ui
23+
```
24+
25+
## Versioning ##
26+
27+
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/bartoszkubicki/magento2-polish-noun-numeral-declension-adapter/tags).
28+
29+
30+
## Changelog
31+
32+
See changelog [here](CHANGELOG.md).
33+
34+
35+
## Authors ##
36+
37+
* [Bartosz Kubicki](https://github.com/bartoszkubicki)
38+
39+
40+
## License ##
41+
42+
This project is licensed under the MIT License - see the [LICENSE](LICENSE.md) file for details.

composer.json

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "bkubicki/module-magento2-ui",
3+
"description": "Module extending module Magento_Ui and adding new components and utils",
4+
"require": {
5+
"php": "~7.2.0||~7.3.0||~7.4.0",
6+
"magento/framework": "102.0.*||103.0.*",
7+
"magento/module-ui": ">=101.0.0"
8+
},
9+
"type": "magento2-module",
10+
"version": "1.0.0",
11+
"license": "MIT",
12+
"autoload": {
13+
"files": [
14+
"registration.php"
15+
],
16+
"psr-4": {
17+
"BKubicki\\Magento2Ui\\": ""
18+
}
19+
}
20+
}

etc/module.xml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* @author Bartosz Kubicki <b.w.kubicki@gmail.com>
5+
* Github https://github.com/bartoszkubicki
6+
*/
7+
-->
8+
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
9+
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
10+
<module name="BKubicki_Magento2Ui">
11+
<sequence>
12+
<module name="Magento_Ui"/>
13+
</sequence>
14+
</module>
15+
</config>

registration.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* File: registration.php
7+
*
8+
* @author Bartosz Kubicki b.w.kubicki@gmail.com>
9+
* Github: https://github.com/bartoszkubicki
10+
*/
11+
use Magento\Framework\Component\ComponentRegistrar;
12+
13+
ComponentRegistrar::register(
14+
ComponentRegistrar::MODULE,
15+
'BKubicki_Magento2Ui',
16+
__DIR__
17+
);
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/**
2+
* File: rest-api-url-builder.js
3+
*
4+
* @author Bartosz Kubicki b.w.kubicki@gmail.com>
5+
* Github: https://github.com/bartoszkubicki
6+
*/
7+
8+
'use strict';
9+
10+
define([], function () {
11+
return {
12+
method: 'rest',
13+
version: 'V1',
14+
serviceUrl: ':method/:storeCode/:version',
15+
16+
/**
17+
* @param {String} url
18+
* @param {String} storeCode
19+
* @param {Object} params
20+
* @return {String}
21+
*/
22+
createUrl: function (url, storeCode, params) {
23+
let completeUrl = this.serviceUrl + url;
24+
return this.bindParams(completeUrl, storeCode, params);
25+
},
26+
27+
/**
28+
* @param {String} url
29+
* @param {String} storeCode
30+
* @param {Object} params
31+
* @return {String}
32+
*/
33+
bindParams: function (url, storeCode, params) {
34+
let urlParts;
35+
36+
params.method = String(this.method);
37+
params.storeCode = String(storeCode);
38+
params.version = String(this.version);
39+
40+
urlParts = url.split('/');
41+
urlParts = urlParts.filter(Boolean);
42+
43+
urlParts.forEach(function (part, key) {
44+
part = part.replace(':', '');
45+
46+
if (params[part] !== undefined) { //eslint-disable-line eqeqeq
47+
urlParts[key] = params[part];
48+
}
49+
});
50+
51+
return urlParts.join('/');
52+
}
53+
};
54+
});

0 commit comments

Comments
 (0)