<commit_before>//
//  DBShot.swift
//  DribbbleAPI
//
//  Created by <NAME> on 9/5/16.
//  Copyright © 2016 somedev. All rights reserved.
//

import Foundation

public struct DBShot {
    public let id: String
    public let userID: String
    public let teamID: String
    public let title: String
    public let description: String
    public let width: Float
    public let height: Float
    public let hidpi: URL?
    public let normal: URL?
    public let teaser: URL?
    public let viewsCount: UInt
    public let likesCount: UInt
    public let commentsCount: UInt
    public let attachmentsCount: UInt
    public let reboundsCount: UInt
    public let bucketsCount: UInt
    public let created: Date
    public let updated: Date
    public let isAnimated: Bool
    public let tags: [String]
}

extension DBShot {

    public init?(dictionary: [String: Any] = [:]) {
        guard let id: String = dictionary.JSONValueForKey("id") else {
            return nil
        }

        self.id = id
        userID = dictionary.JSONValueForKey("user.id") ?? ""
        teamID = dictionary.JSONValueForKey("team.id") ?? ""
        title = dictionary.JSONValueForKey("title") ?? ""
        description = dictionary.JSONValueForKey("description") ?? ""
        width = dictionary.JSONValueForKey("width") ?? 0
        height = dictionary.JSONValueForKey("height") ?? 0
        hidpi = dictionary.JSONValueForKey("images.hidpi")
        normal = dictionary.JSONValueForKey("images.normal")
        teaser = dictionary.JSONValueForKey("images.teaser")
        viewsCount = dictionary.JSONValueForKey("views_count") ?? 0
        likesCount = dictionary.JSONValueForKey("likes_count") ?? 0
        commentsCount = dictionary.JSONValueForKey("comments_count") ?? 0
        attachmentsCount = dictionary.JSONValueForKey("attachments_count") ?? 0
        reboundsCount = dictionary.JSONValueForKey("rebounds_count") ?? 0
        bucketsCount = dictionary.JSONValueForKey("buckets_count") ?? 0
        created = dictionary.JSONValueForKey("created_at") ?? Date()
        updated = dictionary.JSONValueForKey("updated_at") ?? Date()
        isAnimated = dictionary.JSONValueForKey("animated") ?? false
        tags = dictionary.JSONValueForKey("tags") ?? []
    }
}

extension DBShot {

    static func currentUserShots(page p: UInt = 1, perPage: UInt = 100) -> Request<[DBShot]> {
        return Request(path: "user/shots",
            headers: Request<DBShot>.defaultHeaders,
            params: ["page": "\(p)", "per_page": "\(perPage)"],
            parser: { data in
                guard let arr = data as? [[String: Any]] else { return nil }
                return arr.flatMap({ DBShot(dictionary: $0) })
        })
    }
<commit_msg>DBShot model updated<commit_after>//
//  DBShot.swift
//  DribbbleAPI
//
//  Created by <NAME> on 9/5/16.
//  Copyright © 2016 somedev. All rights reserved.
//

import Foundation

public struct DBShot {
    public let id: String
    public let title: String
    public let description: String
    public let width: Float
    public let height: Float
    public let hidpi: URL?
    public let normal: URL?
    public let teaser: URL?
    public let viewsCount: UInt
    public let likesCount: UInt
    public let commentsCount: UInt
    public let attachmentsCount: UInt
    public let reboundsCount: UInt
    public let bucketsCount: UInt
    public let created: Date
    public let updated: Date
    public let htmlURL: URL?
    public let isAnimated: Bool
    public let tags: [String]
    public let user: DBUser?
    public let team: DBTeam?
}

extension DBShot {

    public init?(dictionary: [String: Any] = [:]) {
        guard let id: String = dictionary.JSONValueForKey("id") else {
            return nil
        }

        self.id = id
        title = dictionary.JSONValueForKey("title") ?? ""
        description = dictionary.JSONValueForKey("description") ?? ""
        width = dictionary.JSONValueForKey("width") ?? 0
        height = dictionary.JSONValueForKey("height") ?? 0
        hidpi = dictionary.JSONValueForKey("images.hidpi")
        normal = dictionary.JSONValueForKey("images.normal")
        teaser = dictionary.JSONValueForKey("images.teaser")
        viewsCount = dictionary.JSONValueForKey("views_count") ?? 0
        likesCount = dictionary.JSONValueForKey("likes_count") ?? 0
        commentsCount = dictionary.JSONValueForKey("comments_count") ?? 0
        attachmentsCount = dictionary.JSONValueForKey("attachments_count") ?? 0
        reboundsCount = dictionary.JSONValueForKey("rebounds_count") ?? 0
        bucketsCount = dictionary.JSONValueForKey("buckets_count") ?? 0
        created = dictionary.JSONValueForKey("created_at") ?? Date()
        updated = dictionary.JSONValueForKey("updated_at") ?? Date()
        isAnimated = dictionary.JSONValueForKey("animated") ?? false
        tags = dictionary.JSONValueForKey("tags") ?? []
        user = dictionary.JSONValueForKey("user")
        team = dictionary.JSONValueForKey("team")
        htmlURL = dictionary.JSONValueForKey("html_url")
    }
}

extension DBShot {

    static func currentUserShots(page p: UInt = 1, perPage: UInt = 100) -> Request<[DBShot]> {
        return Request(path: "user/shots",
            headers: Request<DBShot>.defaultHeaders,
            params: ["page": "\(p)", "per_page": "\(perPage)"],
            parser: { data in
                guard let arr = data as? [[String: Any]] else { return nil }
                return arr.flatMap({ DBShot(dictionary: $0) })
        })
    }

{'fraction_non_alphanumeric': 0.11358292638813529, 'fraction_numerical': 0.007596310363537711, 'mean_word_length': 2.8752627890679747, 'pattern_counts': {'":': 4, '<': 9, '<?xml version=': 0, '>': 11, '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': '2390559', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1559, 'n_words': 416}