headhunter_bindings/
request.rs

1use serde::{Serialize, de::DeserializeOwned};
2use std::fmt::Display;
3
4/// Trait for convenient work with different types of requests and simultaneous connection
5/// with the response data type using the trait associated types
6pub trait Request: Serialize {
7    /// Response type that can be deserialized with serde
8    type Response: DeserializeOwned;
9
10    /// Returns string query to API to invoke current request
11    fn method() -> Option<&'static str> {
12        None
13    }
14
15    /// Builds a url with parameter for POST, PUT, DELETE requests
16    fn build_url<T: Display>(_: T) -> Option<String> {
17        None
18    }
19}
20
21/// Request that is used to get the temporary code from the OAuth service
22#[derive(Debug, Serialize)]
23pub struct UserAuthorizationRequest<'a> {
24    pub response_type: &'a str,
25    pub client_id: &'a str,
26}
27
28impl<'a> Request for UserAuthorizationRequest<'a> {
29    type Response = ();
30
31    fn method() -> Option<&'static str> {
32        Some("oauth/authorize")
33    }
34}
35
36/// Request that is used to get access token from the temporary code
37#[derive(Debug, Serialize)]
38pub struct UserOpenAuthorizationRequest<'a> {
39    pub grant_type: &'a str,
40    pub client_id: &'a str,
41    pub client_secret: &'a str,
42    pub code: &'a str,
43}
44
45impl<'a> Request for UserOpenAuthorizationRequest<'a> {
46    type Response = super::response::UserOpenAuthorizationResponse;
47
48    fn method() -> Option<&'static str> {
49        Some("oauth/token")
50    }
51}
52
53/// Request that is used to renew access token
54#[derive(Debug, Serialize)]
55pub struct UserRenewOpenAuthorizationRequest<'a> {
56    pub grant_type: &'a str,
57    pub refresh_token: &'a str,
58}
59
60impl<'a> Request for UserRenewOpenAuthorizationRequest<'a> {
61    type Response = super::response::UserOpenAuthorizationResponse;
62
63    fn method() -> Option<&'static str> {
64        Some("oauth/token")
65    }
66}
67
68/// Request that can get user information, useful for checking token
69#[derive(Debug, Serialize)]
70pub struct MeRequest;
71
72impl Request for MeRequest {
73    type Response = super::response::MeResponse;
74
75    fn method() -> Option<&'static str> {
76        Some("me")
77    }
78}
79
80/// Request that can get list of submitted resumes
81#[derive(Debug, Serialize)]
82pub struct MineResumesRequest;
83
84impl Request for MineResumesRequest {
85    type Response = super::response::MineResumesResponse;
86
87    fn method() -> Option<&'static str> {
88        Some("resumes/mine")
89    }
90}
91
92/// Request that can publish new information in existing resume
93#[derive(Debug, Serialize)]
94pub struct PublishResumeRequest;
95
96impl Request for PublishResumeRequest {
97    type Response = ();
98
99    fn build_url<T: Display>(resume_id: T) -> Option<String> {
100        Some(format!("resumes/{resume_id}/publish"))
101    }
102}