app_store_connect/
device_api.rs1use crate::bundle_api::BundleIdPlatform;
8use crate::{AppStoreConnectClient, Result};
9use serde::{Deserialize, Serialize};
10
11const APPLE_CERTIFICATE_URL: &str = "https://api.appstoreconnect.apple.com/v1/devices";
12
13impl AppStoreConnectClient {
14 pub fn register_device(
15 &self,
16 name: &str,
17 platform: BundleIdPlatform,
18 udid: &str,
19 ) -> Result<DeviceResponse> {
20 let token = self.get_token()?;
21 let body = DeviceCreateRequest {
22 data: DeviceCreateRequestData {
23 attributes: DeviceCreateRequestAttributes {
24 name: name.into(),
25 platform: platform.to_string(),
26 udid: udid.into(),
27 },
28 r#type: "devices".into(),
29 },
30 };
31 let req = self
32 .client
33 .post(APPLE_CERTIFICATE_URL)
34 .bearer_auth(token)
35 .header("Accept", "application/json")
36 .header("Content-Type", "application/json")
37 .json(&body);
38 Ok(self.send_request(req)?.json()?)
39 }
40
41 pub fn list_devices(&self) -> Result<DevicesResponse> {
42 let token = self.get_token()?;
43 let req = self
44 .client
45 .get(APPLE_CERTIFICATE_URL)
46 .bearer_auth(token)
47 .header("Accept", "application/json");
48 Ok(self.send_request(req)?.json()?)
49 }
50
51 pub fn get_device(&self, id: &str) -> Result<DeviceResponse> {
52 let token = self.get_token()?;
53 let req = self
54 .client
55 .get(format!("{APPLE_CERTIFICATE_URL}/{id}"))
56 .bearer_auth(token)
57 .header("Accept", "application/json");
58 Ok(self.send_request(req)?.json()?)
59 }
60}
61
62#[derive(Debug, Serialize)]
63#[serde(rename_all = "camelCase")]
64pub struct DeviceCreateRequest {
65 pub data: DeviceCreateRequestData,
66}
67
68#[derive(Debug, Serialize)]
69#[serde(rename_all = "camelCase")]
70pub struct DeviceCreateRequestData {
71 pub attributes: DeviceCreateRequestAttributes,
72 pub r#type: String,
73}
74
75#[derive(Debug, Serialize)]
76#[serde(rename_all = "camelCase")]
77pub struct DeviceCreateRequestAttributes {
78 pub name: String,
79 pub platform: String,
80 pub udid: String,
81}
82
83#[derive(Debug, Deserialize)]
84#[serde(rename_all = "camelCase")]
85pub struct DeviceResponse {
86 pub data: Device,
87}
88
89#[derive(Debug, Deserialize)]
90#[serde(rename_all = "camelCase")]
91pub struct DevicesResponse {
92 pub data: Vec<Device>,
93}
94
95#[derive(Debug, Deserialize)]
96#[serde(rename_all = "camelCase")]
97pub struct Device {
98 pub attributes: DeviceAttributes,
99 pub id: String,
100}
101
102#[derive(Debug, Deserialize)]
103#[serde(rename_all = "camelCase")]
104pub struct DeviceAttributes {
105 pub device_class: String,
106 pub model: Option<String>,
107 pub name: String,
108 pub platform: String,
109 pub status: String,
110 pub udid: String,
111 pub added_date: String,
112}