Current section
Files
Jump to
Current section
Files
src/aws_marketplace_commerce_analytics.erl
%% WARNING: DO NOT EDIT, AUTO-GENERATED CODE!
%% See https://github.com/aws-beam/aws-codegen for more details.
%% @doc Provides AWS Marketplace business intelligence data on-demand.
-module(aws_marketplace_commerce_analytics).
-export([generate_data_set/2,
generate_data_set/3,
start_support_data_export/2,
start_support_data_export/3]).
-include_lib("hackney/include/hackney_lib.hrl").
%% Example:
%% generate_data_set_request() :: #{
%% <<"customerDefinedValues">> => map(),
%% <<"dataSetPublicationDate">> := non_neg_integer(),
%% <<"dataSetType">> := list(any()),
%% <<"destinationS3BucketName">> := string(),
%% <<"destinationS3Prefix">> => string(),
%% <<"roleNameArn">> := string(),
%% <<"snsTopicArn">> := string()
%% }
-type generate_data_set_request() :: #{binary() => any()}.
%% Example:
%% generate_data_set_result() :: #{
%% <<"dataSetRequestId">> => string()
%% }
-type generate_data_set_result() :: #{binary() => any()}.
%% Example:
%% marketplace_commerce_analytics_exception() :: #{
%% <<"message">> => string()
%% }
-type marketplace_commerce_analytics_exception() :: #{binary() => any()}.
%% Example:
%% start_support_data_export_request() :: #{
%% <<"customerDefinedValues">> => map(),
%% <<"dataSetType">> := list(any()),
%% <<"destinationS3BucketName">> := string(),
%% <<"destinationS3Prefix">> => string(),
%% <<"fromDate">> := non_neg_integer(),
%% <<"roleNameArn">> := string(),
%% <<"snsTopicArn">> := string()
%% }
-type start_support_data_export_request() :: #{binary() => any()}.
%% Example:
%% start_support_data_export_result() :: #{
%% <<"dataSetRequestId">> => string()
%% }
-type start_support_data_export_result() :: #{binary() => any()}.
-type generate_data_set_errors() ::
marketplace_commerce_analytics_exception().
-type start_support_data_export_errors() ::
marketplace_commerce_analytics_exception().
%%====================================================================
%% API
%%====================================================================
%% @doc Given a data set type and data set publication date, asynchronously
%% publishes the requested data set to the specified
%% S3 bucket and notifies the specified SNS topic once the data is available.
%%
%% Returns a unique request identifier that
%% can be used to correlate requests with notifications from the SNS topic.
%% Data sets will be published in comma-separated values (CSV) format with
%% the file name {data_set_type}_YYYY-MM-DD.csv.
%% If a file with the same name already exists (e.g. if the same data set is
%% requested twice), the original file will
%% be overwritten by the new file.
%% Requires a Role with an attached permissions policy providing Allow
%% permissions for the following actions:
%% s3:PutObject, s3:GetBucketLocation, sns:GetTopicAttributes, sns:Publish,
%% iam:GetRolePolicy.
-spec generate_data_set(aws_client:aws_client(), generate_data_set_request()) ->
{ok, generate_data_set_result(), tuple()} |
{error, any()} |
{error, generate_data_set_errors(), tuple()}.
generate_data_set(Client, Input)
when is_map(Client), is_map(Input) ->
generate_data_set(Client, Input, []).
-spec generate_data_set(aws_client:aws_client(), generate_data_set_request(), proplists:proplist()) ->
{ok, generate_data_set_result(), tuple()} |
{error, any()} |
{error, generate_data_set_errors(), tuple()}.
generate_data_set(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"GenerateDataSet">>, Input, Options).
%% @doc This target has been deprecated.
%%
%% Given a data set type and a from date, asynchronously publishes the
%% requested customer support data
%% to the specified S3 bucket and notifies the specified SNS topic once the
%% data is available. Returns a unique request
%% identifier that can be used to correlate requests with notifications from
%% the SNS topic.
%% Data sets will be published in comma-separated values (CSV) format with
%% the file name
%% {data_set_type}_YYYY-MM-DD'T'HH-mm-ss'Z'.csv.
%% If a file with the same name already exists (e.g. if the same data set is
%% requested twice), the original file will
%% be overwritten by the new file.
%% Requires a Role with an attached permissions policy providing Allow
%% permissions for the following actions:
%% s3:PutObject, s3:GetBucketLocation, sns:GetTopicAttributes, sns:Publish,
%% iam:GetRolePolicy.
-spec start_support_data_export(aws_client:aws_client(), start_support_data_export_request()) ->
{ok, start_support_data_export_result(), tuple()} |
{error, any()} |
{error, start_support_data_export_errors(), tuple()}.
start_support_data_export(Client, Input)
when is_map(Client), is_map(Input) ->
start_support_data_export(Client, Input, []).
-spec start_support_data_export(aws_client:aws_client(), start_support_data_export_request(), proplists:proplist()) ->
{ok, start_support_data_export_result(), tuple()} |
{error, any()} |
{error, start_support_data_export_errors(), tuple()}.
start_support_data_export(Client, Input, Options)
when is_map(Client), is_map(Input), is_list(Options) ->
request(Client, <<"StartSupportDataExport">>, Input, Options).
%%====================================================================
%% Internal functions
%%====================================================================
-spec request(aws_client:aws_client(), binary(), map(), list()) ->
{ok, Result, {integer(), list(), hackney:client()}} |
{error, Error, {integer(), list(), hackney:client()}} |
{error, term()} when
Result :: map() | undefined,
Error :: map().
request(Client, Action, Input, Options) ->
RequestFun = fun() -> do_request(Client, Action, Input, Options) end,
aws_request:request(RequestFun, Options).
do_request(Client, Action, Input0, Options) ->
Client1 = Client#{service => <<"marketplacecommerceanalytics">>},
DefaultHost = build_host(<<"marketplacecommerceanalytics">>, Client1),
{URL, Host} = aws_util:apply_endpoint_url_override(build_url(DefaultHost, Client1), DefaultHost, <<"/">>, <<"AWS_ENDPOINT_URL_MARKETPLACE_COMMERCE_ANALYTICS">>),
Headers = [
{<<"Host">>, Host},
{<<"Content-Type">>, <<"application/x-amz-json-1.1">>},
{<<"X-Amz-Target">>, <<"MarketplaceCommerceAnalytics20150701.", Action/binary>>}
],
Input = Input0,
Payload = jsx:encode(Input),
SignedHeaders = aws_request:sign_request(Client1, <<"POST">>, URL, Headers, Payload),
Response = hackney:request(post, URL, SignedHeaders, Payload, Options),
handle_response(Response).
handle_response({ok, 200, ResponseHeaders, Client}) ->
case hackney:body(Client) of
{ok, <<>>} ->
{ok, undefined, {200, ResponseHeaders, Client}};
{ok, Body} ->
Result = jsx:decode(Body),
{ok, Result, {200, ResponseHeaders, Client}}
end;
handle_response({ok, StatusCode, ResponseHeaders, Client}) ->
{ok, Body} = hackney:body(Client),
Error = jsx:decode(Body),
{error, Error, {StatusCode, ResponseHeaders, Client}};
handle_response({error, Reason}) ->
{error, Reason}.
build_host(_EndpointPrefix, #{region := <<"local">>, endpoint := Endpoint}) ->
Endpoint;
build_host(_EndpointPrefix, #{region := <<"local">>}) ->
<<"localhost">>;
build_host(EndpointPrefix, #{region := Region, endpoint := Endpoint}) ->
aws_util:binary_join([EndpointPrefix, Region, Endpoint], <<".">>).
build_url(Host, Client) ->
Proto = aws_client:proto(Client),
Port = aws_client:port(Client),
aws_util:binary_join([Proto, <<"://">>, Host, <<":">>, Port, <<"/">>], <<"">>).