Skip to content

Commit 519b9f5

Browse files
authored
Merge pull request #69 from zehua/tinyurl-shorterning
replace deprecated google url shortener with tinyurl
2 parents 7d363dd + 8f7e289 commit 519b9f5

File tree

8 files changed

+5299
-1879
lines changed

8 files changed

+5299
-1879
lines changed

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,13 @@ This will start serving the _repl_ at [localhost:8080/example](http://localhost:
215215
To build the JavaScript bundle:
216216

217217
```
218-
npm run build
218+
npm run build-js
219+
```
220+
221+
To build the CSS bundle:
222+
223+
```
224+
npm run build-css
219225
```
220226

221227
#### Watch modes

dist/bundle.js

Lines changed: 55 additions & 58 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

example/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@
9696

9797
ramdaRepl(e.target, {
9898

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

102102
// If unset, initialValue will use the value or textcontent of the

lib/js/repl.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import reporter from './logger';
44
import bindClearButton from './clear';
55
import bindResetButton from './reset';
66
import bindPrettyBtn from './pretty';
7-
import bindShortUrlButton from './googl';
7+
import bindShortUrlButton from './tinyurl';
88
import bindInputPanel from './input-panel';
99
import bindOutputPanel from './output-panel';
1010
import replDOM from './dom/replDOM';

lib/js/googl.js renamed to lib/js/tinyurl.js

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import R from 'ramda';
2-
import S from 'sanctuary';
32
import {Future} from 'ramda-fantasy';
43

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

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

1818
oReq.addEventListener('load', resolve, false);
1919
oReq.addEventListener('error', reject, false);
2020
oReq.addEventListener('abort', reject, false);
21-
oReq.open('POST', options.apiUrl, true);
22-
oReq.setRequestHeader('Content-Type', 'application/json; charset=utf-8');
23-
oReq.send(JSON.stringify(requestData));
21+
oReq.open('GET', apiUrl, true);
22+
oReq.send(null);
2423
});
2524
};
2625

27-
const getResponse = R.compose(R.map(S.parseJson(Object)),
28-
R.map(R.path(['target', 'responseText'])), xhr);
29-
30-
const getShortUrl = options => R.map(R.compose(setValue(options), R.prop('id')));
26+
const getResponse = R.compose(R.map(R.path(['target', 'responseText'])), xhr);
3127

3228
const futureXhr = options => getResponse(options);
3329

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

4339
options.btnMakeShortUrl.addEventListener('click', function() {
44-
futureXhr(options).fork(error, getShortUrl(options));
40+
futureXhr(options).fork(error, setValue(options));
4541
});
4642

4743
}

0 commit comments

Comments
 (0)