1use crate::client::Client;
2use ureq::{Error, Request};
3use serde::{Deserialize};
4
5#[derive(Deserialize)]
6pub struct CountryNetwork {
7 pub comment: String,
8 pub features: Vec<String>,
9 pub mcc: String,
10 pub mncs: Vec<String>,
11 #[serde(rename = "networkName")]
12 pub network_name: String,
13 pub price: f64,
14}
15
16#[derive(Deserialize)]
17pub struct CountryPricing {
18 #[serde(rename = "countryCode")]
19 pub country_code: String,
20 #[serde(rename = "countryName")]
21 pub country_name: String,
22 #[serde(rename = "countryPrefix")]
23 pub country_prefix: String,
24 pub networks: Vec<CountryNetwork>,
25}
26
27#[derive(Deserialize)]
28pub struct PricingResponse {
29 #[serde(rename = "countCountries")]
30 pub count_countries: u32,
31 #[serde(rename = "countNetworks")]
32 pub count_networks: u32,
33 pub countries: Vec<CountryPricing>,
34}
35
36pub struct PricingParams {
37 pub country: Option<String>,
38}
39
40pub struct Pricing {
41 client: Client
42}
43
44impl Pricing {
45 pub fn new(client: Client) -> Self {
46 Pricing {
47 client,
48 }
49 }
50
51 pub fn get(&self, params: PricingParams, format: &str) -> Request {
52 let mut req = self.client.request("GET", "pricing").clone();
53
54 if params.country.is_some() {
55 req = req.query("country", &*params.country.unwrap_or_default().to_string());
56 }
57
58 req.query("format", format)
59 }
60
61 pub fn csv(&self, params: PricingParams) -> Result<String, Error> {
62 Ok(self.get(params, "csv").call()?.into_string()?)
63 }
64
65 pub fn json(&self, params: PricingParams) -> Result<PricingResponse, Error> {
66 Ok(self.get(params, "json").call()?.into_json::<PricingResponse>()?)
67 }
68}