<commit_before>// Dollar Street API encapsulation

// API urls and routes
const dsUrl = "https://ds-dev.dollarstreet.org/dollar-street/v1/";
const dsLanguages = "languagesList";
const dsLanguage = "language?lang=";
const dsStreetSettings = "street-settings";
const dsRegions = "countries-filter?thing=Families&countries=World&regions=World&lang=";
const dsThings = "things-filter?thing=Families&countries=World&regions=World&lang=";

// Main component
Vue.component("dollarstreet-api", {
	name: "DollarStreetAPI",
	data: function() {
		return {
			language: "en",
			l10n: {},
			streetSettings: {},
			regions: [],
			things: []
		}
	},

	mounted() {
		let vm = this;

		// Find matching language
		_dsAPIGet(dsLanguages).then(function(result) {
			requirejs(["sugar-web/env"], function(env) {
				env.getEnvironment(function(err, environment) {
					// Set language
					var defaultLanguage = navigator.language;
					var language = environment.user ? environment.user.language : defaultLanguage;
					for (let i = 0 ; i < result.length ; i++) {
						if (result[i].code.indexOf(language) == 0) {
							vm.language = result[i].code;
							break;
						}
					}

					// Initialize data set
					Promise.all([
						_dsAPIGet(dsLanguage+vm.language),
						_dsAPIGet(dsStreetSettings),
						_dsAPIGet(dsRegions+vm.language),
						_dsAPIGet(dsThings+vm.language),
					]).then(function (results) {
						vm.l10n = results[0];
						vm.streetSettings = results[1];
						vm.regions = results[2];
						vm.things = results[3].otherThings;
						vm.$emit("initialized");
 					}).catch(function(error) {
						vm.$emit("error");
					});
				});
			});
		}).catch(function(error) {
			vm.$emit("error");
		})
	},

	methods: {
		// Get a localized string by id
		getL10n: function(id) {
			return this.l10n[id];
		},

		// Get regions
		getRegions: function() {
			return this.regions;
		},

		// Get things
		getThings: function() {
			return this.things;<commit_msg>Find thing by id, add family<commit_after>// Dollar Street API encapsulation

// API urls and routes
const dsUrl = "https://ds-dev.dollarstreet.org/dollar-street/v1/";
const dsLanguages = "languagesList";
const dsLanguage = "language?lang=";
const dsStreetSettings = "street-settings";
const dsRegions = "countries-filter?thing=Families&countries=World&regions=World&lang=";
const dsThings = "things-filter?thing=Families&countries=World&regions=World&lang=";

// Main component
Vue.component("dollarstreet-api", {
	name: "DollarStreetAPI",
	data: function() {
		return {
			language: "en",
			l10n: {},
			streetSettings: {},
			regions: [],
			things: [],
			familyThing: {}
		}
	},

	mounted() {
		let vm = this;

		// Find matching language
		_dsAPIGet(dsLanguages).then(function(result) {
			requirejs(["sugar-web/env"], function(env) {
				env.getEnvironment(function(err, environment) {
					// Set language
					var defaultLanguage = navigator.language;
					var language = environment.user ? environment.user.language : defaultLanguage;
					for (let i = 0 ; i < result.length ; i++) {
						if (result[i].code.indexOf(language) == 0) {
							vm.language = result[i].code;
							break;
						}
					}

					// Initialize data set
					Promise.all([
						_dsAPIGet(dsLanguage+vm.language),
						_dsAPIGet(dsStreetSettings),
						_dsAPIGet(dsRegions+vm.language),
						_dsAPIGet(dsThings+vm.language),
					]).then(function (results) {
						vm.l10n = results[0];
						vm.streetSettings = results[1];
						vm.regions = results[2];
						vm.things = results[3].otherThings;
						vm.thing = results[3].thing;
						vm.$emit("initialized");
 					}).catch(function(error) {
						vm.$emit("error");
					});
				});
			});
		}).catch(function(error) {
			vm.$emit("error");
		})
	},

	methods: {
		// Get a localized string by id
		getL10n: function(id) {
			return this.l10n[id];
		},

		// Get regions
		getRegions: function() {
			return this.regions;
		},

		// Get things
		getThings: function() {
			return this.things;
		},

		// Find a thing by id
		getThingById: function(id) {
			let vm = this;
			for (let i = 0 ; i < vm.things.length ; i++) {
				let current = vm.things[i];
				if (current._id == id) {
					return current;
				}
			}
			return null;
		},

		// Get family thing
		getFamily: function() {
			return this.familyThing;
{'fraction_non_alphanumeric': 0.15464632454923716, 'fraction_numerical': 0.007397133610725843, 'mean_word_length': 3.082075471698113, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 3, 'https://': 2, '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': '7146253', 'n_tokens_mistral': 1855, 'n_tokens_neox': 1422, 'n_words': 285}