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
use serde_json::json;
use crate::{
Endpoint,
http::errors::ApiError,
types::{
Analytics, DnsRecord, NetworkErrors, NetworkLogEntry,
NetworkPerformance,
},
};
use super::AppResource;
impl AppResource {
/// Returns edge-network analytics for the application.
///
/// The [`Analytics`] value breaks down visits, requests, data transferred,
/// and origin metadata (countries, devices, browsers, etc.) across recent
/// traffic.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn analytics(&self) -> Result<Analytics, ApiError> {
self.client
.request_endpoint(Endpoint::get_app_analytics(&self.id))
.await?
.into_result_t()
}
/// Returns the DNS record the application's domain is expected to point
/// to.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn dns_record(&self) -> Result<DnsRecord, ApiError> {
self.client
.request_endpoint(Endpoint::get_app_dns_record(&self.id))
.await?
.into_result_t()
}
/// Associates a custom domain with the application.
///
/// `custom` must be a fully-qualified domain name that the caller has
/// pointed at the address returned by
/// [`dns_record`](AppResource::dns_record). Returns `Ok(true)` when the
/// domain is registered.
///
/// # Errors
///
/// Returns [`ApiError::Api`] with
/// [`ApiErrorCode::InvalidSubdomain`](crate::ApiErrorCode::InvalidSubdomain)
/// if the domain is malformed or already in use, or
/// [`ApiError::Transport`] on network failure.
pub async fn set_custom_domain(
&self,
custom: &str,
) -> Result<bool, ApiError> {
let endpoint = Endpoint::set_app_custom_domain(&self.id);
let request = endpoint
.request_builder(&self.client.http_client, &self.client.base_url)
.json(&json!({"custom": custom}))
.build()?;
self.client
.execute_request::<()>(request)
.await?
.into_bool_result()
}
/// Returns edge-network error analytics for the application.
///
/// The [`NetworkErrors`] value includes aggregate totals, a per-status
/// breakdown, time-bucketed timeseries data, and the most error-prone
/// paths. Set `include_4xx` to `true` to include 4xx client errors in
/// the response (default: 5xx only).
///
/// Requires a Pro or Enterprise plan.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn network_errors(
&self,
include_4xx: bool,
) -> Result<NetworkErrors, ApiError> {
self.client
.request_endpoint(Endpoint::network_errors(&self.id, include_4xx))
.await?
.into_result_t()
}
/// Returns edge-network request logs for the application.
///
/// Each [`NetworkLogEntry`] contains the timestamp, client information,
/// request details, and response metadata for a single edge request.
///
/// Requires a Pro or Enterprise plan. The API retains logs for a maximum
/// of 7 days.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn network_logs(
&self,
) -> Result<Vec<NetworkLogEntry>, ApiError> {
self.client
.request_endpoint(Endpoint::network_logs(&self.id))
.await?
.into_result_t()
}
/// Returns edge-network latency performance analytics for the application.
///
/// The [`NetworkPerformance`] value includes aggregate latency
/// percentiles (p50/p95/p99), time-bucketed timeseries, and breakdowns
/// by country, datacenter, and the slowest request paths.
///
/// Requires a Pro or Enterprise plan. Rate-limited to 10 requests per
/// 60 seconds per owner for cache misses.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn network_performance(
&self,
) -> Result<NetworkPerformance, ApiError> {
self.client
.request_endpoint(Endpoint::network_performance(&self.id))
.await?
.into_result_t()
}
/// Purges the edge cache for the application.
///
/// Returns `Ok(true)` when the purge has been queued.
///
/// # Errors
///
/// Returns [`ApiError::Transport`] on network failure or [`ApiError::Api`]
/// on an API-level error.
pub async fn purge_cache(&self) -> Result<bool, ApiError> {
self.client
.request_endpoint::<()>(Endpoint::purge_edge_cache(&self.id))
.await?
.into_bool_result()
}
}