Skip to main content

nautilus_derive/common/
urls.rs

1// -------------------------------------------------------------------------------------------------
2//  Copyright (C) 2015-2026 Nautech Systems Pty Ltd. All rights reserved.
3//  https://nautechsystems.io
4//
5//  Licensed under the GNU Lesser General Public License Version 3.0 (the "License");
6//  You may not use this file except in compliance with the License.
7//  You may obtain a copy of the License at https://www.gnu.org/licenses/lgpl-3.0.en.html
8//
9//  Unless required by applicable law or agreed to in writing, software
10//  distributed under the License is distributed on an "AS IS" BASIS,
11//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12//  See the License for the specific language governing permissions and
13//  limitations under the License.
14// -------------------------------------------------------------------------------------------------
15
16use super::{
17    consts::{REST_URL_MAINNET, REST_URL_TESTNET, WS_URL_MAINNET, WS_URL_TESTNET},
18    enums::DeriveEnvironment,
19};
20
21#[must_use]
22pub fn rest_url(environment: DeriveEnvironment) -> &'static str {
23    match environment {
24        DeriveEnvironment::Mainnet => REST_URL_MAINNET,
25        DeriveEnvironment::Testnet => REST_URL_TESTNET,
26    }
27}
28
29#[must_use]
30pub fn ws_url(environment: DeriveEnvironment) -> &'static str {
31    match environment {
32        DeriveEnvironment::Mainnet => WS_URL_MAINNET,
33        DeriveEnvironment::Testnet => WS_URL_TESTNET,
34    }
35}
36
37#[cfg(test)]
38mod tests {
39    use rstest::rstest;
40
41    use super::*;
42
43    #[rstest]
44    fn test_rest_url_routes_by_environment() {
45        assert_eq!(rest_url(DeriveEnvironment::Mainnet), REST_URL_MAINNET);
46        assert_eq!(rest_url(DeriveEnvironment::Testnet), REST_URL_TESTNET);
47    }
48
49    #[rstest]
50    fn test_ws_url_routes_by_environment() {
51        assert_eq!(ws_url(DeriveEnvironment::Mainnet), WS_URL_MAINNET);
52        assert_eq!(ws_url(DeriveEnvironment::Testnet), WS_URL_TESTNET);
53    }
54}