1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
open! Awso_common.Jane_compat
open Values
type ('i, 'o, 'e) t =
| BatchMeterUsage: (BatchMeterUsageRequest.t, BatchMeterUsageResult.t,
BatchMeterUsageResult.error) t
| MeterUsage: (MeterUsageRequest.t, MeterUsageResult.t,
MeterUsageResult.error) t
| RegisterUsage: (RegisterUsageRequest.t, RegisterUsageResult.t,
RegisterUsageResult.error) t
| ResolveCustomer: (ResolveCustomerRequest.t, ResolveCustomerResult.t,
ResolveCustomerResult.error) t
let method_of_endpoint : type i o e. (i, o, e) t -> _ =
function
| BatchMeterUsage -> `POST
| MeterUsage -> `POST
| RegisterUsage -> `POST
| ResolveCustomer -> `POST
let uri_of_endpoint : type i o e. (i, o, e) t -> i -> Uri.t =
((fun endpoint x ->
match endpoint with
| BatchMeterUsage -> (Format.kasprintf Uri.of_string) "/"
| MeterUsage -> (Format.kasprintf Uri.of_string) "/"
| RegisterUsage -> (Format.kasprintf Uri.of_string) "/"
| ResolveCustomer -> (Format.kasprintf Uri.of_string) "/")
[@ocaml.warning "-27"])
let to_request (type i) (type o) (type e) (endp : (i, o, e) t) (req : i) =
match endp with
| BatchMeterUsage ->
let json = BatchMeterUsageRequest.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.1");
("X-Amz-Target", "AWSMPMeteringService.BatchMeterUsage")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| MeterUsage ->
let json = MeterUsageRequest.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.1");
("X-Amz-Target", "AWSMPMeteringService.MeterUsage")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| RegisterUsage ->
let json = RegisterUsageRequest.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.1");
("X-Amz-Target", "AWSMPMeteringService.RegisterUsage")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
| ResolveCustomer ->
let json = ResolveCustomerRequest.to_json req in
let body = Yojson.Safe.to_string json in
let =
Awso.Http.Headers.of_list
[("Content-Type", "application/x-amz-json-1.1");
("X-Amz-Target", "AWSMPMeteringService.ResolveCustomer")] in
Awso.Http.Request.make ~body ~headers (method_of_endpoint endp)
let of_response (type i) (type o) (type e) (endpoint : (i, o, e) t)
(resp : Awso.Http.Response.t) : (o, e) result=
let code = Awso.Http.Status.to_code (Awso.Http.Response.status resp) in
let is_success = (code >= 200) && (code < 300) in
let parse_aws_error error_of_json =
let body = Awso.Http.Response.body resp in
let bail () =
raise
(Awso.Http.Io.Error.Bad_response
{ Awso.Http.Io.Error.code = code; body; x_amzn_error_type = None }) in
match (error_of_json, ((code >= 400) && (code <= 599))) with
| (Some error_of_json, true) ->
let json = Yojson.Safe.from_string body in
(match json |> (Yojson.Safe.Util.member "__type") with
| `String error_type -> error_of_json error_type json
| `Null -> bail ()
| _ ->
failwith
(sprintf "Error '__type' did not have string type: %s" body))
| (None, _) | (_, false) -> bail () in
let _ = parse_aws_error in
let _ = resp in
match endpoint with
| BatchMeterUsage ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (BatchMeterUsageResult.of_json json)
else Error (parse_aws_error (Some BatchMeterUsageResult.error_of_json))
| MeterUsage ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (MeterUsageResult.of_json json)
else Error (parse_aws_error (Some MeterUsageResult.error_of_json))
| RegisterUsage ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (RegisterUsageResult.of_json json)
else Error (parse_aws_error (Some RegisterUsageResult.error_of_json))
| ResolveCustomer ->
if is_success
then
let json = Yojson.Safe.from_string (Awso.Http.Response.body resp) in
Ok (ResolveCustomerResult.of_json json)
else Error (parse_aws_error (Some ResolveCustomerResult.error_of_json))