-
Notifications
You must be signed in to change notification settings - Fork 2
Add Support Tickets + Eligibility endpoints #743
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
jkmassel
wants to merge
3
commits into
trunk
Choose a base branch
from
add/support-forms
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
wp_api/src/wp_com/endpoint/support_eligibility_endpoint.rs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
use wp_derive_request_builder::WpDerivedRequest; | ||
|
||
use crate::{ | ||
request::endpoint::{AsNamespace, DerivedRequest}, | ||
wp_com::{WpComNamespace, support_eligibility::SupportEligibility}, | ||
}; | ||
|
||
#[derive(WpDerivedRequest)] | ||
enum SupportEligibilityRequest { | ||
#[get(url = "/mobile-support/eligibility", output = SupportEligibility)] | ||
GetSupportEligibility, | ||
} | ||
|
||
impl DerivedRequest for SupportEligibilityRequest { | ||
fn namespace() -> impl AsNamespace { | ||
WpComNamespace::V2 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
use crate::{ | ||
request::endpoint::{AsNamespace, DerivedRequest}, | ||
wp_com::{ | ||
WpComNamespace, | ||
support_tickets::{ | ||
AddMessageToSupportConversationParams, ConversationId, CreateSupportTicketParams, | ||
SupportConversation, SupportConversationSummary, | ||
}, | ||
}, | ||
}; | ||
use wp_derive_request_builder::WpDerivedRequest; | ||
|
||
#[derive(WpDerivedRequest)] | ||
enum SupportTicketsRequest { | ||
#[post(url = "/mobile-support/conversations", params = &CreateSupportTicketParams, output = SupportConversation)] | ||
CreateSupportTicket, | ||
#[get(url = "/mobile-support/conversations", output = Vec<SupportConversationSummary>)] | ||
GetSupportConversationList, | ||
#[get(url = "/mobile-support/conversations/<conversation_id>", output = SupportConversation)] | ||
GetSupportConversation, | ||
#[post(url = "/mobile-support/conversations/<conversation_id>", params = &AddMessageToSupportConversationParams, output = SupportConversation)] | ||
AddMessageToSupportConversation, | ||
} | ||
|
||
impl DerivedRequest for SupportTicketsRequest { | ||
fn namespace() -> impl AsNamespace { | ||
WpComNamespace::V2 | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportEligibility { | ||
pub is_user_eligible: bool, | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,145 @@ | ||
use std::collections::HashMap; | ||
|
||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{date::WpGmtDateTime, impl_as_query_value_for_new_type}; | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, uniffi::Record)] | ||
pub struct CreateSupportTicketParams { | ||
pub subject: String, | ||
pub message: String, | ||
pub application: String, | ||
#[uniffi(default = None)] | ||
#[serde(skip_serializing_if = "Option::is_none")] | ||
pub wpcom_site_id: Option<u64>, | ||
#[uniffi(default = [])] | ||
pub tags: Vec<String>, | ||
#[uniffi(default = [])] | ||
pub attachments: Vec<String>, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportConversationSummary { | ||
pub id: ConversationId, | ||
pub title: String, | ||
pub description: String, | ||
pub status: String, | ||
pub created_at: WpGmtDateTime, | ||
pub updated_at: WpGmtDateTime, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportConversation { | ||
pub id: ConversationId, | ||
pub title: String, | ||
pub description: String, | ||
pub status: String, | ||
pub created_at: WpGmtDateTime, | ||
pub updated_at: WpGmtDateTime, | ||
pub messages: Vec<SupportMessage>, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportMessage { | ||
pub id: u64, | ||
pub content: String, | ||
pub author: SupportMessageAuthor, | ||
pub role: String, | ||
pub author_is_current_user: bool, | ||
pub created_at: WpGmtDateTime, | ||
pub attachments: Vec<SupportAttachment>, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportUserIdentity { | ||
pub id: u64, | ||
pub email: String, | ||
pub display_name: String, | ||
pub avatar_url: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportAttachment { | ||
pub id: u64, | ||
pub filename: String, | ||
pub content_type: String, | ||
pub size: u64, | ||
pub url: String, | ||
pub metadata: HashMap<String, AttachmentMetadataValue>, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Enum)] | ||
#[serde(untagged)] | ||
pub enum SupportMessageAuthor { | ||
User(SupportUserIdentity), | ||
SupportAgent(SupportAgentIdentity), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should there be an "other" variant, just in case the "role" value is some other value, like "system" messages? |
||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Enum, strum_macros::Display)] | ||
#[strum(serialize_all = "snake_case")] | ||
pub enum AttachmentMetadataKey { | ||
Width, | ||
Height, | ||
Other(String), | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Enum)] | ||
#[serde(untagged)] | ||
pub enum AttachmentMetadataValue { | ||
String(String), | ||
Number(u64), | ||
Boolean(bool), | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, Deserialize, uniffi::Record)] | ||
pub struct SupportAgentIdentity { | ||
pub id: u64, | ||
pub name: String, | ||
} | ||
|
||
#[derive(Debug, PartialEq, Eq, Serialize, uniffi::Record)] | ||
pub struct AddMessageToSupportConversationParams { | ||
pub message: String, | ||
#[uniffi(default = [])] | ||
pub attachments: Vec<String>, | ||
} | ||
|
||
impl_as_query_value_for_new_type!(ConversationId); | ||
uniffi::custom_newtype!(ConversationId, u64); | ||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)] | ||
pub struct ConversationId(pub u64); | ||
|
||
impl std::str::FromStr for ConversationId { | ||
type Err = std::num::ParseIntError; | ||
|
||
fn from_str(s: &str) -> Result<Self, Self::Err> { | ||
s.parse().map(Self) | ||
} | ||
} | ||
|
||
impl std::fmt::Display for ConversationId { | ||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { | ||
write!(f, "{}", self.0) | ||
} | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::*; | ||
|
||
#[test] | ||
fn test_support_conversation_deserialization() { | ||
let json = include_str!("../../tests/wpcom/support_tickets/single-conversation.json"); | ||
let conversation: SupportConversation = | ||
serde_json::from_str(json).expect("Failed to deserialize support conversation"); | ||
assert_eq!(conversation.messages.len(), 7); | ||
} | ||
|
||
#[test] | ||
fn test_support_conversation_list_deserialization() { | ||
let json = include_str!("../../tests/wpcom/support_tickets/conversation-list.json"); | ||
let conversation_list: Vec<SupportConversationSummary> = | ||
serde_json::from_str(json).expect("Failed to deserialize support conversation list"); | ||
assert_eq!(conversation_list.len(), 11); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
At the moment how the
author
is parsed id depending on theSupportMessageAuthor
enum variant order: it's a "User" if the JSON can be parsed as an "User"; then it's a "Agent" if the JSON can be parsed as an "Agent". Would it be more correct to parseauthor
based on therole
value, instead of how theSupportMessageAuthor
enum type is declared?