4545 timeout => pos_integer ()
4646}.
4747
48+ -type lookup_error () :: {json_error , term ()}
49+ | {request_failed , term ()}
50+ | {http_error , non_neg_integer (), binary ()}.
51+
52+ -type bulk_error () :: lookup_error ()
53+ | {invalid_input , binary ()}.
54+
55+ % % bulk/2 delegates to bulk/3 whose invalid_input messages are constant
56+ % % binaries; dialyzer infers their exact byte-size which is narrower than
57+ % % binary(). There is no readable type for "binary of at least N bytes".
58+ -dialyzer ({no_underspecs , bulk / 2 }).
59+
4860-define (DEFAULT_ENDPOINT , <<" https://api.ipdata.co" >>).
4961-define (EU_ENDPOINT , <<" https://eu-api.ipdata.co" >>).
5062-define (DEFAULT_TIMEOUT , 5000 ).
@@ -86,7 +98,7 @@ new(_ApiKey, _Opts) ->
8698% % @doc Look up the IP address of the calling machine.
8799% % @end
88100% %--------------------------------------------------------------------
89- -spec lookup (Client :: client ()) -> {ok , map ()} | {error , term ()}.
101+ -spec lookup (Client :: client ()) -> {ok , #{ atom () | binary () => term ()}} | {error , lookup_error ()}.
90102lookup (Client ) ->
91103 lookup (Client , <<>>, []).
92104
@@ -97,7 +109,7 @@ lookup(Client) ->
97109% % @end
98110% %--------------------------------------------------------------------
99111-spec lookup (Client :: client (), IP :: binary ()) ->
100- {ok , map ()} | {error , term ()}.
112+ {ok , #{ atom () | binary () => term ()}} | {error , lookup_error ()}.
101113lookup (Client , IP ) ->
102114 lookup (Client , IP , []).
103115
@@ -114,7 +126,7 @@ lookup(Client, IP) ->
114126% % @end
115127% %--------------------------------------------------------------------
116128-spec lookup (Client :: client (), IP :: binary (), Fields :: [binary ()]) ->
117- {ok , map ()} | {error , term ()}.
129+ {ok , #{ atom () | binary () => term ()}} | {error , lookup_error ()}.
118130lookup (#{api_key := ApiKey , endpoint := Endpoint , timeout := Timeout }, IP , Fields ) ->
119131 Path = case IP of
120132 <<>> -> <<>>;
@@ -130,7 +142,7 @@ lookup(#{api_key := ApiKey, endpoint := Endpoint, timeout := Timeout}, IP, Field
130142% % @end
131143% %--------------------------------------------------------------------
132144-spec bulk (Client :: client (), IPs :: [binary ()]) ->
133- {ok , [map ()]} | {error , term ()}.
145+ {ok , [map ()]} | {error , bulk_error ()}.
134146bulk (Client , IPs ) ->
135147 bulk (Client , IPs , []).
136148
@@ -147,7 +159,7 @@ bulk(Client, IPs) ->
147159% % @end
148160% %--------------------------------------------------------------------
149161-spec bulk (Client :: client (), IPs :: [binary ()], Fields :: [binary ()]) ->
150- {ok , [map ()]} | {error , term ()}.
162+ {ok , [map ()]} | {error , bulk_error ()}.
151163bulk (_Client , [], _Fields ) ->
152164 {error , {invalid_input , <<" At least one IP address is required" >>}};
153165bulk (_Client , IPs , _Fields ) when length (IPs ) > ? MAX_BULK_IPS ->
@@ -166,7 +178,7 @@ resolve_endpoint(eu) -> ?EU_ENDPOINT;
166178resolve_endpoint (URL ) when is_binary (URL ) -> URL .
167179
168180-spec build_url (Endpoint :: binary (), Path :: binary (),
169- ApiKey :: binary (), Fields :: [binary ()]) -> binary () .
181+ ApiKey :: binary (), Fields :: [binary ()]) -> << _ : 64 , _ : _ * 8 >> .
170182build_url (Endpoint , Path , ApiKey , Fields ) ->
171183 Base = <<Endpoint /binary , Path /binary , " ?api-key=" , ApiKey /binary >>,
172184 case Fields of
0 commit comments