<commit_before>import { IMyInfoService } from './IMyInfoService';
import { IMyInfo } from './IMyInfo';

import { IWebPartContext } from '@microsoft/sp-webpart-base';

export default class MyInfoService implements IMyInfoService {

    private context: IWebPartContext;
    constructor(context: IWebPartContext) {
        this.context = context;
    }

    public get(): Promise<IMyInfo | string> {
        return new Promise<IMyInfo>((resolve) => {
        
            Promise.all([
                this.getName(),
                this.getLists(),
                this.getCustomers()
            ]).then((values) => {
                resolve ({
                    myName: values[0],
                    spListNames: values[1],
                    customers: values[2]
                });
            });
        });
    }

    private getName(): Promise<string> {
        return new Promise<string>((resolve) => {
            resolve("<NAME>");
        });
    }

    private getLists(): Promise<string[]> {
        return new Promise<string[]>((resolve) => {
            resolve(["List Alpha", "List B", "List C"]);
        });
    }

    private getCustomers(): Promise<string[]> {
        return new Promise<string[]>((resolve) => {
            let query = "http://services.odata.org/Northwind/Northwind.svc/Customers/?$top=10";

            var myInit: RequestInit = {
                method: 'GET',
                headers: {"accept": "application/json"},
                mode: 'cors',
                cache: 'default' 
            };

            fetch(query, myInit).then ((response) => {
                response.json().then((o) => {
                    let result = o.value.map((v) => { return v.CompanyName; });
                    resolve(result);
                });
            });
        });
    }
}<commit_msg>Added SPHttpClient example<commit_after>import { IMyInfoService } from './IMyInfoService';
import { IMyInfo } from './IMyInfo';

import { IWebPartContext } from '@microsoft/sp-webpart-base';
import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';

export default class MyInfoService implements IMyInfoService {

    private context: IWebPartContext;
    constructor(context: IWebPartContext) {
        this.context = context;
    }

    public get(): Promise<IMyInfo | string> {
        return new Promise<IMyInfo>((resolve) => {
        
            Promise.all([
                this.getName(),
                this.getLists(),
                this.getCustomers()
            ]).then((values) => {
                resolve ({
                    myName: values[0],
                    spListNames: values[1],
                    customers: values[2]
                });
            });
        });
    }

    private getName(): Promise<string> {
        return new Promise<string>((resolve) => {
            resolve("<NAME>");
        });
    }

    // Example using SPHttpClient - local SharePoint site
    // import { SPHttpClient, SPHttpClientResponse } from '@microsoft/sp-http';
    private getLists(): Promise<string[]> {
        return new Promise<string[]>((resolve) => {
            this.context.spHttpClient.fetch(
                this.context.pageContext.web.absoluteUrl +
                    "/_api/lists?$filter=Hidden%20eq%20false",
                SPHttpClient.configurations.v1,
                {
                    method: "GET"
                }
            )
            .then((response: SPHttpClientResponse) => {
                response.json().then((o) => {
                    let result = o.value.map((v) => { return v.Title; });
                    resolve(result);
                });                
            });
        });
    }

    // Example using simple fetch - Northwind DB
    private getCustomers(): Promise<string[]> {
        return new Promise<string[]>((resolve) => {
            let query = "http://services.odata.org/Northwind/Northwind.svc/Customers/?$top=10";

            var myInit: RequestInit = {
                method: 'GET',
                headers: {"accept": "application/json"},
                mode: 'cors',
                cache: 'default' 
            };

            // NOTE: you could use this.context.HttpClient.fetch() - same thing
            fetch(query, myInit).then ((response) => {
                response.json().then((o) => {
                    let result = o.value.map((v) => { return v.CompanyName; });
                    resolve(result);
                });
            });
        });
    }
}
{'fraction_non_alphanumeric': 0.13839681133746679, 'fraction_numerical': 0.003321523472099203, 'mean_word_length': 1.5650198750709825, 'pattern_counts': {'":': 2, '<': 21, '<?xml version=': 0, '>': 40, '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': '530466', 'n_tokens_mistral': 1231, 'n_tokens_neox': 1160, 'n_words': 228}