cryptoapis/apis/
manage_subscriptions_api.rs

1/*
2 * CryptoAPIs
3 *
4 * Crypto APIs is a complex and innovative infrastructure layer that radically simplifies the development of any Blockchain and Crypto related applications. Organized around REST, Crypto APIs can assist both novice Bitcoin/Ethereum enthusiasts and crypto experts with the development of their blockchain applications. Crypto APIs provides unified endpoints and data, raw data, automatic tokens and coins forwardings, callback functionalities, and much more.
5 *
6 * The version of the OpenAPI document: 2021-03-20
7 * Contact: developers@cryptoapis.io
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12use reqwest;
13
14use crate::apis::ResponseContent;
15use super::{Error, configuration};
16
17
18/// struct for typed errors of method `activate_blockchain_event_subscription`
19#[derive(Debug, Clone, Serialize, Deserialize)]
20#[serde(untagged)]
21pub enum ActivateBlockchainEventSubscriptionError {
22    Status400(crate::models::InlineResponse40083),
23    Status401(crate::models::InlineResponse40183),
24    Status402(crate::models::InlineResponse402),
25    Status403(crate::models::InlineResponse40383),
26    Status404(crate::models::InlineResponse4041),
27    Status409(crate::models::InlineResponse409),
28    Status415(crate::models::InlineResponse415),
29    Status422(crate::models::InlineResponse422),
30    Status429(crate::models::InlineResponse429),
31    Status500(crate::models::InlineResponse500),
32    UnknownValue(serde_json::Value),
33}
34
35/// struct for typed errors of method `delete_blockchain_event_subscription`
36#[derive(Debug, Clone, Serialize, Deserialize)]
37#[serde(untagged)]
38pub enum DeleteBlockchainEventSubscriptionError {
39    Status400(crate::models::InlineResponse40084),
40    Status401(crate::models::InlineResponse40184),
41    Status402(crate::models::InlineResponse402),
42    Status403(crate::models::InlineResponse40384),
43    Status404(crate::models::InlineResponse4041),
44    Status409(crate::models::InlineResponse409),
45    Status415(crate::models::InlineResponse415),
46    Status422(crate::models::InlineResponse422),
47    Status429(crate::models::InlineResponse429),
48    Status500(crate::models::InlineResponse500),
49    UnknownValue(serde_json::Value),
50}
51
52/// struct for typed errors of method `get_blockchain_event_subscription_details_by_reference_id`
53#[derive(Debug, Clone, Serialize, Deserialize)]
54#[serde(untagged)]
55pub enum GetBlockchainEventSubscriptionDetailsByReferenceIdError {
56    Status400(crate::models::InlineResponse40082),
57    Status401(crate::models::InlineResponse40182),
58    Status402(crate::models::InlineResponse402),
59    Status403(crate::models::InlineResponse40382),
60    Status404(crate::models::InlineResponse4041),
61    Status409(crate::models::InlineResponse409),
62    Status415(crate::models::InlineResponse415),
63    Status422(crate::models::InlineResponse422),
64    Status429(crate::models::InlineResponse429),
65    Status500(crate::models::InlineResponse500),
66    UnknownValue(serde_json::Value),
67}
68
69/// struct for typed errors of method `list_blockchain_events_subscriptions`
70#[derive(Debug, Clone, Serialize, Deserialize)]
71#[serde(untagged)]
72pub enum ListBlockchainEventsSubscriptionsError {
73    Status400(crate::models::InlineResponse40081),
74    Status401(crate::models::InlineResponse40181),
75    Status402(crate::models::InlineResponse402),
76    Status403(crate::models::InlineResponse40381),
77    Status409(crate::models::InlineResponse409),
78    Status415(crate::models::InlineResponse415),
79    Status422(crate::models::InlineResponse422),
80    Status429(crate::models::InlineResponse429),
81    Status500(crate::models::InlineResponse500),
82    UnknownValue(serde_json::Value),
83}
84
85
86/// Through this endpoint customers can reactivate an event subscription (callback) which has been deactivated by the system. Deactivations could happen due to various reasons, most often \"maximum retry attempts reached\".
87pub async fn activate_blockchain_event_subscription(configuration: &configuration::Configuration, reference_id: &str, context: Option<&str>, activate_blockchain_event_subscription_rb: Option<crate::models::ActivateBlockchainEventSubscriptionRb>) -> Result<crate::models::ActivateBlockchainEventSubscriptionR, Error<ActivateBlockchainEventSubscriptionError>> {
88
89    let local_var_client = &configuration.client;
90
91    let local_var_uri_str = format!("{}/blockchain-events/subscriptions/{referenceId}/activate", configuration.base_path, referenceId=crate::apis::urlencode(reference_id));
92    let mut local_var_req_builder = local_var_client.request(reqwest::Method::POST, local_var_uri_str.as_str());
93
94    if let Some(ref local_var_str) = context {
95        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
96    }
97    if let Some(ref local_var_user_agent) = configuration.user_agent {
98        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
99    }
100    if let Some(ref local_var_apikey) = configuration.api_key {
101        let local_var_key = local_var_apikey.key.clone();
102        let local_var_value = match local_var_apikey.prefix {
103            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
104            None => local_var_key,
105        };
106        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
107    };
108    local_var_req_builder = local_var_req_builder.json(&activate_blockchain_event_subscription_rb);
109
110    let local_var_req = local_var_req_builder.build()?;
111    let local_var_resp = local_var_client.execute(local_var_req).await?;
112
113    let local_var_status = local_var_resp.status();
114    let local_var_content = local_var_resp.text().await?;
115
116    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
117        serde_json::from_str(&local_var_content).map_err(Error::from)
118    } else {
119        let local_var_entity: Option<ActivateBlockchainEventSubscriptionError> = serde_json::from_str(&local_var_content).ok();
120        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
121        Err(Error::ResponseError(local_var_error))
122    }
123}
124
125/// Through this endpoint the customer can delete blockchain event subscriptions they have by attributes `referenceId` and `network`.    Currently Crypto APIs 2.0 offers certain Blockchain event endpoints which allow the user to subscribe for one/a few/all and receive callback notifications when the specific event occurs.    {note}To have an operational callback subscription, you need to first verify a domain for the Callback URL. Please see more information on Callbacks [here](https://developers.cryptoapis.io/technical-documentation/general-information/callbacks#callback-url).{/note}    {warning}Crypto APIs will notify the user **only when** the event occurs. There are cases when the specific event doesn't happen at all, or takes a long time to do so. A callback notification **will not** be sent if the event does not or cannot occur, or will take long time to occur.{/warning}
126pub async fn delete_blockchain_event_subscription(configuration: &configuration::Configuration, blockchain: &str, network: &str, reference_id: &str, context: Option<&str>) -> Result<crate::models::DeleteBlockchainEventSubscriptionR, Error<DeleteBlockchainEventSubscriptionError>> {
127
128    let local_var_client = &configuration.client;
129
130    let local_var_uri_str = format!("{}/blockchain-events/{blockchain}/{network}/subscriptions/{referenceId}", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network), referenceId=crate::apis::urlencode(reference_id));
131    let mut local_var_req_builder = local_var_client.request(reqwest::Method::DELETE, local_var_uri_str.as_str());
132
133    if let Some(ref local_var_str) = context {
134        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
135    }
136    if let Some(ref local_var_user_agent) = configuration.user_agent {
137        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
138    }
139    if let Some(ref local_var_apikey) = configuration.api_key {
140        let local_var_key = local_var_apikey.key.clone();
141        let local_var_value = match local_var_apikey.prefix {
142            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
143            None => local_var_key,
144        };
145        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
146    };
147
148    let local_var_req = local_var_req_builder.build()?;
149    let local_var_resp = local_var_client.execute(local_var_req).await?;
150
151    let local_var_status = local_var_resp.status();
152    let local_var_content = local_var_resp.text().await?;
153
154    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
155        serde_json::from_str(&local_var_content).map_err(Error::from)
156    } else {
157        let local_var_entity: Option<DeleteBlockchainEventSubscriptionError> = serde_json::from_str(&local_var_content).ok();
158        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
159        Err(Error::ResponseError(local_var_error))
160    }
161}
162
163/// Through this endpoint the customer can get detailed information for a callback subscription by providing its reference ID.    Currently Crypto APIs 2.0 offers certain Blockchain event endpoints which allow the user to subscribe for one/a few/all and receive callback notifications when the specific event occurs.
164pub async fn get_blockchain_event_subscription_details_by_reference_id(configuration: &configuration::Configuration, reference_id: &str, context: Option<&str>) -> Result<crate::models::GetBlockchainEventSubscriptionDetailsByReferenceIdr, Error<GetBlockchainEventSubscriptionDetailsByReferenceIdError>> {
165
166    let local_var_client = &configuration.client;
167
168    let local_var_uri_str = format!("{}/blockchain-events/subscriptions/{referenceId}", configuration.base_path, referenceId=crate::apis::urlencode(reference_id));
169    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
170
171    if let Some(ref local_var_str) = context {
172        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
173    }
174    if let Some(ref local_var_user_agent) = configuration.user_agent {
175        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
176    }
177    if let Some(ref local_var_apikey) = configuration.api_key {
178        let local_var_key = local_var_apikey.key.clone();
179        let local_var_value = match local_var_apikey.prefix {
180            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
181            None => local_var_key,
182        };
183        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
184    };
185
186    let local_var_req = local_var_req_builder.build()?;
187    let local_var_resp = local_var_client.execute(local_var_req).await?;
188
189    let local_var_status = local_var_resp.status();
190    let local_var_content = local_var_resp.text().await?;
191
192    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
193        serde_json::from_str(&local_var_content).map_err(Error::from)
194    } else {
195        let local_var_entity: Option<GetBlockchainEventSubscriptionDetailsByReferenceIdError> = serde_json::from_str(&local_var_content).ok();
196        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
197        Err(Error::ResponseError(local_var_error))
198    }
199}
200
201/// Through this endpoint the customer can obtain a list of their callback subscriptions for the available Blockchain events.    Currently Crypto APIs 2.0 offers certain Blockchain event endpoints which allow the user to subscribe for one/a few/all and receive callback notifications when the specific event occurs.    {note}To have an operational callback subscription, you need to first verify a domain for the Callback URL. Please see more information on Callbacks [here](https://developers.cryptoapis.io/technical-documentation/general-information/callbacks#callback-url).{/note}
202pub async fn list_blockchain_events_subscriptions(configuration: &configuration::Configuration, blockchain: &str, network: &str, context: Option<&str>, limit: Option<i64>, offset: Option<i64>) -> Result<crate::models::ListBlockchainEventsSubscriptionsR, Error<ListBlockchainEventsSubscriptionsError>> {
203
204    let local_var_client = &configuration.client;
205
206    let local_var_uri_str = format!("{}/blockchain-events/{blockchain}/{network}/subscriptions", configuration.base_path, blockchain=crate::apis::urlencode(blockchain), network=crate::apis::urlencode(network));
207    let mut local_var_req_builder = local_var_client.request(reqwest::Method::GET, local_var_uri_str.as_str());
208
209    if let Some(ref local_var_str) = context {
210        local_var_req_builder = local_var_req_builder.query(&[("context", &local_var_str.to_string())]);
211    }
212    if let Some(ref local_var_str) = limit {
213        local_var_req_builder = local_var_req_builder.query(&[("limit", &local_var_str.to_string())]);
214    }
215    if let Some(ref local_var_str) = offset {
216        local_var_req_builder = local_var_req_builder.query(&[("offset", &local_var_str.to_string())]);
217    }
218    if let Some(ref local_var_user_agent) = configuration.user_agent {
219        local_var_req_builder = local_var_req_builder.header(reqwest::header::USER_AGENT, local_var_user_agent.clone());
220    }
221    if let Some(ref local_var_apikey) = configuration.api_key {
222        let local_var_key = local_var_apikey.key.clone();
223        let local_var_value = match local_var_apikey.prefix {
224            Some(ref local_var_prefix) => format!("{} {}", local_var_prefix, local_var_key),
225            None => local_var_key,
226        };
227        local_var_req_builder = local_var_req_builder.header("x-api-key", local_var_value);
228    };
229
230    let local_var_req = local_var_req_builder.build()?;
231    let local_var_resp = local_var_client.execute(local_var_req).await?;
232
233    let local_var_status = local_var_resp.status();
234    let local_var_content = local_var_resp.text().await?;
235
236    if !local_var_status.is_client_error() && !local_var_status.is_server_error() {
237        serde_json::from_str(&local_var_content).map_err(Error::from)
238    } else {
239        let local_var_entity: Option<ListBlockchainEventsSubscriptionsError> = serde_json::from_str(&local_var_content).ok();
240        let local_var_error = ResponseContent { status: local_var_status, content: local_var_content, entity: local_var_entity };
241        Err(Error::ResponseError(local_var_error))
242    }
243}
244