<commit_before>import OAuth2 from 'client-oauth2'
import JsonApi from 'devour-client'
const baseUrl = process.env.KITSU_HOST + '/api'

class Kitsu {
  constructor() {
    this.auth = new OAuth2({
      clientId: process.env.KITSU_CLIENT,
      clientSecret: process.env.KITSU_SECRET,
      accessTokenUri: baseUrl + '/oauth/token'
    })

    this.jsonApi = new JsonApi({ apiUrl: baseUrl + '/edge' })

    this.jsonApi.define('user', {
      name: '',
      about: '',
      website: '',
      waifuOrHusbando: '',
      waifu: {
        jsonApi: 'hasOne',
        type: 'characters'
      },
      gender: '',
      location: '',
      birthday: '',
      createdAt: '',
      followersCount: '',
      followingCount: '',
      lifeSpentOnAnime: '',
      avatar: { medium: '' }
    })

    this.jsonApi.define('character', {
      name: ''
    })

    this.jsonApi.define('follow', {
      follower: {
        jsonApi: 'hasOne',
        type: 'users'
      },
      followed: {
        jsonApi: 'hasOne',
        type: 'users'
      }
    })

    this.jsonApi.define('anime', {
      canonicalTitle: '',
      slug: '',
      synopsis: '',
      averageRating: '',
      posterImage: { large: '' },
      episodeCount: '',
      episodeLength: '',
      showType: '',
      startDate: '',
      ageRating: '',
      ageRatingGuide: '',
      nsfw: '',
      youtubeVideoId: '',
      genres: {
        jsonApi: 'hasMany',
        type: 'genres'
      }
    }, { collectionPath: 'anime' })

    this.jsonApi.define('manga', {
      canonicalTitle: '',
      slug: '',
      synopsis: '',
      averageRating: '',
      posterImage: { large: '' },
      chapterCount: '',
      volumeCount: '',
      mangaType: '',
      startDate: '',
      genres: {
        jsonApi: 'hasMany',
        type: 'genres'
      }
    }, { collectionPath: 'manga' })

    this.jsonApi.define('genre', {
      name: ''
    })

    this.jsonApi.define('libraryEntry', {
      status: '',
      progress: '',
      reconsuming: '',
      reconsumeCount: '',
      private: '',
      rating: '',
      media: {
        jsonApi: 'hasOne'
      },
      user: {
        jsonApi: 'hasOne',
        type: 'users'
      }
    }, { collectionPath: 'library-entries' })
  }

  authenticate(token) {
    this.jsonApi.headers['Authorization'] = `Bearer ${token}`
  }

  unauthenticate() {
    delete this.jsonApi.headers['Authorization']
  }

  login(username, password) {
    return this.auth.owner.getToken(username, password)
  }

  getUser(id) {
    return this.jsonApi.find('user', id)
  }

  searchUsers(query) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('user', {
        filter: { query },
        include: 'waifu',
        page: { limit: 1 }
      }).then((users) => {
        pass(users[0])
      })
    })
  }

  searchAnime(text) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('anime', {
        filter: { text },
        include: 'genres',
        page: { limit: 1 }
      }).then((anime) => {
        pass(anime[0])
      })
    })
  }

  searchManga(text) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('manga', {
        filter: { text },
        include: 'genres',
        page: { limit: 1 }
      }).then((manga) => {
        pass(manga[0])
      })
    })
  }

  searchFollows(follower, followed) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('follow', {
        filter: { follower, followed },
        include: 'follower,followed'
      }).then((follows) => {
        pass(follows[0])
      })
    })
  }

  createFollow(follow) {
    return this.jsonApi.create('follow', follow)
  }

  removeFollow(id) {
    return this.jsonApi.destroy('follow', id)
  }

  createEntry(entry) {
    return this.jsonApi.create('libraryEntry', entry)
  }

  getEntry(id) {
    return this.jsonApi.find('libraryEntry', id)
  }

  getEntryForMedia(type, userId, mediaId) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('libraryEntry', {
        filter: { userId, mediaId },
        include: 'media'
      }).then((entries) => {
        entries = entries.filter((entry) => {
          return entry.media.type == type
        })
        pass(entries[0])
      })
    })
  }

  updateEntry(entry) {
    return this.jsonApi.update('libraryEntry', entry)
  }

  removeEntry(id) {
    return this.jsonApi.destroy('libraryEntry', id)
  }
}

module.exports = Kitsu
<commit_msg>set user agent<commit_after>import OAuth2 from 'client-oauth2'
import JsonApi from 'devour-client'
const baseUrl = process.env.KITSU_HOST + '/api'

