<commit_before>//
//  AccessToken.swift
//  Heimdall
//
//  Created by <NAME> on 2/12/15.
//  Copyright (c) 2015 B264 GmbH. All rights reserved.
//

import Argo
import LlamaKit
import Runes

@objc
public class AccessToken {
    public let accessToken: String
    public let tokenType: String
    public let expiresAt: NSDate?
    public let refreshToken: String?

    public init(accessToken: String, tokenType: String, expiresAt: NSDate? = nil, refreshToken: String? = nil) {
        self.accessToken = accessToken
        self.tokenType = tokenType
        self.expiresAt = expiresAt
        self.refreshToken = refreshToken
    }
}

extension AccessToken: Equatable {}

public func == (lhs: AccessToken, rhs: AccessToken) -> Bool {
    return lhs.accessToken == rhs.accessToken
        && lhs.tokenType == rhs.tokenType
        && lhs.expiresAt == rhs.expiresAt
        && lhs.refreshToken == rhs.refreshToken
}

extension AccessToken: JSONDecodable {
    public class func create(accessToken: String)(tokenType: String)(expiresAt: NSDate?)(refreshToken: String?) -> AccessToken {
        return AccessToken(accessToken: accessToken, tokenType: tokenType, expiresAt: expiresAt, refreshToken: refreshToken)
    }

    public class func decode(data: NSData) -> AccessToken? {
        var error: NSError?

        if let json: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: &error) {
            return decode(JSONValue.parse(json))
        } else {
            return nil
        }
    }

    public class func decode(json: JSONValue) -> AccessToken? {
        return AccessToken.create
            <^> json <| "access_token"
            <*> json <| "token_type"
            <*> json <|? "expires_in"
            <*> json <|? "refresh_token"
    }
}<commit_msg>Reorder convenience decoding<commit_after>//
//  AccessToken.swift
//  Heimdall
//
//  Created by <NAME> on 2/12/15.
//  Copyright (c) 2015 B264 GmbH. All rights reserved.
//

import Argo
import LlamaKit
import Runes

@objc
public class AccessToken {
    public let accessToken: String
    public let tokenType: String
    public let expiresAt: NSDate?
    public let refreshToken: String?

    public init(accessToken: String, tokenType: String, expiresAt: NSDate? = nil, refreshToken: String? = nil) {
        self.accessToken = accessToken
        self.tokenType = tokenType
        self.expiresAt = expiresAt
        self.refreshToken = refreshToken
    }
}

extension AccessToken: Equatable {}

public func == (lhs: AccessToken, rhs: AccessToken) -> Bool {
    return lhs.accessToken == rhs.accessToken
        && lhs.tokenType == rhs.tokenType
        && lhs.expiresAt == rhs.expiresAt
        && lhs.refreshToken == rhs.refreshToken
}

extension AccessToken: JSONDecodable {
    public class func create(accessToken: String)(tokenType: String)(expiresAt: NSDate?)(refreshToken: String?) -> AccessToken {
        return AccessToken(accessToken: accessToken, tokenType: tokenType, expiresAt: expiresAt, refreshToken: refreshToken)
    }

    public class func decode(json: JSONValue) -> AccessToken? {
        return AccessToken.create
            <^> json <| "access_token"
            <*> json <| "token_type"
            <*> json <|? "expires_in"
            <*> json <|? "refresh_token"
    }

    public class func decode(data: NSData) -> AccessToken? {
        var error: NSError?

        if let json: AnyObject = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions(0), error: &error) {
            return decode(JSONValue.parse(json))
        } else {
            return nil
        }
    }
}
{'fraction_non_alphanumeric': 0.10711343037627026, 'fraction_numerical': 0.007140895358418017, 'mean_word_length': 2.853968253968254, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3797354', 'n_tokens_mistral': 1105, 'n_tokens_neox': 1060, 'n_words': 282}