1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
use crate::error::{VkApiError, VkError};
use crate::{ParamGrid, send_request, VkApi};

const API: &str = "https://api.vk.com/method/market.";


pub async fn delete(api: &VkApi, owner_id:i64, item_id:usize) -> Result<u8, VkApiError> {
    let mut params = ParamGrid::new();
    params.insert_if_not_exists("owner_id", owner_id);
    params.insert_if_not_exists("item_id", item_id);

    let response_text = send_request(
        &api.client,
        Some(params),
        &format!("{}delete", API),
        &api.flow_key,
        api.v,
    )
    .await?;

    if let Ok(error) = serde_json::from_str::<VkError>(&response_text) {
        return Err(VkApiError::VkError(error));
    }

    Ok(1)
}

pub async fn delete_property(api: &VkApi, group_id:usize, property_id:usize) -> Result<u8, VkApiError> {
    let mut params = ParamGrid::new();
    params.insert_if_not_exists("group_id", group_id);
    params.insert_if_not_exists("property_id", property_id);

    let response_text = send_request(
        &api.client,
        Some(params),
        &format!("{}deleteProperty", API),
        &api.flow_key,
        api.v,
    )
        .await?;

    if let Ok(error) = serde_json::from_str::<VkError>(&response_text) {
        return Err(VkApiError::VkError(error));
    }

    Ok(1)
}

pub async fn ungroup_items(api: &VkApi, group_id:i64, item_group_id:usize) -> Result<u8, VkApiError> {
    let mut params = ParamGrid::new();
    params.insert_if_not_exists("group_id", group_id);
    params.insert_if_not_exists("item_group_id", item_group_id);

    let response_text = send_request(
        &api.client,
        Some(params),
        &format!("{}ungroupItems", API),
        &api.flow_key,
        api.v,
    )
        .await?;

    if let Ok(error) = serde_json::from_str::<VkError>(&response_text) {
        return Err(VkApiError::VkError(error));
    }

    Ok(1)
}