1
0
mirror of https://github.com/ascribe/onion.git synced 2024-11-15 01:25:17 +01:00

Rename fetch to requests to avoid name clashing

This commit is contained in:
vrde 2015-06-16 13:48:48 +02:00
parent ed3adf8f67
commit 03f09b8c83
11 changed files with 30 additions and 30 deletions

View File

@ -5,17 +5,19 @@ import Router from 'react-router';
import promise from 'es6-promise'; import promise from 'es6-promise';
promise.polyfill(); promise.polyfill();
import fetch from 'isomorphic-fetch';
//require('isomorphic-fetch');
import ApiUrls from './constants/api_urls'; import ApiUrls from './constants/api_urls';
import routes from './routes'; import routes from './routes';
import fetch from './utils/fetch'; import requests from './utils/requests';
let headers = { let headers = {
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json' 'Content-Type': 'application/json'
}; };
fetch.defaults({ requests.defaults({
urlMap: ApiUrls, urlMap: ApiUrls,
http: { http: {
headers: headers, headers: headers,

View File

@ -2,7 +2,7 @@
import React from 'react'; import React from 'react';
import fetch from '../../utils/fetch'; import requests from '../../utils/requests';
import ApiUrls from '../../constants/api_urls'; import ApiUrls from '../../constants/api_urls';
import FormMixin from '../../mixins/form_mixin'; import FormMixin from '../../mixins/form_mixin';
@ -11,7 +11,7 @@ let EditionDeleteForm = React.createClass({
mixins: [FormMixin], mixins: [FormMixin],
url() { url() {
return fetch.prepareUrl(ApiUrls.edition_delete, {edition_id: this.getBitcoinIds().join()}); return requests.prepareUrl(ApiUrls.edition_delete, {edition_id: this.getBitcoinIds().join()});
}, },
httpVerb(){ httpVerb(){
return 'delete'; return 'delete';

View File

@ -2,7 +2,7 @@
import React from 'react'; import React from 'react';
import fetch from '../../utils/fetch'; import requests from '../../utils/requests';
import apiUrls from '../../constants/api_urls'; import apiUrls from '../../constants/api_urls';
import FormMixin from '../../mixins/form_mixin'; import FormMixin from '../../mixins/form_mixin';
@ -14,7 +14,7 @@ let PieceExtraDataForm = React.createClass({
mixins: [FormMixin], mixins: [FormMixin],
url() { url() {
return fetch.prepareUrl(apiUrls.piece_extradata, {piece_id: this.props.editions[0].bitcoin_id}); return requests.prepareUrl(apiUrls.piece_extradata, {piece_id: this.props.editions[0].bitcoin_id});
}, },
getFormData() { getFormData() {

View File

@ -2,7 +2,7 @@
import React from 'react'; import React from 'react';
import fetch from '../../utils/fetch'; import requests from '../../utils/requests';
import apiUrls from '../../constants/api_urls'; import apiUrls from '../../constants/api_urls';
import FormMixin from '../../mixins/form_mixin'; import FormMixin from '../../mixins/form_mixin';
@ -11,7 +11,7 @@ let EditionRemoveFromCollectionForm = React.createClass({
mixins: [FormMixin], mixins: [FormMixin],
url() { url() {
return fetch.prepareUrl(apiUrls.edition_remove_from_collection, {edition_id: this.getBitcoinIds().join()}); return requests.prepareUrl(apiUrls.edition_remove_from_collection, {edition_id: this.getBitcoinIds().join()});
}, },
httpVerb(){ httpVerb(){
return 'delete'; return 'delete';

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
let EditionFetcher = { let EditionFetcher = {
/** /**
@ -8,7 +8,7 @@ let EditionFetcher = {
* If no arg is supplied, load the current user * If no arg is supplied, load the current user
*/ */
fetchOne(editionId) { fetchOne(editionId) {
return fetch.get('edition', {'bitcoin_id': editionId}); return requests.get('edition', {'bitcoin_id': editionId});
} }
}; };

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
import { generateOrderingQueryParams } from '../utils/fetch_api_utils'; import { generateOrderingQueryParams } from '../utils/fetch_api_utils';
@ -11,7 +11,7 @@ let EditionListFetcher = {
*/ */
fetch(pieceId, orderBy, orderAsc) { fetch(pieceId, orderBy, orderAsc) {
let ordering = generateOrderingQueryParams(orderBy, orderAsc); let ordering = generateOrderingQueryParams(orderBy, orderAsc);
return fetch.get('editions_list', { 'piece_id': pieceId, ordering }); return requests.get('editions_list', { 'piece_id': pieceId, ordering });
} }
}; };

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
let PieceFetcher = { let PieceFetcher = {
@ -9,7 +9,7 @@ let PieceFetcher = {
* If no arg is supplied, load the current user * If no arg is supplied, load the current user
*/ */
fetchOne() { fetchOne() {
return fetch.get('piece'); return requests.get('piece');
} }
}; };

View File

@ -1,7 +1,7 @@
'use strict'; 'use strict';
import { generateOrderingQueryParams } from '../utils/fetch_api_utils'; import { generateOrderingQueryParams } from '../utils/fetch_api_utils';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
let PieceListFetcher = { let PieceListFetcher = {
@ -11,7 +11,7 @@ let PieceListFetcher = {
*/ */
fetch(page, pageSize, search, orderBy, orderAsc) { fetch(page, pageSize, search, orderBy, orderAsc) {
let ordering = generateOrderingQueryParams(orderBy, orderAsc); let ordering = generateOrderingQueryParams(orderBy, orderAsc);
return fetch.get('pieces_list', { page, pageSize, search, ordering }); return requests.get('pieces_list', { page, pageSize, search, ordering });
} }
}; };

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
let UserFetcher = { let UserFetcher = {
@ -9,7 +9,7 @@ let UserFetcher = {
* If no arg is supplied, load the current user * If no arg is supplied, load the current user
*/ */
fetchOne() { fetchOne() {
return fetch.get('user'); return requests.get('user');
} }
}; };

View File

@ -1,6 +1,6 @@
'use strict'; 'use strict';
import fetch from '../utils/fetch'; import requests from '../utils/requests';
import React from 'react'; import React from 'react';
import AlertDismissable from '../components/ascribe_forms/alert'; import AlertDismissable from '../components/ascribe_forms/alert';
@ -29,14 +29,14 @@ export const FormMixin = {
}, },
post(e){ post(e){
fetch requests
.post(this.url(e), { body: this.getFormData() }) .post(this.url(e), { body: this.getFormData() })
.then(this.handleSuccess) .then(this.handleSuccess)
.catch(this.handleError); .catch(this.handleError);
}, },
delete(e){ delete(e){
fetch requests
.delete(this.url(e)) .delete(this.url(e))
.then(this.handleSuccess) .then(this.handleSuccess)
.catch(this.handleError); .catch(this.handleError);

View File

@ -1,7 +1,5 @@
'use strict'; 'use strict';
import { default as _fetch } from 'isomorphic-fetch';
import { argsToQueryParams } from '../utils/fetch_api_utils'; import { argsToQueryParams } from '../utils/fetch_api_utils';
@ -10,7 +8,7 @@ class ServerError extends Error {}
class APIError extends Error {} class APIError extends Error {}
class Fetch { class Requests {
_merge(defaults, options) { _merge(defaults, options) {
let merged = {}; let merged = {};
for (let key in defaults) { for (let key in defaults) {
@ -79,7 +77,7 @@ class Fetch {
options = options || {}; options = options || {};
let merged = this._merge(this.httpOptions, options); let merged = this._merge(this.httpOptions, options);
merged.method = verb; merged.method = verb;
return _fetch(url, merged) return fetch(url, merged)
.then(this.unpackResponse) .then(this.unpackResponse)
.then(JSON.parse) .then(JSON.parse)
.catch(this.handleFatalError.bind(this)) .catch(this.handleFatalError.bind(this))
@ -117,6 +115,6 @@ class Fetch {
} }
let fetch = new Fetch(); let requests = new Requests();
export default fetch; export default requests;