示例#1
0
 it('should promisify options', done => {
   request('a', {
     mutate (options) {
       return options
     }
   }).finally(done)
 })
示例#2
0
 it('should promisify options 3', done => {
   request('a', {
     mutate () {
       return false
     }
   }).finally(done)
 })
示例#3
0
const shouldRenderCompo = (plugin) => new Promise((resolve, reject) => {
  request('/settings-manager/autoReload')
    .then(response => {
      plugin.preventComponentRendering = !response.autoReload;
      plugin.blockerComponentProps = {
        blockerComponentTitle: 'components.AutoReloadBlocker.header',
        blockerComponentDescription: 'components.AutoReloadBlocker.description',
        blockerComponentIcon: 'fa-refresh',
        blockerComponentContent: 'renderIde',
      };

      if (response.environment !== 'development') {
        plugin.preventComponentRendering = true;
        plugin.blockerComponentProps = {
          blockerComponentTitle: 'components.ProductionBlocker.header',
          blockerComponentDescription: 'components.ProductionBlocker.description',
          blockerComponentIcon: 'fa-ban',
          blockerComponentContent: 'renderButton',
        };
      }

      return resolve(plugin);
    })
    .catch(err => reject(err));
});
示例#4
0
文件: haha.js 项目: apersonw/oni-cli
export async function query (params) {
  return request({
    url: users,
    method: 'get',
    data: params,
  })
}
示例#5
0
window.podlovePlayer = (selector, episode, additional = {}) => {
  const node = findNode(selector)
  const nodeHtml = node.innerHTML
  node.innerHTML = ''

  return requestConfig(episode)
    .then(config =>
      Promise.resolve(merge(config, additional))
        .then(setPublicPath)
        .then(createPlayerDom)
        .then(sandboxFromSelector(node))
        // Set Title for accessibility
        .then(setAccessibilityAttributes(config))
        .then(resizer)
        .then(sandboxWindow(['PODLOVE_STORE']))
        .then(dispatchUrlParameters)
    )
    .catch(err => {
      node.innerHTML = nodeHtml
      console.group(`Can't load Podlove Webplayer ${version}`)
      console.error('selector', selector)
      console.error('config', episode)
      console.error(err)
      console.groupEnd()
    })
}
示例#6
0
 it('200', done => {
   request({
     url: ''
   }).then(json => {
     expect(json.hello).to.equal('world')
     done()
   })
 })
示例#7
0
 return dispatch => {
   request(`/orgs/${config.ownerName}`, {
     method: 'get'
   })
   .then(res => {
     if (res.name) return dispatch(getRepoOwnerNameSucces(res.name));
     return dispatch(getRepoOwnerNameError());
   })
 }
示例#8
0
  [INIT]: ({ dispatch }, { type, payload }) => {
    const transcriptsUrl = get(payload, 'transcripts')

    request(transcriptsUrl)
      .then(transformTranscript)
      .then(data => {
        return data
      })
      .catch(() => [])
      .then(compose(dispatch, actions.initTranscripts))
  },
示例#9
0
  getOptions = query => {
    const params = {
      limit: 20,
      skip: this.state.toSkip,
      source: this.props.relation.plugin || 'content-manager',
    };

    // Set `query` parameter if necessary
    if (query) {
      delete params.limit,
      delete params.skip,
      params[`${this.props.relation.displayedAttribute}_contains`] = query;
    }
    // Request URL
    const requestUrl = `/content-manager/explorer/${this.props.relation.model ||
      this.props.relation.collection}`;

    // Call our request helper (see 'utils/request')
    return request(requestUrl, {
      method: 'GET',
      params,
    })
      .then(response => {
        const options = isArray(response)
          ? response.map(item => ({
            value: item,
            label: templateObject({ mainField: this.props.relation.displayedAttribute }, item)
              .mainField,
          }))
          : [
            {
              value: response,
              label: response[this.props.relation.displayedAttribute],
            },
          ];

        const newOptions = cloneDeep(this.state.options);
        options.map(option => {
          // Don't add the values when searching
          if (findIndex(newOptions, o => o.value.id === option.value.id) === -1) {
            return newOptions.push(option);
          }
        });

        return this.setState({
          options: newOptions,
          isLoading: false,
        });
      })
      .catch(() => {
        strapi.notification.error('content-manager.notification.error.relationship.fetch');
      });
  };
