# -*- coding: UTF-8 -*-
from .__common__ import hashtype, API


__all__ = ["MalwareBazaar"]


class MalwareBazaar(API):
    doc = "https://bazaar.abuse.ch/api"
    url = "https://mb-api.abuse.ch/api/v1"
    _api_key_header = "Auth-Key"
    _post_condition = lambda s: s.json.get('query_status') != "file_not_found"

    @hashtype("sha256")
    def get_file_by_hash(self, hash):
        # daily limit: 2000/IP/day
        self._post("", data={'query': "get_file", 'sha256_hash': hash})._unzip(b"infected")._save()

