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
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//! Response module contains all the structures necessary
//! for doing all the interesting stuff.

/// Represents a strong type on the grammarly bot version.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct GrammarlyVersion(pub String);

/// Represents a strong type on the grammarly api version.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct ApiVersion(pub u64);

/// Represents a bot info.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Software {
    /// The name of the bot.
    pub name: String,
    /// The grammarly's bot version
    pub version: GrammarlyVersion,
    /// The api version used.
    #[serde(rename = "apiVersion")]
    pub api_version: ApiVersion,
    /// Is true if the API key used is premium one.
    pub premium: bool,
    /// Contains premium hint. If the API key is not a premium one,
    /// suggests to get one.
    #[serde(rename = "premiumHint")]
    pub premium_hint: String,
    /// Grammarly bot check status.
    pub status: String,
}

/// Represents warnings in the response. They are useful
/// but could be ignored (not necessarily fixed) and they
/// should be treated as an advice.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Warnings {
    /// True if results are incompleted.
    #[serde(rename = "incompleteResults")]
    pub incomplete_results: bool,
    // TODO Check for other values.
}

/// Detected language code and name, determined by the
/// grammarly bot.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct DetectedLanguage {
    /// The language name.
    pub name: String,
    /// The language code.
    pub code: String,
}

/// Passed language and detected language information.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct LanguageDetails {
    /// The language name.
    pub name: String,
    /// The language code.
    pub code: String,
    /// The language detected by the grammarly bot.
    #[serde(rename = "detectedLanguage")]
    pub detected_language: DetectedLanguage,
}

/// Represents a single possible replacement of the word.
/// If you have mispelled a word, the service advises you
/// to correct the word and all the corrections are suggested
/// using these `Replacement` objects.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Replacement {
    /// The suggested word to change to.
    pub value: String,
}

/// Represents the problem context, a sentence, or a subsentence.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Context {
    /// The context itself.
    pub text: String,
    /// The word's offset causing the problem inside the context.
    pub offset: u64,
    /// The length of the word in the context.
    pub length: u64,
}

/// Represents a single problem found.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Match {
    /// Problem detailed explanation.
    pub message: String,
    /// Short explanation, the type of a problem.
    #[serde(rename = "shortMessage")]
    pub short_message: String,
    /// All the replacement suggestions.
    pub replacements: Vec<Replacement>,
    /// Offset from the beginning of the passed text.
    pub offset: u64,
    /// The length of the word causing the problem.
    pub length: u64,
    /// The context in which the problem was found.
    pub context: Context,
    /// The whole sentence where the problem was found.
    pub sentence: String,
    // TODO specify other fields...
}

/// Grammarly's main response structure.
#[derive(Debug, Default, Clone, serde::Deserialize)]
pub struct Response {
    /// Grammarly bot information.
    pub software: Software,
    /// Grammarly bot warnings.
    pub warnings: Warnings,
    /// Language information.
    pub language: LanguageDetails,
    /// Problems found.
    pub matches: Vec<Match>,
}