<commit_before>// @flow

import StaticMap                                                    from './static-map.js';
import StaticMapLocation,         { makeStaticMapLocation         } from './location.js';
import StaticMapMarkerCollection, { makeStaticMapMarkerCollection } from './marker-collection.js';
import StaticMapStyle,            { makeStaticMapStyle            } from './style.js';

export default class StaticMapAuthenticatedFactory {

    apiKey: string;

    constructor(apiKey: string) {
        this.apiKey = apiKey;
    }

    makeStaticMap(width: number, height: number): StaticMap {
        const staticMap = new StaticMap(width, height);
        staticMap.apiKey(this.apiKey);
        return staticMap;
    }
<commit_msg>src/static-map/authenticated-factory.js: add "client credentials" auth<commit_after>// @flow

//----------------------------------------------------------------------//
//                         Import local modules                         //
//----------------------------------------------------------------------//

import StaticMap                                                     from './static-map.js';
import StaticMapLocation,         { makeStaticMapLocation          } from './location.js';
import StaticMapMarkerCollection, { makeStaticMapMarkerCollection  } from './marker-collection.js';
import StaticMapStyle,            { makeStaticMapStyle             } from './style.js';
import type { TypeAuthDataApiKey, TypeAuthDataClient, TypeAuthData } from './types.js';


//----------------------------------------------------------------------//
//                            Exported class                            //
//----------------------------------------------------------------------//

export default class StaticMapAuthenticatedFactory {

    auth: TypeAuthData;

    /** @private */
    constructor(auth: TypeAuthData) {
        this.auth = auth;
    }

    static usingApiKey(apiKey: string): StaticMapAuthenticatedFactory {
        const auth: TypeAuthDataApiKey = { type: 'apiKey', apiKey };
        return new StaticMapAuthenticatedFactory(auth);
    }

    static usingClientCredentials(clientId: string, clientSecret: string): StaticMapAuthenticatedFactory {
        const auth: TypeAuthDataClient = { type: 'client', clientId, clientSecret };
        return new StaticMapAuthenticatedFactory(auth);
    }

    makeStaticMap(width: number, height: number): StaticMap {

        const staticMap = new StaticMap(width, height);

        /** @see flowtype.org/docs/disjoint-unions.html */
        switch (this.auth.type) {
            case 'apiKey':
                staticMap.setApiKey(this.auth.apiKey);
                break;
            case 'client':
                staticMap.setClientCredentials(this.auth.clientId, this.auth.clientSecret);
                break;
        }

        return staticMap;

    }

{'fraction_non_alphanumeric': 0.18875780707841777, 'fraction_numerical': 0.0, 'mean_word_length': 1.5535872453498671, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, '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': '6526738', 'n_tokens_mistral': 689, 'n_tokens_neox': 651, 'n_words': 146}