-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactual.mli
172 lines (155 loc) · 4.78 KB
/
factual.mli
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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
open Batteries
open Yojson.Basic
(* This module exports the Filter type used to create read and facet queries. *)
module Filter : sig
type t = EqualNum of string * float
| EqualStr of string * string
| NotEqualNum of string * float
| NotEqualStr of string * string
| InNumList of string * float list
| InStrList of string * string list
| NotInNumList of string * float list
| NotInStrList of string * string list
| BeginsWith of string * string
| NotBeginsWith of string * string
| BeginsWithAny of string * string list
| NotBeginsWithAny of string * string list
| IsBlank of string
| IsNotBlank of string
| And of t list
| Or of t list
val toString : t list -> (string * string) option
end
(* This module exports the Geo type used to create read and facet queries. *)
module Geo : sig
type t = Circle of float * float * float
| Point of float * float
val toString : t option -> (string * string) option
end
(* This module exports the Search type used to create read and facet queries. *)
module Search : sig
type t = AndSearch of string list
| OrSearch of string list
| NoSearch
val toString : t -> (string * string) option
end
(* This module exports the type used to represent a table for the read or
schema query types. *)
module Table : sig
type t = Places
| RestaurantsUS
| HotelsUS
| Global
| Crosswalk
| HealthCareProviders
| WorldGeographies
| ProductsCPG
| ProductsCrosswalk
| Monetize
| Custom of string
val show : t -> string
end
module Path : sig
type t = {
url : string;
params : (string * string) list
}
val show : t -> string
end
(* This module exports the types used to create facets queries. *)
module FacetsQuery : sig
type t = {
table : Table.t;
search : Search.t;
select : string list;
filters : Filter.t list;
geo : Geo.t option;
limit : int option;
minCount : int option;
includeCount : bool
}
val toPath : t -> Path.t
end
(* This module exports the type used to create geocode queries. *)
module GeocodeQuery : sig
type t = Geo.t
val toPath : t -> Path.t
end
(* This module exports the type used to create geopulse queries. *)
module GeopulseQuery : sig
type t = {
geo : Geo.t;
select : string list
}
val toPath : t -> Path.t
end
(* This module exports the types used to create read queries. *)
module ReadQuery : sig
type t = {
table : Table.t;
search : Search.t;
select : string list;
limit : int option;
offset : int option;
filters : Filter.t list;
geo : Geo.t option;
includeCount : bool
}
val toPath : t -> Path.t
end
(* This module exports the type used to create resolve queries. *)
module ResolveQuery : sig
type value = Str of string * string
| Num of string * float
type t = value list
val toPath : t -> Path.t
end
(* This module exports the type used to create schema queries. *)
module SchemaQuery : sig
type t = Table.t
val toPath : t -> Path.t
end
(* A member of the Query typeclass must define a toPath method which converts
the Query into a path. *)
module type Query = sig
type t
val toPath : t -> Path.t
end
(* This module exports the type which encapsulates Factual API responses. It
also provides some utility function that can be used to manipulate the
Json object which holds the data. *)
module Response : sig
type t = {
status : string;
version : float;
response : json;
errorMessage : string option;
errorType : string option
}
val fromValue : json -> t
val toList : json -> json list
val lookupNumber : string -> json -> float
val lookupString : string -> json -> string option
val lookupValue : string -> json -> json
end
(* Lwt functions *)
module type Lwt = sig
type 'a _r
val bind : 'a _r -> ('a -> 'b _r) -> 'b _r
val catch : (unit -> 'a _r) -> (exn -> 'a _r) -> 'a _r
val return : 'a -> 'a _r
val fail : exn -> 'a _r
end
(* This module exports functions which are used to execute queries and handle
the OAuth authentication process. *)
module Client (Lwt : Lwt) : sig
module Oauth_client : module type of Oauth_client.Client(Lwt)
module Make (Http_client : Oauth_client.Http_client) (Query : Query) : sig
val makeRequest : string -> string -> Query.t -> Response.t Lwt._r
val makeRawRequest : string -> string -> Path.t -> Response.t Lwt._r
val makeMultiRequest : string -> string -> (string, Query.t) Map.PMap.t-> (string, Response.t) Map.PMap.t Lwt._r
val debugQuery : Query.t -> unit
end
end
module Sync : Lwt with type 'a _r = 'a
include module type of Client(Sync)