eve_esi/scope/
location.rs

1//! # EVE ESI Location Scopes
2//!
3//! This module provides a type-safe way to add location-related scopes for OAuth2 to the [`super::ScopeBuilder`]
4//!
5//! See [module-level documentation](super) for an overview & usage of scopes for the esi_crate
6//!
7//! ## Methods
8//! | Method                                    | Description                                                          |
9//! | ----------------------------------------- | -------------------------------------------------------------------- |
10//! | [`LocationScopes::new`]                   | Creates a new instance of [`LocationScopes`]                         |
11//! | [`LocationScopes::all`]                   | Creates a new instance of [`LocationScopes`] with all scopes applied |
12//! | [`LocationScopes::read_location`]         | Read access to character's current location                          |
13//! | [`LocationScopes::read_online`]           | Read access to characer's online status                              |
14//! | [`LocationScopes::read_ship_type`]        | Read access to character's ship type                                 |
15
16/// Read access to character's current location
17pub const READ_LOCATION: &str = "esi-location.read_location.v1";
18/// Read access to characer's online status
19pub const READ_ONLINE: &str = "esi-location.read_online.v1";
20/// Read access to character's ship type
21pub const READ_SHIP_TYPE: &str = "esi-location.read_ship_type.v1";
22
23/// Struct with methods for listing location scopes to request for OAuth2
24pub struct LocationScopes {
25    pub(super) scopes: Vec<String>,
26}
27
28impl Default for LocationScopes {
29    /// Create a default instance of [`LocationScopes`]
30    fn default() -> Self {
31        Self::new()
32    }
33}
34
35impl LocationScopes {
36    /// Create a new instance of [`LocationScopes`]
37    pub fn new() -> Self {
38        LocationScopes { scopes: Vec::new() }
39    }
40
41    /// Creates a new instance of [`LocationScopes`] with all scopes applied
42    pub fn all() -> Self {
43        LocationScopes::new()
44            .read_location()
45            .read_online()
46            .read_ship_type()
47    }
48
49    /// Read access to character's current location
50    ///
51    /// Adds the `esi-location.read_location.v1` scope
52    pub fn read_location(mut self) -> Self {
53        self.scopes.push(READ_LOCATION.to_string());
54        self
55    }
56
57    /// Read access to characer's online status
58    ///
59    /// Adds the `esi-location.read_online.v1` scope
60    pub fn read_online(mut self) -> Self {
61        self.scopes.push(READ_ONLINE.to_string());
62        self
63    }
64
65    /// Read access to character's ship type
66    ///
67    /// Adds the `esi-location.read_ship_type.v1` scope
68    pub fn read_ship_type(mut self) -> Self {
69        self.scopes.push(READ_SHIP_TYPE.to_string());
70        self
71    }
72}
73
74#[cfg(test)]
75mod location_scopes_tests {
76    use crate::scope::LocationScopes;
77
78    /// Tests initializing a default instance of [`LocationScopes`]
79    #[test]
80    fn test_location_scopes_default() {
81        let location_scopes = LocationScopes::default();
82
83        assert_eq!(location_scopes.scopes.len(), 0)
84    }
85}