Skip to content

Commit 857e502

Browse files
Derive ApiResult and VecApiResult
1 parent ca5b73b commit 857e502

File tree

13 files changed

+45
-93
lines changed

13 files changed

+45
-93
lines changed

cloudflare/src/endpoints/account/mod.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
use crate::framework::response::ApiResult;
21
use chrono::{DateTime, Utc};
2+
use cloudflare_derive_macros::{ApiResult, VecApiResult};
33
use serde::{Deserialize, Serialize};
44

55
pub mod list_accounts;
@@ -8,7 +8,7 @@ pub use list_accounts::ListAccounts;
88
/// Cloudflare Accounts
99
/// An Account is the root object which owns other resources such as zones, load balancers and billing details.
1010
/// <https://api.cloudflare.com/#accounts-properties>
11-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
11+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult, VecApiResult)]
1212
pub struct Account {
1313
/// Account identifier tag.
1414
pub id: String,
@@ -38,6 +38,3 @@ pub struct AccountDetails {
3838
/// Account name
3939
pub name: String,
4040
}
41-
42-
impl ApiResult for Account {}
43-
impl ApiResult for Vec<Account> {}

cloudflare/src/endpoints/argo_tunnel/data_structures.rs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
use chrono::{offset::Utc, DateTime};
2+
use cloudflare_derive_macros::{ApiResult, VecApiResult};
23
use serde::{Deserialize, Serialize};
34
use uuid::Uuid;
45

5-
use crate::framework::response::ApiResult;
6-
76
/// A Named Argo Tunnel
87
/// This is an Argo Tunnel that has been created. It can be used for routing and subsequent running.
98
/// <https://api.cloudflare.com/#argo-tunnel-properties>
10-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
9+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult, VecApiResult)]
1110
pub struct Tunnel {
1211
pub id: Uuid,
1312
pub created_at: DateTime<Utc>,
@@ -26,11 +25,8 @@ pub struct ActiveConnection {
2625
pub is_pending_reconnect: bool,
2726
}
2827

29-
impl ApiResult for Tunnel {}
30-
impl ApiResult for Vec<Tunnel> {}
31-
3228
/// The result of a route request for a Named Argo Tunnel
33-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
29+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult)]
3430
#[serde(untagged)]
3531
pub enum RouteResult {
3632
Dns(DnsRouteResult),
@@ -55,5 +51,3 @@ pub enum Change {
5551
New,
5652
Updated,
5753
}
58-
59-
impl ApiResult for RouteResult {}

cloudflare/src/endpoints/dns.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
use crate::framework::{
2-
endpoint::{serialize_query, EndpointSpec, Method},
3-
response::ApiResult,
4-
};
1+
use crate::framework::endpoint::{serialize_query, EndpointSpec, Method};
52
/// <https://api.cloudflare.com/#dns-records-for-a-zone-properties>
63
use crate::framework::{OrderDirection, SearchMatch};
74
use chrono::offset::Utc;
85
use chrono::DateTime;
6+
use cloudflare_derive_macros::{ApiResult, VecApiResult};
97
use serde::{Deserialize, Serialize};
108
use std::net::{Ipv4Addr, Ipv6Addr};
119

@@ -174,13 +172,13 @@ pub enum DnsContent {
174172
SRV { content: String },
175173
}
176174

177-
#[derive(Deserialize, Debug)]
175+
#[derive(Deserialize, Debug, ApiResult)]
178176
pub struct DeleteDnsRecordResponse {
179177
/// DNS record identifier tag
180178
pub id: String,
181179
}
182180

183-
#[derive(Deserialize, Debug)]
181+
#[derive(Deserialize, Debug, ApiResult, VecApiResult)]
184182
pub struct DnsRecord {
185183
/// Extra Cloudflare-specific information about the record
186184
pub meta: Meta,
@@ -208,7 +206,3 @@ pub struct DnsRecord {
208206
/// The domain of the record
209207
pub zone_name: String,
210208
}
211-
212-
impl ApiResult for DnsRecord {}
213-
impl ApiResult for Vec<DnsRecord> {}
214-
impl ApiResult for DeleteDnsRecordResponse {}

cloudflare/src/endpoints/load_balancing/delete_lb.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::framework::endpoint::{EndpointSpec, Method};
2-
use crate::framework::response::ApiResult;
32

3+
use cloudflare_derive_macros::ApiResult;
44
use serde::Deserialize;
55

66
/// Delete Load Balancer
@@ -25,8 +25,7 @@ impl<'a> EndpointSpec<Response> for DeleteLoadBalancer<'a> {
2525
}
2626
}
2727

28-
#[derive(Deserialize, Clone, Debug)]
28+
#[derive(Deserialize, Clone, Debug, ApiResult)]
2929
pub struct Response {
3030
pub id: String,
3131
}
32-
impl ApiResult for Response {}

cloudflare/src/endpoints/load_balancing/delete_pool.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::framework::endpoint::{EndpointSpec, Method};
2-
use crate::framework::response::ApiResult;
32

3+
use cloudflare_derive_macros::ApiResult;
44
use serde::Deserialize;
55

66
/// Delete Pool
@@ -25,8 +25,7 @@ impl<'a> EndpointSpec<Response> for DeletePool<'a> {
2525
}
2626
}
2727

28-
#[derive(Deserialize, Clone, Debug)]
28+
#[derive(Deserialize, Clone, Debug, ApiResult)]
2929
pub struct Response {
3030
pub id: String,
3131
}
32-
impl ApiResult for Response {}

cloudflare/src/endpoints/load_balancing/list_lb.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
use crate::endpoints::load_balancing::LoadBalancer;
22
use crate::framework::endpoint::{EndpointSpec, Method};
3-
use crate::framework::response::ApiResult;
43

