<commit_before>import {Injectable} from '@angular/core';

declare var FB: any;

// TODO create an interface (type) for the response instead of any

@Injectable()
export class FacebookService {

    /**
     * This method is used to initialize and setup the SDK.
     * @param params
     */
    init(params: FacebookInitParams): void {
        FB.init(params);
    }

    /**
     * This method lets you make calls to the Graph API
     * @param path This is the Graph API endpoint path that you want to call.
     * @param method This is the HTTP method that you want to use for the API request.
     * @param params This is an object consisting of any parameters that you want to pass into your Graph API call.
     * @returns {Promise<any>}
     */
    api(path: string, method?: FacebookApiMethod = 'get', params?: any = {}): Promise<any> {
        return new Promise<any>(
            (resolve, reject) => {
                FB.api(path, method, params, (response: any) => {
                    if(!response){
                        reject();
                    }else if(response.error){
                        reject(response.error);
                    }else{
                        resolve(response);
                    }
                });
            }
        );
    }

    /**
     * This method is used to trigger different forms of Facebook created UI dialogs.
     * These dialogs include:
     * - Share dialog
     * - Login dialog
     * - Add page tab dialog
     * - Requests dialog
     * - Send dialog
     * - Payments dialog
     * - Go Live dialog
     * @param params A collection of parameters that control which dialog is loaded, and relevant settings.
     * @returns {Promise<any>}
     */
    ui(params: FacebookUiParams): Promise<any> {
        return new Promise<any>(
            (resolve, reject) => {
                FB.ui(params, (response: any) => {
                    if(!response) reject();
                    else if(response.error) reject(response.error);
                    else resolve(response);
                });
            }
        );
    }

    /**
     * This method allows you to determine if a user is logged in to Facebook and has authenticated your app.
     * @returns {Promise<FacebookLoginStatus>}
     */
    getLoginStatus(): Promise<FacebookLoginStatus> {
        return new Promise<FacebookLoginStatus>(
            (resolve, reject) => {
                FB.getLoginStatus((response: FacebookLoginStatus) => {
                    if(!response) reject();
                    else resolve(response);
                });
            }
        );
    }

    /**
     * Login the user
     * @param options
     * @returns {Promise<FacebookLoginResponse>}
     */
    login(options?: FacebookLoginOptions): Promise<FacebookLoginResponse> {
        return new Promise<FacebookLoginResponse>(
            (resolve, reject) => {
                FB.login((response: FacebookLoginResponse) => {
                   if(response.authResponse) {
                       resolve(response);
                   }else{
                       reject();
                   }
                }, options);
            }
        );
    }

    /**
     * Logout the user
     * @returns {Promise<any>}
     */
    logout(): Promise<any> {
        return new Promise<any>(
            (resolve, reject) => {
                FB.logout((response: any) => {
                    resolve(response);
                });
            }
        );
    }

}

export interface FacebookInitParams {
    /**
     * Your application ID. If you don't have one find it in the App dashboard or go there to create a new app. Defaults to null.
     */
    appId?: string;

    /**
     * Determines which versions of the Graph API and any API dialogs or plugins are invoked when using the .api() and .ui() functions. Valid values are determined by currently available versions, such as 'v2.0'. This is a required parameter.
     */
    version: string;

    /**
     * Determines whether a cookie is created for the session or not. If enabled, it can be accessed by server-side code. Defaults to false.<commit_msg>add getAuthResponse()<commit_after>import {Injectable} from '@angular/core';

declare var FB: any;

// TODO create an interface (type) for the response instead of any

@Injectable()
export class FacebookService {

    /**
     * This method is used to initialize and setup the SDK.
     * @param params
     */
    init(params: FacebookInitParams): void {
        FB.init(params);
    }

    /**
     * This method lets you make calls to the Graph API
     * @param path This is the Graph API endpoint path that you want to call.
     * @param method This is the HTTP method that you want to use for the API request.
     * @param params This is an object consisting of any parameters that you want to pass into your Graph API call.
     * @returns {Promise<any>}
     */
    api(path: string, method?: FacebookApiMethod = 'get', params?: any = {}): Promise<any> {
        return new Promise<any>(
            (resolve, reject) => {
                FB.api(path, method, params, (response: any) => {
                    if(!response){
                        reject();
                    }else if(response.error){
                        reject(response.error);
                    }else{
                        resolve(response);
                    }
                });
            }
        );
    }

    /**
     * This method is used to trigger different forms of Facebook created UI dialogs.
     * These dialogs include:
     * - Share dialog
     * - Login dialog
     * - Add page tab dialog
     * - Requests dialog
     * - Send dialog
     * - Payments dialog
     * - Go Live dialog
     * @param params A collection of parameters that control which dialog is loaded, and relevant settings.
     * @returns {Promise<any>}
     */
    ui(params: FacebookUiParams): Promise<any> {
        return new Promise<any>(
            (resolve, reject) => {
                FB.ui(params, (response: any) => {
                    if(!response) reject();
                    else if(response.error) reject(response.error);
                    else resolve(response);
                });
            }
        );
    }

    /**
     * This method allows you to determine if a user is logged in to Facebook and has authenticated your app.
     * @returns {Promise<FacebookLoginStatus>}
     */
    getLoginStatus(): Promise<FacebookLoginStatus> {
        return new Promise<FacebookLoginStatus>(
            (resolve, reject) => {
                FB.getLoginStatus((response: FacebookLoginStatus) => {
                    if(!response) reject();
                    else resolve(response);
                });
            }
        );
    }

    /**
     * Login the user
     * @param options
     * @returns {Promise<FacebookLoginResponse>}
     */
    login(options?: FacebookLoginOptions): Promise<FacebookLoginResponse> {
        return new Promise<FacebookLoginResponse>(
            (resolve, reject) => {
                FB.login((response: FacebookLoginResponse) => {
                    if(response.authResponse) {
                        resolve(response);
                    }else{
                        reject();
                    }
                }, options);
            }
        );
    }

    /**
     * Logout the user
     * @returns {Promise<any>}
     */
    logout(): Promise<any> {
        return new Promise<any>(
            (resolve) => {
                FB.logout((response: any) => {
                    resolve(response);
                });
            }
        );
    }

    /**
     * This synchronous function returns back the current authResponse.
     * @returns {Promise<FacebookAuthResponse>}
     */
    getAuthResponse(): FacebookAuthResponse {
        return <FacebookAuthResponse>FB.getAuthResponse();
    }

}

export interface FacebookInitParams {
    /**
     * Your application ID. If you don't have one find it in the App dashboard or go there to create a new app. Defaults to null.
     */
    appId?: string;

    /**
     * Determines which versions of the Graph API and any API dialogs or plugins are invoked when using the .api() and .ui() functions. Valid values are determined by currently available versions, such as 'v2.0'. This is a required parameter.
     */
    version: string;

    /**
     * Determines whether a cookie is created for the session or not. If enabled, it can be accessed by server-side code. Defaults to false.
{'fraction_non_alphanumeric': 0.09923842999414177, 'fraction_numerical': 0.00046865846514352667, 'mean_word_length': 1.6927444794952682, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 55, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 35, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '321265', 'n_tokens_mistral': 2179, 'n_tokens_neox': 2066, 'n_words': 729}