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
//! Utilities that provide some basic functionality that may be useful, but are
//! generally non-essential for usage of the library.
use HashMap;
use Write;
use API_URL;
use Result;
/// Formats a URI for retrieving a forecast without options.
///
/// Accepts the token to use, as well as the latitude and longitude of the
/// location being requested.
///
/// # Examples
///
/// Format a request URI using the token `"abc"`, a latitude of `-7.3`, and a
/// longitude of `8.17`:
///
/// ```rust
/// use darksky::utils;
///
/// let uri = utils::uri("abc", -7.3, 8.17);
/// let exp = "https://api.darksky.net/forecast/abc/-7.3,8.17?units=auto";
///
/// assert_eq!(uri, exp);
/// ```
/// Formats a URI for retrieving a forecast with options.
///
/// Accepts the token to use, the latitude and longitude of the location being
/// requested, and additional options for the request.
///
/// # Examples
///
/// Format a request URI with the token `"def"`, a latitude of `-4.13`, a
/// longitude of `14.32`, and excluding the [`Hourly`][`Block::Hourly`] block:
///
/// ```rust
/// use darksky::{Block, Options, utils};
///
/// let options = Options::default()
/// .exclude(vec![Block::Hourly])
/// .into_inner();
/// let uri = utils::uri_optioned(
/// "def",
/// -4.13,
/// 14.32,
/// Some(1_450_000_000.to_string()),
/// options,
/// ).unwrap();
/// let exp = "https://api.darksky.net/forecast/def/-4.13,14.32,1450000000?exclude=hourly&";
///
/// assert_eq!(uri, exp);
/// ```
///
/// [`Block::Hourly`]: ../enum.Block.html#variant.Hourly