<commit_before>import Ember from "ember";
import layout from "../../templates/components/nypr-accounts/membership-card";
import computed from "ember-computed";
import moment from "moment";
import service from 'ember-service/inject';

export default Ember.Component.extend({
  layout,
  session: service(),
  taxLetterUrl: computed(function() {
    let config = Ember.getOwner(this).resolveRegistration('config:environment');
    let urlRoot = config.membershipAPI || "https://api.wnyc.org";
    return `${urlRoot}/v1/taxes`;
  }),
  previousYear: computed(function() {
    return moment()
      .subtract(1, "year")
      .year();
  }),
  hasPledgesInPastTaxYear: computed.filter("pledges", function(pledge) {
    let previousYear = moment().subtract(1, "year").year();
    let pledgeYear = pledge.orderDate || pledge.get("orderDate").year();
    return moment(pledgeYear == previousYear);
  }),
  actions: {
    downloadTaxLetter() {
      this.get('session').authorize('authorizer:nypr', (header, value) => {
        Ember.$.ajax({
          url: "https://api.demo.nypr.digital/membership/v1/taxes",
          beforeSend: function(xhr){xhr.setRequestHeader(header, value);},
          type: "GET",
          success: function(data, textStatus, jqxhr) {
            // Create data blob from response
            var blob = new Blob([data], {type: "application/pdf"});
            var url = window.URL.createObjectURL(blob);

            // Create hidden <a>, click on it, remove it
            var a = document.createElement("a");
            document.body.appendChild(a);
            a.style = "display: none";
            a.href = url;
            a.download = "NYPR_Tax_Documentation.pdf";
            a.click();
            window.URL.revokeObjectURL(url);

          }
        });
      });
    }
  }<commit_msg>Fix blank PDF issue w/ arrayBuffer<commit_after>import Ember from "ember";
import layout from "../../templates/components/nypr-accounts/membership-card";
import computed from "ember-computed";
import moment from "moment";
import service from 'ember-service/inject';

export default Ember.Component.extend({
  layout,
  session: service(),
  taxLetterUrl: computed(function() {
    let config = Ember.getOwner(this).resolveRegistration('config:environment');
    let urlRoot = config.membershipAPI || "https://api.wnyc.org";
    return `${urlRoot}/v1/taxes`;
  }),
  previousYear: computed(function() {
    return moment()
      .subtract(1, "year")
      .year();
  }),
  hasPledgesInPastTaxYear: computed.filter("pledges", function(pledge) {
    let previousYear = moment().subtract(1, "year").year();
    let pledgeYear = pledge.orderDate || pledge.get("orderDate").year();
    return moment(pledgeYear == previousYear);
  }),
  actions: {
    downloadTaxLetter() {
      this.get('session').authorize('authorizer:nypr', (header, value) => {
        let taxLetterUrl = this.get("taxLetterUrl");
        let fetchOptions = {};
        fetchOptions[header] = value;

        fetch(taxLetterUrl, fetchOptions).then(response => {
          response.arrayBuffer().then(data =>{
            var blob = new Blob([data], {type: "application/pdf"});
            var url = window.URL.createObjectURL(blob);

            // Create hidden <a>, click on it, remove it
            var a = document.createElement("a");
            document.body.appendChild(a);
            a.href = url;
            a.download = "NYPR_Tax_Documentation.pdf";
            a.click();
            window.URL.revokeObjectURL(url);
          });
        })
      });
    }
  }
{'fraction_non_alphanumeric': 0.15116605788142737, 'fraction_numerical': 0.001966844619275077, 'mean_word_length': 2.8320775026910656, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '522749', 'n_tokens_mistral': 1046, 'n_tokens_neox': 1026, 'n_words': 215}