<commit_before># -*- coding: utf-8 -*-
"""Module with connector managing communication with Mprofi API."""

import os
import json

from .packages.requests import Session


class MprofiAPIConnector(object):

    """Connector class that manages communication  with mprofi public API.

    :param api_token: Optional, explicit api token, as string. If api_token
        is not specified `MPROFI_API_TOKEN` env variable will be used.
    :param payload: Optional initial payload (list of dicts).

    """<commit_msg>MD-146 Added example code snippets showing use of the library<commit_after># -*- coding: utf-8 -*-
"""Module with connector managing communication with Mprofi API."""

import os
import json

from .packages.requests import Session


class MprofiAPIConnector(object):

    """Connector class that manages communication  with mprofi public API.

    :param api_token: Optional, explicit api token, as string. If api_token
        is not specified `MPROFI_API_TOKEN` env variable will be used.
    :param payload: Optional initial payload (list of dicts).

    :Example:

    >>> connector = MprofiAPIConnector(api_token="token from mprofi.pl website")
    >>> connector.add_message('111222333', 'Welcome!')
    >>> connector.send()
    ... {u'id': 1}  # This will be a dict with message id

    Sending multiple messages will change `send()` results

    >>> connector = MprofiAPIConnector(api_token="token from mprofi.pl website")
    >>> connector.add_message('111222333', 'Welcome!')
    >>> connector.add_message('111222333', 'Welcome!')
    >>> connector.send()
    ... {u'result': [{u'id': 2}, {u'id': 3}]}  # a dict with results in a list
    >>> # now `response` property has all added messages with ids
    >>> connector.response
    ... [
    ...     {
    ...         u'id': 2,
    ...         'message': 'Hello!',
    ...         'recipient': '123123123'
    ...     },
    ...     {
    ...         u'id': 3,
    ...         'message': 'Hello!',
    ...         'recipient': '123123123'
    ...     }
    ... ]
    >>> # you can also grab current status of messages you've sent
    >>> connector.get_status()
    ... [
    ...     {
    ...         u'id': 2,
    ...         'message': 'Hello!',
    ...         'recipient': '123123123',
    ...         u'reference': u'2015-02-05',  # you can set own reference
    ...                                       # string as `send()` argument
    ...         u'status': u'WAITING_TO_PROCESS',
    ...         u'ts': None
    ...     },
    ...     {
    ...         u'id': 3,
    ...         'message': 'Hello!',
    ...         'recipient': '123123123',
    ...         u'reference': u'2015-02-05',
    ...         u'status': u'WAITING_TO_PROCESS',
    ...         u'ts': None
    ...     }
    ... ]

    """
{'fraction_non_alphanumeric': 0.1541231544832553, 'fraction_numerical': 0.03276917536910335, 'mean_word_length': 2.0460526315789473, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 36, 'https://': 0, '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': '1440141', 'n_tokens_mistral': 898, 'n_tokens_neox': 812, 'n_words': 237}