54
/// List Load Balancers
65
/// <https://api.cloudflare.com/#load-balancers-list-load-balancers>
@@ -18,5 +17,3 @@ impl<'a> EndpointSpec<Vec<LoadBalancer>> for ListLoadBalancers<'a> {
1817
format!("zones/{}/load_balancers", self.zone_identifier)
1918
}
2019
}
21-
22-
impl ApiResult for Vec<LoadBalancer> {}

cloudflare/src/endpoints/load_balancing/mod.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ pub mod delete_pool;
55
pub mod list_lb;
66
pub mod pool_details;
77

8-
use crate::framework::response::ApiResult;
98
use chrono::offset::Utc;
109
use chrono::DateTime;
10+
use cloudflare_derive_macros::{ApiResult, VecApiResult};
1111
use serde::{Deserialize, Serialize};
1212
use std::collections::{HashMap, HashSet};
1313
use std::hash::{Hash, Hasher};
1414
use std::net::IpAddr;
1515

16-
#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug)]
16+
#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug, ApiResult, VecApiResult)]
1717
pub struct LoadBalancer {
1818
pub id: String,
1919
pub created_on: DateTime<Utc>,
@@ -108,8 +108,6 @@ pub enum Secure {
108108
Never,
109109
}
110110

111-
impl ApiResult for LoadBalancer {}
112-
113111
/// A pool is a set of origins that requests could be routed to (e.g. each of your data centers or
114112
/// regions have its own pool).
115113
/// Requests will be routed to particular pools according to your steering policy, and then balanced
@@ -120,7 +118,7 @@ impl ApiResult for LoadBalancer {}
120118
/// handle. Then you might use a "dynamic latency" steering policy to ensure requests get routed
121119
/// to whatever pool can serve them fastest. So US users will probably get routed to the US pool. If
122120
/// the US pool becomes unavailable, they'll fail over to the Oceania pool.
123-
#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug)]
121+
#[derive(Eq, PartialEq, Deserialize, Serialize, Clone, Debug, ApiResult)]
124122
pub struct Pool {
125123
pub id: String,
126124
pub created_on: DateTime<Utc>,
@@ -151,7 +149,7 @@ pub struct Pool {
151149
/// An origin represents something that can serve user requests. Usually a machine, maybe an ELB.
152150
/// Origins with similar latency functions (e.g. origins in the same data center or region) might be
153151
/// in the same pool.
154-
#[derive(Deserialize, Serialize, Clone, Debug)]
152+
#[derive(Deserialize, Serialize, Clone, Debug, ApiResult)]
155153
pub struct Origin {
156154
/// A human-identifiable name for the origin.
157155
/// e.g. app-server-1
@@ -190,6 +188,3 @@ impl Hash for Origin {
190188
self.weight.to_bits().hash(state);
191189
}
192190
}
193-
194-
impl ApiResult for Origin {}
195-
impl ApiResult for Pool {}

cloudflare/src/endpoints/r2.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use chrono::offset::Utc;
22
use chrono::DateTime;
3+
use cloudflare_derive_macros::ApiResult;
34
use serde::{Deserialize, Serialize};
45
use std::collections::HashMap;
56

@@ -16,14 +17,13 @@ pub struct Bucket {
1617
}
1718

1819
/// ListBucketsResult contains a list of buckets in an account.
19-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
20+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult)]
2021
pub struct ListBucketsResult {
2122
pub buckets: Vec<Bucket>,
2223
}
2324

2425
type EmptyMap = HashMap<(), ()>;
2526
impl ApiResult for EmptyMap {}
26-
impl ApiResult for ListBucketsResult {}
2727

2828
/// Lists all buckets within the account.
2929
#[derive(Debug)]

cloudflare/src/endpoints/user.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::framework::endpoint::{EndpointSpec, Method};
2-
use crate::framework::response::ApiResult;
32

43
use chrono::{DateTime, Utc};
4+
use cloudflare_derive_macros::ApiResult;
55
use serde::{Deserialize, Serialize};
66

77
/// Get User Details
@@ -17,7 +17,7 @@ pub struct Organization {
1717
roles: Vec<String>, // List of role names for the User at the Organization
1818
}
1919

20-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
20+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult)]
2121
pub struct UserDetails {
2222
pub organizations: Vec<Organization>,
2323
#[serde(default)]
@@ -35,7 +35,6 @@ pub struct UserDetails {
3535
pub suspended: bool,
3636
pub email: String,
3737
}
38-
impl ApiResult for UserDetails {}
3938

4039
#[test]
4140
fn handles_empty_betas_field() {
@@ -81,12 +80,11 @@ impl EndpointSpec<UserDetails> for GetUserDetails {
8180
/// Returns whether a given token is valid or not.
8281
/// <https://blog.cloudflare.com/api-tokens-general-availability/>
8382
///
84-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
83+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult)]
8584
pub struct UserTokenStatus {
8685
pub id: String,
8786
pub status: String,
8887
}
89-
impl ApiResult for UserTokenStatus {}
9088

9189
#[derive(Debug)]
9290
pub struct GetUserTokenStatus {}

cloudflare/src/endpoints/workers/delete_script.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::framework::endpoint::{EndpointSpec, Method};
2-
use crate::framework::response::ApiResult;
32

3+
use cloudflare_derive_macros::ApiResult;
44
use serde::{Deserialize, Serialize};
55

66
/// Delete Workers script
@@ -25,8 +25,7 @@ impl<'a> EndpointSpec<ScriptDeleteID> for DeleteScript<'a> {
2525
}
2626
}
2727

28-
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
28+
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq, ApiResult)]
2929
pub struct ScriptDeleteID {
3030
pub id: String,
3131
}
32-
impl ApiResult for ScriptDeleteID {}

0 commit comments

Comments
 (0)