<commit_before>import requests


class MissingCompanyError(Exception):
    pass


class MissingNameError(Exception):
    pass


class PyHunter:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_endpoint = 'https://api.hunter.io/v2/{}'

    def _query_hunter(self, endpoint, payload):
        res = requests.get(endpoint, params=payload)
        res.raise_for_status()

        data = res.json()['data']

        return data

    def domain_search(self, domain=None, company=None, limit=None, offset=None,
                      emails_type=None):
        if not domain and not company:
            raise MissingCompanyError(
                'You must supply at least a domain name or a company name'
            )

        if domain:
            payload = {'domain': domain, 'api_key': self.api_key}
        elif company:
            payload = {'company': company, 'api_key': self.api_key}

        if limit:
            payload['limit'] = limit

        if offset:
            payload['offset'] = offset

        if emails_type:
            payload['type'] = emails_type

        endpoint = self.base_endpoint.format('domain-search')

        res = self._query_hunter(endpoint, payload)
        emails = res['emails']
        pattern = res['pattern']

        return emails, pattern

    def email_finder(self, domain=None, company=None, first_name=None,
                     last_name=None, full_name=None):
        payload = {'api_key': self.api_key}

        if not domain and not company:
            raise MissingCompanyError(
                'You must supply at least a domain name or a company name'
            )

        if domain:
            payload['domain'] = domain
        elif company:
            payload['company'] = company

        if not(first_name and last_name) and not full_name:
            raise MissingNameError(
                'You must supply a first name AND a last name OR a full name'
            )

        if first_name and last_name:
            payload['first_name'] = first_name
            payload['last_name'] = last_name
        elif full_name:
            payload['full_name'] = full_name

        endpoint = self.base_endpoint.format('email-finder')

        res = self._query_hunter(endpoint, payload)
        email = res['email']
        score = res['score']

        return email, score

    def email_verifier(self, email):
        payload = {'email': email, 'api_key': self.api_key}

        endpoint = self.base_endpoint.format('email-verifier')

        res = self._query_hunter(endpoint, payload)
        result = res['result']
        score = res['score']
        regexp = res['regexp']
        gibberish = res['gibberish']
        disposable = res['disposable']
        webmail = res['webmail']
        mx_records = res['mx_records']
        smtp_server = res['smtp_server']
        smtp_check = res['smtp_check']
        accept_all = res['accept_all']
        sources = res['sources']

        return (result, score, regexp, gibberish, disposable, webmail,
                mx_records, smtp_server, smtp_check, accept_all, sources)

    def email_count(self, domain):
        payload = {'domain': domain}

        endpoint = self.base_endpoint.format('email-count')

        res = self._query_hunter(endpoint, payload)
        total = res['total']
        personal_emails = res['personal_emails']
        generic_emails = res['generic_emails']

        return total, personal_emails, generic_emails

    def account_information(self):
        payload = {'api_key': self.api_key}

        endpoint = self.base_endpoint.format('account')

        res = self._query_hunter(endpoint, payload)
        first_name = res['first_name']
        last_name = res['last_name']
        email = res['email']
        plan_name = res['plan_name']
        plan_level = res['plan_level']
        reset_date = res['reset_date']
        team_id = res['team_id']
        calls_used = res['calls']['used']
        calls_available = res['calls']['available']
        calls_left = calls_available - calls_used

        return (first_name, last_name, email, plan_name, plan_level,
                reset_date, team_id, calls_used, calls_available, calls_left)<commit_msg>Use raw responses, add leads get an post methods and change query accordingly<commit_after>import requests


class MissingCompanyError(Exception):
    pass


class MissingNameError(Exception):
    pass


class PyHunter:
    def __init__(self, api_key):
        self.api_key = api_key
        self.base_endpoint = 'https://api.hunter.io/v2/{}'

    def _query_hunter(self, endpoint, params, request_type='get',
                      payload=None):
        if not payload:
            res = getattr(requests, request_type)(endpoint, params=params)
        else:
            res = getattr(requests, request_type)(endpoint, params=params,
                                                  json=payload)
        res.raise_for_status()

        data = res.json()['data']

        return data

    def domain_search(self, domain=None, company=None, limit=None, offset=None,
                      emails_type=None):
        if not domain and not company:
            raise MissingCompanyError(
                'You must supply at least a domain name or a company name'
            )

        if domain:
            params = {'domain': domain, 'api_key': self.api_key}
        elif company:
            params = {'company': company, 'api_key': self.api_key}

        if limit:
            params['limit'] = limit

        if offset:
            params['offset'] = offset

        if emails_type:
            params['type'] = emails_type

        endpoint = self.base_endpoint.format('domain-search')

        return self._query_hunter(endpoint, params)

    def email_finder(self, domain=None, company=None, first_name=None,
                     last_name=None, full_name=None, raw=False):
        params = {'api_key': self.api_key}

        if not domain and not company:
            raise MissingCompanyError(
                'You must supply at least a domain name or a company name'
            )

        if domain:
            params['domain'] = domain
        elif company:
            params['company'] = company

        if not(first_name and last_name) and not full_name:
            raise MissingNameError(
                'You must supply a first name AND a last name OR a full name'
            )

        if first_name and last_name:
            params['first_name'] = first_name
            params['last_name'] = last_name
        elif full_name:
            params['full_name'] = full_name

        endpoint = self.base_endpoint.format('email-finder')

        res = self._query_hunter(endpoint, params)
        if raw:
            return res

        email = res['email']
        score = res['score']

        return email, score

    def email_verifier(self, email):
        params = {'email': email, 'api_key': self.api_key}

        endpoint = self.base_endpoint.format('email-verifier')

        return self._query_hunter(endpoint, params)

    def email_count(self, domain):
        params = {'domain': domain}

        endpoint = self.base_endpoint.format('email-count')

        return self._query_hunter(endpoint, params)

    def account_information(self):
        params = {'api_key': self.api_key}

        endpoint = self.base_endpoint.format('account')

        res = self._query_hunter(endpoint, params)
        res['calls']['left'] = res['calls']['available'] - res['calls']['used']

        return res

    def get_leads(self):
        params = {'api_key': self.api_key}

        endpoint = self.base_endpoint.format('leads')

        return self._query_hunter(endpoint, params)

    def get_lead(self, id_):
        params = {'api_key': self.api_key}

        endpoint = self.base_endpoint.format('leads/' + str(id_))

        return self._query_hunter(endpoint, params)

    def create_lead(self, first_name, last_name, email=None, position=None,
                    company=None, company_industry=None, company_size=None,
                    confidence_score=None, website=None, country_code=None,
                    postal_code=None, source=None, linkedin_url=None,
                    phone_number=None, twitter=None, leads_list_id=None):
        args = locals()
        payload = dict((key, value) for key, value in args.items() if value
                       is not None)
        payload.pop('self')

        params = {'api_key': self.api_key}

        endpoint = self.base_endpoint.format('lead')

        return self._query_hunter(endpoint, params, 'post', payload)
{'fraction_non_alphanumeric': 0.1033603707995365, 'fraction_numerical': 0.0002317497103128621, 'mean_word_length': 2.2145251396648047, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5279506', 'n_tokens_mistral': 2453, 'n_tokens_neox': 2349, 'n_words': 594}