Example #1
0
export function getCharacters(platform) {
  const charactersPromise = $http(bungieApiQuery(
    `/D1/Platform/Destiny/${platform.platformType}/Account/${platform.membershipId}/`
  ))
      .then(handleErrors, handleErrors)
      .then(processBnetCharactersRequest);

  return charactersPromise;

  function processBnetCharactersRequest(response) {
    if (!response.data || _.size(response.data.Response) === 0) {
      throw error(t('BungieService.NoAccountForPlatform', {
        platform: platform.label
      }), 1601);
    }

    return _.map(response.data.Response.data.characters, (c: any) => {
      c.inventory = response.data.Response.data.inventory;

      return {
        id: c.characterBase.characterId,
        base: c
      };
    });
  }
}
Example #2
0
 const promises = characters.map((character) => {
   return $http(bungieApiQuery(
     `/D1/Platform/Destiny/${platform.platformType}/Account/${platform.membershipId}/Character/${character.id}/Inventory/`
   ))
     .then(handleErrors, handleErrors)
     .then((response) => processInventoryResponse(character, response));
 });
Example #3
0
export function equipItems(store, items) {
  // Sort exotics to the end. See https://github.com/DestinyItemManager/DIM/issues/323
  items = _.sortBy(items, (i: any) => {
    return i.isExotic ? 1 : 0;
  });

  const platform = getActivePlatform();
  return $http(bungieApiUpdate(
    '/D1/Platform/Destiny/EquipItems/',
    {
      characterId: store.id,
      membershipType: platform!.platformType,
      itemIds: items.map((i) => i.id)
    }))
    .then(retryOnThrottled)
    .then(handleErrors, handleErrors)
    .then((response) => {
      const data: any = response.data.Response;
      store.updateCharacterInfoFromEquip(data.summary);
      return items.filter((i: any) => {
        const item = data.equipResults.find((r) => r.itemInstanceId === i.id);
        return item && item.equipStatus === 1;
      });
    });
}
Example #4
0
export function transfer(item, store, amount) {
  const platform = getActivePlatform();
  const promise = $http(bungieApiUpdate(
    '/D1/Platform/Destiny/TransferItem/',
    {
      characterId: store.isVault ? item.owner : store.id,
      membershipType: platform!.platformType,
      itemId: item.id,
      itemReferenceHash: item.hash,
      stackSize: amount || item.amount,
      transferToVault: store.isVault
    }
  ))
    .then(retryOnThrottled)
    .then(handleErrors, handleErrors)
    .catch((e) => {
      return handleUniquenessViolation(e, item, store);
    });

  return promise;

  // Handle "DestinyUniquenessViolation" (1648)
  function handleUniquenessViolation(e, item, store) {
    if (e && e.code === 1648) {
      throw error(t('BungieService.ItemUniquenessExplanation', {
        name: item.name,
        type: item.type.toLowerCase(),
        character: store.name,
        context: store.gender
      }), e.code);
    }
    return $q.reject(e);
  }
}
Example #5
0
export function getVendorForCharacter(account, character, vendorHash) {
  return $http(bungieApiQuery(
    `/D1/Platform/Destiny/${account.platformType}/MyAccount/Character/${character.id}/Vendor/${vendorHash}/`
  ))
    .then(handleErrors, handleErrors)
    .then((response: any) => response.data.Response.data);
}
Example #6
0
export function equip(item) {
  const platform = getActivePlatform();
  return $http(bungieApiUpdate(
    '/D1/Platform/Destiny/EquipItem/',
    {
      characterId: item.owner,
      membershipType: platform!.platformType,
      itemId: item.id
    }
  ))
    .then(retryOnThrottled)
    .then(handleErrors, handleErrors);
}
Example #7
0
export function getGlobalAlerts(): IPromise<GlobalAlert[]> {
  return $http(bungieApiQuery(`/Platform/GlobalAlerts/`))
    .then((response: IHttpResponse<ServerResponse<any>>) => {
      if (response && response.data && response.data.Response) {
        return response.data.Response.map((alert) => {
          return {
            key: alert.AlertKey,
            type: GlobalAlertLevelsToToastLevels[alert.AlertLevel],
            body: alert.AlertHtml,
            timestamp: alert.AlertTimestamp
          };
        });
      }
      return [];
    });
}
Example #8
0
export function setItemState(item, store, lockState, type) {
  switch (type) {
  case 'lock':
    type = 'SetLockState';
    break;
  case 'track':
    type = 'SetQuestTrackedState';
    break;
  }

  const platform = getActivePlatform();
  return $http(bungieApiUpdate(
    `/D1/Platform/Destiny/${type}/`,
    {
      characterId: store.isVault ? item.owner : store.id,
      membershipType: platform!.platformType,
      itemId: item.id,
      state: lockState
    }
  ))
    .then(retryOnThrottled)
    .then(handleErrors, handleErrors);
}
Example #9
0
  function getDestinyInventories(platform, characters) {
    // Guardians
    const promises = characters.map((character) => {
      return $http(bungieApiQuery(
        `/D1/Platform/Destiny/${platform.platformType}/Account/${platform.membershipId}/Character/${character.id}/Inventory/`
      ))
        .then(handleErrors, handleErrors)
        .then((response) => processInventoryResponse(character, response));
    });

    // Vault
    const vault = {
      id: 'vault',
      base: null
    };

    const vaultPromise = $http(bungieApiQuery(`/D1/Platform/Destiny/${platform.platformType}/MyAccount/Vault/`))
      .then(handleErrors, handleErrors)
        .then((response) => processInventoryResponse(vault, response));

    promises.push(vaultPromise);

    return $q.all(promises);
  }
Example #10
0
export function httpAdapterWithRetry(config: HttpClientConfig): Promise<any> {
  return $http(buildOptions(config))
      .then(handleErrors, handleErrors)
      .then(retryOnThrottled)
      .then((response) => response.data) as Promise<any>;
}