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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
//! Me interface

use hyper::client::connect::Connect;

use files::MyFiles;
use games::MyGames;
use mods::MyMods;
use types::mods::Mod;
use types::Event;
use types::User;
use EventListOptions;
use Future;
use Modio;
use ModioListResponse;
use QueryParams;

pub use types::mods::Rating;

/// Interface for resources owned by the authenticated user or is team member of.
pub struct Me<C>
where
    C: Clone + Connect + 'static,
{
    modio: Modio<C>,
}

impl<C: Clone + Connect + 'static> Me<C> {
    pub(crate) fn new(modio: Modio<C>) -> Self {
        Self { modio }
    }

    /// Return the authenticated user.
    pub fn authenticated_user(&self) -> Future<User> {
        self.modio.get("/me")
    }

    /// Return a reference to an interface that provides access to games the authenticated user
    /// added or is a team member of.
    pub fn games(&self) -> MyGames<C> {
        MyGames::new(self.modio.clone())
    }

    /// Return a reference to an interface that provides access to mods the authenticated user
    /// added or is a team member of.
    pub fn mods(&self) -> MyMods<C> {
        MyMods::new(self.modio.clone())
    }

    /// Return a reference to an interface that provides access to modfiles the authenticated user
    /// uploaded.
    pub fn files(&self) -> MyFiles<C> {
        MyFiles::new(self.modio.clone())
    }

    /// Return the events that have been fired specific to the authenticated user.
    pub fn events(&self, options: &EventListOptions) -> Future<ModioListResponse<Event>> {
        let mut uri = vec!["/me/events".to_owned()];
        let query = options.to_query_params();
        if !query.is_empty() {
            uri.push(query);
        }
        self.modio.get(&uri.join("?"))
    }

    /// Return all mod's the authenticated user is subscribed to.
    pub fn subscriptions(
        &self,
        options: &SubscriptionsListOptions,
    ) -> Future<ModioListResponse<Mod>> {
        let mut uri = vec!["/me/subscribed".to_owned()];
        let query = options.to_query_params();
        if !query.is_empty() {
            uri.push(query);
        }
        self.modio.get(&uri.join("?"))
    }

    /// Return all mod rating's submitted by the authenticated user.
    pub fn ratings(&self, options: &RatingsListOptions) -> Future<ModioListResponse<Rating>> {
        let mut uri = vec!["/me/ratings".to_owned()];
        let query = options.to_query_params();
        if !query.is_empty() {
            uri.push(query);
        }
        self.modio.get(&uri.join("?"))
    }
}

filter_options!{
    /// Options used to filter subscription listings.
    ///
    /// # Filter parameters
    /// - _q
    /// - id
    /// - game_id
    /// - submitted_by
    /// - date_added
    /// - date_updated
    /// - date_live
    /// - name
    /// - name_id
    /// - summary
    /// - description
    /// - homepage_url
    /// - metadata_blob
    /// - tags
    ///
    /// # Sorting
    /// - id
    /// - name
    /// - downloads
    /// - popular
    /// - ratings
    /// - subscribers
    ///
    /// See the [mod.io docs](https://docs.mod.io/#get-user-subscriptions) for more informations.
    ///
    /// By default this returns up to `100` items. You can limit the result using `limit` and
    /// `offset`.
    /// # Example
    /// ```
    /// use modio::filter::{Order, Operator};
    /// use modio::me::SubscriptionsListOptions;
    ///
    /// let mut opts = SubscriptionsListOptions::new();
    /// opts.game_id(Operator::In, vec![1, 2]);
    /// opts.sort_by(SubscriptionsListOptions::DATE_UPDATED, Order::Desc);
    /// ```
    #[derive(Debug)]
    pub struct SubscriptionsListOptions {
        Filters
        - id = "id";
        - game_id = "game_id";
        - submitted_by = "submitted_by";
        - date_added = "date_added";
        - date_updated = "date_updated";
        - date_live = "date_live";
        - name = "name";
        - name_id = "name_id";
        - summary = "summary";
        - description = "description";
        - homepage_url = "homepage_url";
        - metadata_blob = "metadata_blob";
        - tags = "tags";

        Sort
        - ID = "id";
        - GAME_ID = "game_id";
        - DATE_UPDATED = "date_updated";
        - NAME = "name";
        - DOWNLOADS = "downloads";
        - POPULAR = "popular";
        - RATINGS = "ratings";
        - SUBSCRIBERS = "subscribers";
    }
}

filter_options!{
    /// Options used to filter rating listings.
    ///
    /// # Filter parameters
    /// - _q
    /// - game_id
    /// - mod_id
    /// - date_added
    ///
    /// See the [mod.io docs](https://docs.mod.io/#get-user-ratings) for more informations.
    ///
    /// By default this returns up to `100` items. You can limit the result using `limit` and
    /// `offset`.
    /// # Example
    /// ```
    /// use modio::filter::{Order, Operator};
    /// use modio::me::RatingsListOptions;
    ///
    /// let mut opts = RatingsListOptions::new();
    /// opts.game_id(Operator::In, vec![1, 2]);
    /// opts.sort_by(RatingsListOptions::DATE_ADDED, Order::Desc);
    /// ```
    #[derive(Debug)]
    pub struct RatingsListOptions {
        Filters
        - game_id = "game_id";
        - mod_id = "mod_id";
        - date_added = "date_added";

        Sort
        - GAME_ID = "game_id";
        - MOD_ID = "mod_id";
        - DATE_ADDED = "date_added";
    }
}