<commit_before>//
//  Accounts.swift
//  MastodonKit
//
//  Created by <NAME> on 4/9/17.
//  Copyright © 2017 MastodonKit. All rights reserved.
//

import Foundation

/// `Accounts` requests.
public enum Accounts {
    /// Fetches an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func account(id: String) -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/\(id)")
    }

    /// Gets the current user.
    ///
    /// - Returns: Request for `Account`.
    public static func currentUser() -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/verify_credentials")
    }

    /// Updates the current user.
    ///
    /// - Parameters:
    ///   - displayName: The name to display in the user's profile.
    ///   - note: A new biography for the user.
    ///   - avatar: The media attachment to display as the user's avatar.
    ///   - header: The media attachment to display as the user's header image.
    /// - Returns: Request for `Account`.
    public static func updateCurrentUser(displayName: String? = nil,
                                         note: String? = nil,
                                         avatar: MediaAttachment? = nil,
                                         header: MediaAttachment? = nil) -> Request<Account> {
        let parameters = [
            Parameter(name: "display_name", value: displayName),
            Parameter(name: "note", value: note),
            Parameter(name: "avatar", value: avatar?.base64EncondedString),
            Parameter(name: "header", value: header?.base64EncondedString)
        ]

        let method = HTTPMethod.patch(.parameters(parameters))
        return Request<Account>(path: "/api/v1/accounts/update_credentials", method: method)
    }

    /// Gets an account's followers.
    ///
    /// - Parameters:
    ///   - id: The account id.
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Account]`.
    public static func followers(id: String, range: RequestRange = .default) -> Request<[Account]> {
        let parameters = range.parameters(limit: between(1, and: 80, default: 40))
        let method = HTTPMethod.get(.parameters(parameters))

        return Request<[Account]>(path: "/api/v1/accounts/\(id)/followers", method: method)
    }

    /// Gets who account is following.
    ///
    /// - Parameters:
    ///   - id: The account id
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Account]`.
    public static func following(id: String, range: RequestRange = .default) -> Request<[Account]> {
        let parameters = range.parameters(limit: between(1, and: 80, default: 40))
        let method = HTTPMethod.get(.parameters(parameters))

        return Request<[Account]>(path: "/api/v1/accounts/\(id)/following", method: method)
    }

    /// Gets an account's statuses.
    ///
    /// - Parameters:
    ///   - id: The account id.
    ///   - mediaOnly: Only return statuses that have media attachments.
    ///   - pinnedOnly: Only return statuses that have been pinned.
    ///   - excludeReplies: Skip statuses that reply to other statuses.
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Status]`.
    public static func statuses(id: String,
                                mediaOnly: Bool? = nil,
                                pinnedOnly: Bool? = nil,
                                excludeReplies: Bool? = nil,
                                range: RequestRange = .default) -> Request<[Status]> {
        let rangeParameters = range.parameters(limit: between(1, and: 40, default: 20)) ?? []
        let parameters = rangeParameters + [
            Parameter(name: "only_media", value: mediaOnly.flatMap(trueOrNil)),
            Parameter(name: "pinned", value: pinnedOnly.flatMap(trueOrNil)),
            Parameter(name: "exclude_replies", value: excludeReplies.flatMap(trueOrNil))
        ]

        let method = HTTPMethod.get(.parameters(parameters))
        return Request<[Status]>(path: "/api/v1/accounts/\(id)/statuses", method: method)
    }

    /// Follows an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func follow(id: String) -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/\(id)/follow", method: .post(.empty))
    }

    /// Unfollow an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func unfollow(id: String) -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/\(id)/unfollow", method: .post(.empty))
    }

    /// Follows a remote user:.
    ///
    /// - Parameter uri: The 'username@domain' of the remote user to follow.
    /// - Returns: Request for `Account`.
    public static func remoteFollow(uri: String) -> Request<Account> {
        let parameter = [Parameter(name: "uri", value: uri)]
        let method = HTTPMethod.post(.parameters(parameter))

        return Request<Account>(path: "/api/v1/follows", method: method)<commit_msg>Follow and Unfollow returns a Relationship, not an Account<commit_after>//
//  Accounts.swift
//  MastodonKit
//
//  Created by Ornithologist Coder on 4/9/17.
//  Copyright © 2017 MastodonKit. All rights reserved.
//

import Foundation

/// `Accounts` requests.
public enum Accounts {
    /// Fetches an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func account(id: String) -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/\(id)")
    }

    /// Gets the current user.
    ///
    /// - Returns: Request for `Account`.
    public static func currentUser() -> Request<Account> {
        return Request<Account>(path: "/api/v1/accounts/verify_credentials")
    }

    /// Updates the current user.
    ///
    /// - Parameters:
    ///   - displayName: The name to display in the user's profile.
    ///   - note: A new biography for the user.
    ///   - avatar: The media attachment to display as the user's avatar.
    ///   - header: The media attachment to display as the user's header image.
    /// - Returns: Request for `Account`.
    public static func updateCurrentUser(displayName: String? = nil,
                                         note: String? = nil,
                                         avatar: MediaAttachment? = nil,
                                         header: MediaAttachment? = nil) -> Request<Account> {
        let parameters = [
            Parameter(name: "display_name", value: displayName),
            Parameter(name: "note", value: note),
            Parameter(name: "avatar", value: avatar?.base64EncondedString),
            Parameter(name: "header", value: header?.base64EncondedString)
        ]

        let method = HTTPMethod.patch(.parameters(parameters))
        return Request<Account>(path: "/api/v1/accounts/update_credentials", method: method)
    }

    /// Gets an account's followers.
    ///
    /// - Parameters:
    ///   - id: The account id.
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Account]`.
    public static func followers(id: String, range: RequestRange = .default) -> Request<[Account]> {
        let parameters = range.parameters(limit: between(1, and: 80, default: 40))
        let method = HTTPMethod.get(.parameters(parameters))

        return Request<[Account]>(path: "/api/v1/accounts/\(id)/followers", method: method)
    }

    /// Gets who account is following.
    ///
    /// - Parameters:
    ///   - id: The account id
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Account]`.
    public static func following(id: String, range: RequestRange = .default) -> Request<[Account]> {
        let parameters = range.parameters(limit: between(1, and: 80, default: 40))
        let method = HTTPMethod.get(.parameters(parameters))

        return Request<[Account]>(path: "/api/v1/accounts/\(id)/following", method: method)
    }

    /// Gets an account's statuses.
    ///
    /// - Parameters:
    ///   - id: The account id.
    ///   - mediaOnly: Only return statuses that have media attachments.
    ///   - pinnedOnly: Only return statuses that have been pinned.
    ///   - excludeReplies: Skip statuses that reply to other statuses.
    ///   - range: The bounds used when requesting data from Mastodon.
    /// - Returns: Request for `[Status]`.
    public static func statuses(id: String,
                                mediaOnly: Bool? = nil,
                                pinnedOnly: Bool? = nil,
                                excludeReplies: Bool? = nil,
                                range: RequestRange = .default) -> Request<[Status]> {
        let rangeParameters = range.parameters(limit: between(1, and: 40, default: 20)) ?? []
        let parameters = rangeParameters + [
            Parameter(name: "only_media", value: mediaOnly.flatMap(trueOrNil)),
            Parameter(name: "pinned", value: pinnedOnly.flatMap(trueOrNil)),
            Parameter(name: "exclude_replies", value: excludeReplies.flatMap(trueOrNil))
        ]

        let method = HTTPMethod.get(.parameters(parameters))
        return Request<[Status]>(path: "/api/v1/accounts/\(id)/statuses", method: method)
    }

    /// Follows an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func follow(id: String) -> Request<Relationship> {
        return Request<Relationship>(path: "/api/v1/accounts/\(id)/follow", method: .post(.empty))
    }

    /// Unfollow an account.
    ///
    /// - Parameter id: The account id.
    /// - Returns: Request for `Account`.
    public static func unfollow(id: String) -> Request<Relationship> {
        return Request<Relationship>(path: "/api/v1/accounts/\(id)/unfollow", method: .post(.empty))
    }

    /// Follows a remote user:.
    ///
    /// - Parameter uri: The 'username@domain' of the remote user to follow.
    /// - Returns: Request for `Account`.
    public static func remoteFollow(uri: String) -> Request<Account> {
        let parameter = [Parameter(name: "uri", value: uri)]
        let method = HTTPMethod.post(.parameters(parameter))

        return Request<Account>(path: "/api/v1/follows", method: method)
{'fraction_non_alphanumeric': 0.13841059602649006, 'fraction_numerical': 0.006811731315042573, 'mean_word_length': 2.1219728292971056, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 58, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5314327', 'n_tokens_mistral': 2991, 'n_tokens_neox': 2848, 'n_words': 850}