update method

Future<void> update(
  1. SubredditSettings updated
)

Update the Subreddits settings.

Implementation

Future<void> update(SubredditSettings updated) async {
  final data = Map<String, dynamic>.from(updated._data);
  final remap = <String, String>{
    'allow_top': 'default_set',
    'lang': 'language',
    'link_type': 'content_options',
    'type': 'subreddit_type',
    'sr': 'subreddit_id',
  };

  // Remap keys to what Reddit expects (this is dumb on their part).
  remap.forEach((k, v) {
    if (data[v] != null) {
      data[k] = data[v];
      data.remove(v);
    }
  });

  // Not a valid key for the response.
  if (data.containsKey('domain')) {
    data.remove('domain');
  }

  // Cleanup the map before we send the request.
  data.forEach((k, v) {
    if (v == null) {
      data[k] = 'null';
    } else {
      data[k] = v.toString();
    }
  });

  data['api_type'] = 'json';
  return _subreddit.reddit
      .post(apiPath['site_admin'], data.cast<String, String>());
}