class Kitsu {
  constructor() {
    this.auth = new OAuth2({
      clientId: process.env.KITSU_CLIENT,
      clientSecret: process.env.KITSU_SECRET,
      accessTokenUri: baseUrl + '/oauth/token'
    })

    this.jsonApi = new JsonApi({ apiUrl: baseUrl + '/edge' })

    this.jsonApi.headers['User-Agent'] = 'Slack/1.0.0'

    this.jsonApi.define('user', {
      name: '',
      about: '',
      website: '',
      waifuOrHusbando: '',
      waifu: {
        jsonApi: 'hasOne',
        type: 'characters'
      },
      gender: '',
      location: '',
      birthday: '',
      createdAt: '',
      followersCount: '',
      followingCount: '',
      lifeSpentOnAnime: '',
      avatar: { medium: '' }
    })

    this.jsonApi.define('character', {
      name: ''
    })

    this.jsonApi.define('follow', {
      follower: {
        jsonApi: 'hasOne',
        type: 'users'
      },
      followed: {
        jsonApi: 'hasOne',
        type: 'users'
      }
    })

    this.jsonApi.define('anime', {
      canonicalTitle: '',
      slug: '',
      synopsis: '',
      averageRating: '',
      posterImage: { large: '' },
      episodeCount: '',
      episodeLength: '',
      showType: '',
      startDate: '',
      ageRating: '',
      ageRatingGuide: '',
      nsfw: '',
      youtubeVideoId: '',
      genres: {
        jsonApi: 'hasMany',
        type: 'genres'
      }
    }, { collectionPath: 'anime' })

    this.jsonApi.define('manga', {
      canonicalTitle: '',
      slug: '',
      synopsis: '',
      averageRating: '',
      posterImage: { large: '' },
      chapterCount: '',
      volumeCount: '',
      mangaType: '',
      startDate: '',
      genres: {
        jsonApi: 'hasMany',
        type: 'genres'
      }
    }, { collectionPath: 'manga' })

    this.jsonApi.define('genre', {
      name: ''
    })

    this.jsonApi.define('libraryEntry', {
      status: '',
      progress: '',
      reconsuming: '',
      reconsumeCount: '',
      private: '',
      rating: '',
      media: {
        jsonApi: 'hasOne'
      },
      user: {
        jsonApi: 'hasOne',
        type: 'users'
      }
    }, { collectionPath: 'library-entries' })
  }

  authenticate(token) {
    this.jsonApi.headers['Authorization'] = `Bearer ${token}`
  }

  unauthenticate() {
    delete this.jsonApi.headers['Authorization']
  }

  login(username, password) {
    return this.auth.owner.getToken(username, password)
  }

  getUser(id) {
    return this.jsonApi.find('user', id)
  }

  searchUsers(query) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('user', {
        filter: { query },
        include: 'waifu',
        page: { limit: 1 }
      }).then((users) => {
        pass(users[0])
      })
    })
  }

  searchAnime(text) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('anime', {
        filter: { text },
        include: 'genres',
        page: { limit: 1 }
      }).then((anime) => {
        pass(anime[0])
      })
    })
  }

  searchManga(text) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('manga', {
        filter: { text },
        include: 'genres',
        page: { limit: 1 }
      }).then((manga) => {
        pass(manga[0])
      })
    })
  }

  searchFollows(follower, followed) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('follow', {
        filter: { follower, followed },
        include: 'follower,followed'
      }).then((follows) => {
        pass(follows[0])
      })
    })
  }

  createFollow(follow) {
    return this.jsonApi.create('follow', follow)
  }

  removeFollow(id) {
    return this.jsonApi.destroy('follow', id)
  }

  createEntry(entry) {
    return this.jsonApi.create('libraryEntry', entry)
  }

  getEntry(id) {
    return this.jsonApi.find('libraryEntry', id)
  }

  getEntryForMedia(type, userId, mediaId) {
    return new Promise((pass, fail) => {
      this.jsonApi.findAll('libraryEntry', {
        filter: { userId, mediaId },
        include: 'media'
      }).then((entries) => {
        entries = entries.filter((entry) => {
          return entry.media.type == type
        })
        pass(entries[0])
      })
    })
  }

  updateEntry(entry) {
    return this.jsonApi.update('libraryEntry', entry)
  }

  removeEntry(id) {
    return this.jsonApi.destroy('libraryEntry', id)
  }
}

module.exports = Kitsu

{'fraction_non_alphanumeric': 0.1662022071118047, 'fraction_numerical': 0.0027867573291717757, 'mean_word_length': 2.0778730703259005, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '6364113', 'n_tokens_mistral': 2994, 'n_tokens_neox': 2930, 'n_words': 490}