示例#10
0
 it('should translate arguments', done => {
   let url
   request('a', {
     mutate (options) {
       url = options.url
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(url).to.equal('a')
     done()
   })
 })
示例#11
0
 it('403 with json', done => {
   window.fetch
     // .withArgs(...)
     .returns(Promise.resolve(new window.Response('{"hello":"world"}', {
       status: 403,
       headers
     })))
   request({
     url: ''
   }).catch(err => {
     expect(err.hello).to.equal('world')
     done()
   })
 })
示例#12
0
 it('404', done => {
   window.fetch
     // .withArgs(...)
     .returns(Promise.resolve(new window.Response('Not Found', {
       status: 404,
       statusText: 'Not Found'
     })))
   request({
     url: ''
   }).catch(err => {
     expect(err).to.equal('Not Found')
     done()
   })
 })
示例#13
0
 it('should NOT has question mark', done => {
   let url
   request({
     url: 'a',
     query: {},
     mutate (options) {
       url = options.url
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(url).to.equal('a')
     done()
   })
 })
示例#14
0
 loadLatestConfirmedBlocks() {
   request(this.props.blocksUrl)
     .then(blocks => {
       if (!this.blockList[blocks.data.hash]) {
         this.blocks.unshift(blocks.data);
         this.blockList[blocks.data.hash] = blocks.data;
         this.emptyUnconfirmedBlock.height = blocks.data.height + 1;
         this.setState({
           confirmedBlocks: this.blocks,
           unconfirmedBlock: this.emptyUnconfirmedBlock,
         });
       }
     });
 }
示例#15
0
 function makeRequest() {
   if (getState().app.pending) return;
   
   dispatch(getReposRequest());
   
   request(`/search/repositories?q=${value} in:name user:${config.ownerName}`, {
     method: 'get',
   })
   .then(res => {
     if (!res.items) return dispatch(getReposError());
     return dispatch(getReposSuccess(res.items));
   }, (res => {
     return dispatch(getReposError());
   }));
 }
示例#16
0
 it('should replace url with params', done => {
   let url
   request({
     url: '{y}a{x}b{{x}}',
     params: {
       x: 1
     },
     mutate (options) {
       url = options.url
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(url).to.equal('a1b{x}')
     done()
   })
 })
示例#17
0
 var videos = ids.map(function (id) {
     var video = {
         id: id,
         iFrameUrl: 'https://www.youtube.com/embed/' + id + '?autoplay=1&autohide=1&origin=http://davidmiles.se',
         image: 'url(http://i.ytimg.com/vi/' + id + '/mqdefault.jpg)',
         title: ko.observable(),
         width: '320px',
         height: '180px',
         fill: true
     };
     request('GET', 'https://www.googleapis.com/youtube/v3/videos?key=' + apiKey +
         '&fields=items(snippet(title))&part=snippet&id=' + video.id).end(function (result) {
         video.title(result.body.items[0].snippet.title);
     });
     return video;
 });
示例#18
0
 it('should add query to url 2', done => {
   let url
   request({
     url: 'a?x=1',
     query: {
       x: 1
     },
     mutate (options) {
       url = options.url
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(url).to.equal('a?x=1&x=1')
     done()
   })
 })
示例#19
0
 it('should serialize body 3', done => {
   let body
   request({
     method: 'POST',
     body: {
       x: 1
     },
     mutate (options) {
       body = options.body
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(body).to.equal('{"x":1}')
     done()
   })
 })
示例#20
0
 it('should serialize body', done => {
   let url
   let body
   request({
     body: {
       x: 1
     },
     mutate (options) {
       url = options.url
       body = options.body
       return Promise.resolve({})
     }
   }).finally(() => {
     expect(url).to.equal('?x=1')
     expect(body).to.equal(undefined)
     done()
   })
 })
示例#21
0
const bootstrap = (plugin) => new Promise((resolve, reject) => {
  request('/content-manager/models', { method: 'GET' })
    .then(models => {
      const menu = [{
        name: 'Content Types',
        links: map(omit(models.models.models, 'plugins'), (model, key) => ({
          label: model.labelPlural || model.label || key,
          destination: key,
        })),
      }];
      plugin.leftMenuSections = menu;
      resolve(plugin);
    })
    .catch(e => {
      strapi.notification.error('content-manager.error.model.fetch');
      reject(e);
    });
});
示例#22
0
文件: index.js 项目: oneuptim/strapi
  getOptions = (query) => {
    const params = {
      limit: 20,
      source: this.props.relation.plugin || 'content-manager',
    };

    // Set `query` parameter if necessary
    if (query) {
      params.query = query;
      params.queryAttribute = this.props.relation.displayedAttribute;
    }

    // Request URL
    const requestUrlSuffix = query && this.props.record.get(this.props.relation.alias).toJS() ? this.props.record.get(this.props.relation.alias).toJS() : '';
    const requestUrl = `/content-manager/explorer/${this.props.relation.model || this.props.relation.collection}/${requestUrlSuffix}`;

    // Call our request helper (see 'utils/request')
    return request(requestUrl, {
      method: 'GET',
      params,
    })
      .then(response => {
        const options = isArray(response) ?
          response.map(item => ({
            value: item,
            label: templateObject({ mainField: this.props.relation.displayedAttribute }, item).mainField,
          })) :
          [{
            value: response,
            label: response[this.props.relation.displayedAttribute],
          }];

        return { options };
      })
      .catch(() => {
        strapi.notification.error('content-manager.notification.error.relationship.fetch');
      });
  }
示例#23
0
import request from 'utils/request';

const url = '/api/game';

const api = {
  create(data) {
    return request({
      method: 'post',
      url: url,
      data: data
    });
  },
  query(data) {
    return request({
      method: 'get',
      url: url,
      params: data
    });
  },
  getUserGameData(data) {
    return request({
      method: 'get',
      url: url,
      params: data
    });
  },
};
export default api;
示例#24
0
文件: env.js 项目: aiso/xiansda-vue
  },

  [SET_ENV_I18N] (state, { payload, meta }) {
    if (meta === PROMISE_SUCCESS) {
      Object.assign(state, {
        i18n: payload
      })
      localEnv.set(state)
    }
  }
}

const actions = {
  setEnv ({ commit }, payload) {
    commit(SET_ENV, payload)

    if (payload.lang) {
      commit(SET_ENV_I18N, request(`./i18n/${payload.lang}.json`, {
        proxyFlag : false
      }))
    }
  }
}

export default {
  state,
  getters,
  actions,
  mutations
}
示例#25
0
 it('should NOT ok', () => {
   expect(request()).to.equal(undefined)
   expect(request('a', 'b')).to.equal(undefined)
   expect(request(false)).to.equal(undefined)
 })
示例#26
0
 it('should ok', done => {
   request('a').then(json => {
     expect(json.hello).to.equal('world')
     done()
   })
 })