Source file gapiUrlshortenerV1Service.ml

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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
(* Warning! This file is generated. Modify at your own risk. *)

open GapiUtils.Infix
open GapiUrlshortenerV1Model

module Scope =
struct
  let urlshortener = "https://www.googleapis.com/auth/urlshortener"
  
  
end

module UrlResource =
struct
  module Projection =
  struct
    type t =
      | Default
      | ANALYTICS_CLICKS
      | ANALYTICS_TOP_STRINGS
      | FULL
      
    let to_string = function
      | Default -> ""
      | ANALYTICS_CLICKS -> "ANALYTICS_CLICKS"
      | ANALYTICS_TOP_STRINGS -> "ANALYTICS_TOP_STRINGS"
      | FULL -> "FULL"
      
    let of_string = function
      | "" -> Default
      | "ANALYTICS_CLICKS" -> ANALYTICS_CLICKS
      | "ANALYTICS_TOP_STRINGS" -> ANALYTICS_TOP_STRINGS
      | "FULL" -> FULL
      | s -> failwith ("Unexpected value for Projection:" ^ s)
  
  end
  
  module UrlParameters =
  struct
    type t = {
      (* Standard query parameters *)
      alt : string;
      fields : string;
      prettyPrint : bool;
      quotaUser : string;
      userIp : string;
      key : string;
      (* url-specific query parameters *)
      projection : Projection.t;
      shortUrl : string;
      start_token : string;
      
    }
    
    let default = {
      alt = "";
      fields = "";
      prettyPrint = true;
      quotaUser = "";
      userIp = "";
      key = "";
      projection = Projection.Default;
      shortUrl = "";
      start_token = "";
      
    }
    
    let to_key_value_list qp =
      let param get_value to_string name =
        GapiService.build_param default qp get_value to_string name in [
      param (fun p -> p.alt) (fun x -> x) "alt";
      param (fun p -> p.fields) (fun x -> x) "fields";
      param (fun p -> p.prettyPrint) string_of_bool "prettyPrint";
      param (fun p -> p.quotaUser) (fun x -> x) "quotaUser";
      param (fun p -> p.userIp) (fun x -> x) "userIp";
      param (fun p -> p.key) (fun x -> x) "key";
      param (fun p -> p.projection) Projection.to_string "projection";
      param (fun p -> p.shortUrl) (fun x -> x) "shortUrl";
      param (fun p -> p.start_token) (fun x -> x) "start-token";
      
    ] |> List.concat
    
    let merge_parameters
        ?(standard_parameters = GapiService.StandardParameters.default)
        ?(projection = default.projection)
        ?(shortUrl = default.shortUrl)
        ?(start_token = default.start_token)
        () =
      let parameters = {
        alt = standard_parameters.GapiService.StandardParameters.alt;
        fields = standard_parameters.GapiService.StandardParameters.fields;
        prettyPrint = standard_parameters.GapiService.StandardParameters.prettyPrint;
        quotaUser = standard_parameters.GapiService.StandardParameters.quotaUser;
        userIp = standard_parameters.GapiService.StandardParameters.userIp;
        key = standard_parameters.GapiService.StandardParameters.key;
        projection;
        shortUrl;
        start_token;
        
      } in
      if parameters = default then None else Some parameters
    
  end
  
  let get
        ?(base_url = "https://www.googleapis.com/urlshortener/v1/")
        ?etag
        ?std_params
        ?projection
        ~shortUrl
        session =
    let full_url = GapiUtils.add_path_to_url ["url"] base_url in
    let params = UrlParameters.merge_parameters
      ?standard_parameters:std_params ?projection ~shortUrl () in
    let query_parameters = GapiOption.map UrlParameters.to_key_value_list params
      in
    GapiService.get ?query_parameters ?etag full_url
      (GapiJson.parse_json_response Url.of_data_model) session 
    
  let insert
        ?(base_url = "https://www.googleapis.com/urlshortener/v1/")
        ?std_params
        url
        session =
    let full_url = GapiUtils.add_path_to_url ["url"] base_url in
    let params = UrlParameters.merge_parameters
      ?standard_parameters:std_params () in
    let query_parameters = GapiOption.map UrlParameters.to_key_value_list params
      in
    GapiService.post ?query_parameters
      ~data_to_post:(GapiJson.render_json Url.to_data_model) ~data:url
      full_url (GapiJson.parse_json_response Url.of_data_model) session 
    
  let list
        ?(base_url = "https://www.googleapis.com/urlshortener/v1/")
        ?std_params
        ?projection
        ?start_token
        session =
    let full_url = GapiUtils.add_path_to_url ["url"; "history"] base_url in
    let params = UrlParameters.merge_parameters
      ?standard_parameters:std_params ?projection ?start_token () in
    let query_parameters = GapiOption.map UrlParameters.to_key_value_list params
      in
    GapiService.get ?query_parameters full_url
      (GapiJson.parse_json_response UrlHistory.of_data_model) session 
    
  
end