Skip to content

Commit

Permalink
replace deprecated google url shortener with tinyurl
Browse files Browse the repository at this point in the history
  • Loading branch information
zehua committed Sep 29, 2020
1 parent 7d363dd commit 8f7e289
Show file tree
Hide file tree
Showing 8 changed files with 5,299 additions and 1,879 deletions.
8 changes: 7 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,13 @@ This will start serving the _repl_ at [localhost:8080/example](http://localhost:
To build the JavaScript bundle:

```
npm run build
npm run build-js
```

To build the CSS bundle:

```
npm run build-css
```

#### Watch modes
Expand Down
113 changes: 55 additions & 58 deletions dist/bundle.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion example/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@

ramdaRepl(e.target, {

apiUrl: 'https://www.googleapis.com/urlshortener/v1/url?key=AIzaSyDhbAvT5JqkxFPkoeezJp19-S_mAJudxyk',
apiUrl: 'https://tinyurl.com/api-create.php',
returnUrl: 'http://ramdajs.com/repl/',

// If unset, initialValue will use the value or textcontent of the
Expand Down
2 changes: 1 addition & 1 deletion lib/js/repl.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import reporter from './logger';
import bindClearButton from './clear';
import bindResetButton from './reset';
import bindPrettyBtn from './pretty';
import bindShortUrlButton from './googl';
import bindShortUrlButton from './tinyurl';
import bindInputPanel from './input-panel';
import bindOutputPanel from './output-panel';
import replDOM from './dom/replDOM';
Expand Down
16 changes: 6 additions & 10 deletions lib/js/googl.js → lib/js/tinyurl.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import R from 'ramda';
import S from 'sanctuary';
import {Future} from 'ramda-fantasy';

const setValue = R.curry(function(options, data) {
Expand All @@ -13,21 +12,18 @@ const xhr = function(options) {
return new Future(function(reject, resolve) {
const oReq = new XMLHttpRequest();

const requestData = { longUrl: `${options.returnUrl}${location.hash}` };
const apiUrl = options.apiUrl + '?url='
+ encodeURIComponent(`${options.returnUrl}${location.hash}`);

oReq.addEventListener('load', resolve, false);
oReq.addEventListener('error', reject, false);
oReq.addEventListener('abort', reject, false);
oReq.open('POST', options.apiUrl, true);
oReq.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
oReq.send(JSON.stringify(requestData));
oReq.open('GET', apiUrl, true);
oReq.send(null);
});
};

const getResponse = R.compose(R.map(S.parseJson(Object)),
R.map(R.path(['target', 'responseText'])), xhr);

const getShortUrl = options => R.map(R.compose(setValue(options), R.prop('id')));
const getResponse = R.compose(R.map(R.path(['target', 'responseText'])), xhr);

const futureXhr = options => getResponse(options);

Expand All @@ -41,7 +37,7 @@ export default function bindShortUrlButton(options) {
}

options.btnMakeShortUrl.addEventListener('click', function() {
futureXhr(options).fork(error, getShortUrl(options));
futureXhr(options).fork(error, setValue(options));
});

}
Loading

0 comments on commit 8f7e289

Please sign in to comment.