#!/usr/bin/python

import os
import sys
import traceback

sys.path.insert(0, os.path.join(os.path.dirname(__file__),
    '../lib'))

from smtpcom.sendapi.api import API

def main():
    api = API('json')

    result = api.create_campaign(campaign_name='mycampaign')
    campaign_id = result.get('Id')
    print result
    print api.update_campaign(campaign_name='mycampaign2new', campaign_id=campaign_id)
    print api.create_campaign(campaign_name='mycampaign2', campaign_id='mycampaignid')
    #expected {u'Message': u'mycampaign was successfully added.', u'Id': u'5565c80d7059db0428e0edd0', u'Success': True}
    print api.delete_campaign(campaign_id='mycampaignid')
    print api.get_campaigns(sender='sender', count=1, page=1)

    result = api.add_template(html='test', subject='subject', from_address='test@smtp.com', from_name='Name', name='template_name')
    print result
    template_id = result.get('Id')
    print api.update_template(html='testnew', subject='subjectnew', from_address='testnew@smtp.com', from_name='Namenew', name='template_namenew', template_id=template_id)
    print api.get_template(template_id=template_id)
    print api.get_templates(count=1, page=1)
    print api.delete_template(template_id=template_id)

    print api.get_clicks(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.get_clicks_by_url(url='http://test.com', date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.get_failed_sends(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.get_opens(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.get_realtime_reporting()

    print api.update_realtime_reporting(queue_name='test', server_region='east', public_key='42',
        private_key='56', notify_opens=False, notify_clicks=True, notify_delivery_info=True)

    print api.get_senders()
    print api.get_sends(count=1, page=1)

    print api.export_clicks(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.export_clicks(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1, sender='sablin@smtp.com')
    print api.export_clicks(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1, campaign_id=campaign_id)
    #[{'': 1}]
    print api.export_clicks_by_url(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1, campaign_id=campaign_id, url='htp://test.com')

    print api.export_opens(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1)
    print api.export_opens(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1, sender='sablin@smtp.com')
    print api.export_opens(date_from='01/01/2015', date_to='01/12/2015', count=5, page=1, campaign_id=campaign_id)

    print api.export_summary_stats(date_from='01/01/2015', date_to='01/12/2015', sender='sablin@smtp.com')
    print api.export_summary_stats(date_from='01/01/2015', date_to='01/12/2015', campaign_id=campaign_id)
    print api.get_summary_stats(date_from='01/01/2015', date_to='01/12/2015', sender='sablin@smtp.com')

    '''
    data = {
        'subject': 'subject',
        'body_html': 'body_html',
        'body_text': 'body_text',
        'template_id': 'template_id',
        'from': 'from',
        'from_name': 'from_name',
        'reply_to': 'reply_to',
        'reply_to_name': 'reply_to_name',
        'return_path': 'return_path',
        'recipients': 'yana@smtp.com',
        'recipients_url': 'smtp.com',
        'default_recipient_data': 'default',
        'attachments': 'attachments',
        'campaign_id': 'campaign_id',
        'utm_codes': 'utm_codes',
        'email_headers': 'email_headers'
    }
    '''
    data = {
        'subject': 'subject',
        'body_html': 'body_html',
        'body_text': 'body_text',
        'from': 'yana@smtp.com',
        'recipients': [{"ToAddress":"yana@smtp.com","ToName":"Yana","RecipientData":{"test":"test"}}],
    }
    print api.send(data)

if __name__ == '__main__':
    main()
