<commit_before>%% ===================================================================
%% @author <NAME>
%% @copyright (C): 2014 ACK CYFRONET AGH
%% This software is released under the MIT license
%% cited in 'LICENSE.txt'
%% @end
%% ===================================================================
%% @doc This is a communication layer module. It sends requests to
%% Global Registry using REST API and returns responses.
%% @end
%% ===================================================================

-module(gr_endpoint).

-include("global_registry/gr_types.hrl").

%% API
-export([auth_request/3, auth_request/4, auth_request/5, auth_request/6]).
-export([noauth_request/3, noauth_request/4, noauth_request/5, noauth_request/6]).

%% ====================================================================
%% API functions
%% ====================================================================

%% auth_request/3
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, []).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method) ->
    auth_request(Client, URN, Method, []).


%% auth_request/4
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, Body, []).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method, Body) ->
    auth_request(Client, URN, Method, Body, []).


%% auth_request/5
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, [], Body, Options).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method, Body, Options) ->
    auth_request(Client, URN, Method, [], Body, Options).


%% auth_request/6
%% ====================================================================
%% @doc Sends authenticated request to Global Registry.
%% Context depends on client type.
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Headers :: headers(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(client, URN, Method, Headers, Body, Options) ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request(provider, URN, Method, Headers, Body, Options) ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request({Type, undefined}, URN, Method, Headers, Body, Options) when Type =:= user; Type =:= try_user ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request({Type, AccessToken}, URN, Method, Headers, Body, Options) when Type =:= user; Type =:= try_user ->
    AuthorizationHeader = {"authorization", "Bearer " ++ binary_to_list(AccessToken)},
    do_auth_request(URN, Method, [AuthorizationHeader | Headers], Body, Options).


%% noauth_request/3
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, [])
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method) ->
    noauth_request(Client, URN, Method, []).


%% noauth_request/4
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, Body, [])
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method, Body) ->
    noauth_request(Client, URN, Method, Body, []).


%% noauth_request/5
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, [], Body, Options)
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method, Body, Options) ->
    noauth_request(Client, URN, Method, [], Body, Options).


%% noauth_request/6
%% ====================================================================
%% @doc Sends unauthenticated request to Global Registry.
%% Context depends on client type.
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Headers :: headers(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(client, URN, Method, Headers, Body, Options) ->
    do_noauth_request(URN, Method, Headers, Body, Options);
<commit_msg>VFS-1051 meck adjustments<commit_after>%% ===================================================================
%% @author <NAME>
%% @copyright (C): 2014 ACK CYFRONET AGH
%% This software is released under the MIT license
%% cited in 'LICENSE.txt'
%% @end
%% ===================================================================
%% @doc This is a communication layer module. It sends requests to
%% Global Registry using REST API and returns responses.
%% @end
%% ===================================================================

-module(gr_endpoint).

-include("global_registry/gr_types.hrl").

%% API
-export([auth_request/3, auth_request/4, auth_request/5, auth_request/6]).
-export([noauth_request/3, noauth_request/4, noauth_request/5, noauth_request/6]).

%% ====================================================================
%% API functions
%% ====================================================================

%% auth_request/3
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, []).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method) ->
    gr_endpoint:auth_request(Client, URN, Method, []).


%% auth_request/4
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, Body, []).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method, Body) ->
    gr_endpoint:auth_request(Client, URN, Method, Body, []).


%% auth_request/5
%% ====================================================================
%% @equiv auth_request(Client, URN, Method, [], Body, Options).
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(Client, URN, Method, Body, Options) ->
    gr_endpoint:auth_request(Client, URN, Method, [], Body, Options).


%% auth_request/6
%% ====================================================================
%% @doc Sends authenticated request to Global Registry.
%% Context depends on client type.
%% @end
-spec auth_request(Client :: client(), URN :: urn(), Method :: method(), Headers :: headers(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
auth_request(client, URN, Method, Headers, Body, Options) ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request(provider, URN, Method, Headers, Body, Options) ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request({Type, undefined}, URN, Method, Headers, Body, Options) when Type =:= user; Type =:= try_user ->
    do_auth_request(URN, Method, Headers, Body, Options);

auth_request({Type, AccessToken}, URN, Method, Headers, Body, Options) when Type =:= user; Type =:= try_user ->
    AuthorizationHeader = {"authorization", "Bearer " ++ binary_to_list(AccessToken)},
    do_auth_request(URN, Method, [AuthorizationHeader | Headers], Body, Options).


%% noauth_request/3
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, [])
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method) ->
    gr_endpoint:noauth_request(Client, URN, Method, []).


%% noauth_request/4
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, Body, [])
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method, Body) ->
    gr_endpoint:noauth_request(Client, URN, Method, Body, []).


%% noauth_request/5
%% ====================================================================
%% @equiv noauth_request(Client, URN, Method, [], Body, Options)
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(Client, URN, Method, Body, Options) ->
    gr_endpoint:noauth_request(Client, URN, Method, [], Body, Options).


%% noauth_request/6
%% ====================================================================
%% @doc Sends unauthenticated request to Global Registry.
%% Context depends on client type.
%% @end
-spec noauth_request(Client :: client(), URN :: urn(), Method :: method(), Headers :: headers(), Body :: body(), Options :: list()) -> Result when
    Result :: {ok, Status :: string(), ResponseHeaders :: binary(), ResponseBody :: binary()} | {error, Reason :: term()}.
%% ====================================================================
noauth_request(client, URN, Method, Headers, Body, Options) ->
    do_noauth_request(URN, Method, Headers, Body, Options);

{'fraction_non_alphanumeric': 0.3774549586106152, 'fraction_numerical': 0.0035708488881675054, 'mean_word_length': 6.60679012345679, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 43, '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': '5377822', 'n_tokens_mistral': 3245, 'n_tokens_neox': 2967, 'n_words': 858}