<commit_before>import axios from 'axios'
import { createClient } from 'contentful'

export default class Api {
  constructor (spaceId, accessToken) {
    this.client = createClient({
      space: spaceId,
      accessToken
    })
  }

  fetchLeaders () {
    const select = [
      'fields.ward',
      'fields.subWard',
      'fields.party',
      'fields.fullName',
      'fields.photo',
      'fields.registeredVotersParty',
      'fields.turnoutParty',
      'fields.divisionCount',
      'fields.committeePersonCount'
    ]
    const opts = {
      content_type: 'wardLeader',
      order: 'fields.ward',
      select: select.join(','),
      limit: 1000
    }
    return this.client.getEntries(opts)
      .then((response) => response.items.map(getFieldsAndId))
      .then((items) => items.map(simplifyLinkedPhoto))
  }

  fetchLeader (ward, subWard, party) {
    const requestOpts = {
      content_type: 'wardLeader',
      'fields.ward': ward,
      'fields.party': party
    }
    if (subWard) requestOpts['fields.subWard'] = subWard

    return this.client.getEntries(requestOpts)
    .then((response) => {
      if (response.items.length > 0) {
        return simplifyLinkedPhoto(getFieldsAndId(response.items[0]))
      } else {
        throw new Error('Ward leader was not found')
      }
    })
  }

  fetchSampleBallots (ward, subWard, party) {
    const requestOpts = {
      content_type: 'sampleBallot',
      'fields.ward': ward,
      'fields.party': party,
      'fields.isApproved': true
    }
    if (subWard) requestOpts['fields.subWard'] = subWard

    return this.client.getEntries(requestOpts)
    .then((response) => response.items.map(getFieldsAndId))<commit_msg>Revert "Only show approved sample ballots"<commit_after>import axios from 'axios'
import { createClient } from 'contentful'

export default class Api {
  constructor (spaceId, accessToken) {
    this.client = createClient({
      space: spaceId,
      accessToken
    })
  }

  fetchLeaders () {
    const select = [
      'fields.ward',
      'fields.subWard',
      'fields.party',
      'fields.fullName',
      'fields.photo',
      'fields.registeredVotersParty',
      'fields.turnoutParty',
      'fields.divisionCount',
      'fields.committeePersonCount'
    ]
    const opts = {
      content_type: 'wardLeader',
      order: 'fields.ward',
      select: select.join(','),
      limit: 1000
    }
    return this.client.getEntries(opts)
      .then((response) => response.items.map(getFieldsAndId))
      .then((items) => items.map(simplifyLinkedPhoto))
  }

  fetchLeader (ward, subWard, party) {
    const requestOpts = {
      content_type: 'wardLeader',
      'fields.ward': ward,
      'fields.party': party
    }
    if (subWard) requestOpts['fields.subWard'] = subWard

    return this.client.getEntries(requestOpts)
    .then((response) => {
      if (response.items.length > 0) {
        return simplifyLinkedPhoto(getFieldsAndId(response.items[0]))
      } else {
        throw new Error('Ward leader was not found')
      }
    })
  }

  fetchSampleBallots (ward, subWard, party) {
    const requestOpts = {
      content_type: 'sampleBallot',
      'fields.ward': ward,
      'fields.party': party
    }
    if (subWard) requestOpts['fields.subWard'] = subWard

    return this.client.getEntries(requestOpts)
    .then((response) => response.items.map(getFieldsAndId))
{'fraction_non_alphanumeric': 0.13091016548463358, 'fraction_numerical': 0.0035460992907801418, 'mean_word_length': 2.8076490438695165, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2708553', 'n_tokens_mistral': 1096, 'n_tokens_neox': 1070, 'n_words': 206}