<commit_before>'use strict';

var validateAddress = {
    title: 'Validate Address',
    metadata: [
        {header: 'Description', val: 'Validate an address'},
        {header: 'Endpoint', val: 'https://developer.avalara.com/1.0/address/validate'},
        {header: 'HTTP Method', val: 'GET'}
    ],
    querystring: [
        {name: 'Line1', default: '1100 2nd Ave', required: true},
        {name: 'Line2', default: 'Suite 300', required: false},
        {name: 'Line3', default: '', required: false},
        {name: 'City', default: 'Seattle', required: true},
        {name: 'Region', default: 'WA', required: false},
        {name: 'Country', default: 'United States', required: true},
        {name: 'PostalCode', default: '', required: true}
    ],
    postBody: null
};

var getTax = {
    title: 'Get Tax',
    metadata: [
        {header: 'Description', val: 'Calculates taxes on a document such as a sales order, sales invoice or purchase order'},
        {header: 'Endpoint', val: 'https://developer.avalara.com/1.0/tax/get'},
        {header: 'HTTP Method', val: 'POST'}
    ],
    querystring: [],
    postBody: {
        "context": {
            "resource-path": "/tax/get",
            "http-method": "POST"
        },
        "params": {
            "header": {
                "api-key": ""
            }
        },
        "body-json": {
            "DocDate": "2016-02-11",
            "CustomerCode": "0000",
            "CompanyCode": "APITrialCompany",
            "Addresses": [
                {
                    "AddressCode": "1",
                    "Line1": "435 Ericksen Avenue Northeast",
                    "Line2": "#250",
                    "PostalCode": "98110"
                }
            ],
            "Lines": [
                {
                    "LineNo": "1",
                    "DestinationCode": "1",
                    "OriginCode": "1",
                    "Qty": 1,
                    "Amount": 10
                }
            ]
        }
    }
};

$(function() {
    $('.validateAddress').on('submit', function(e) {
        e.preventDefault();
        var isValid = true;
        $('input[data-required]').each(function() {
            $(this).parent().removeClass('error');
            if (!$(this).val()) {
                $(this).parent().addClass('error');
                isValid = false;
            }
        });

        console.log('isValid', isValid);
    });

    $('.showGetTaxSamplePost').on('click', function(e) {
        e.preventDefault();
        $('.getTaxPostBody').val(JSON.stringify(getTax.postBody['body-json'], null, 2));
    });

<commit_msg>ajax address validation....wip<commit_after>'use strict';

var validateAddress = {
    title: 'Validate Address',
    metadata: [
        {header: 'Description', val: 'Validate an address'},
        {header: 'Endpoint', val: 'https://developer.avalara.com/1.0/address/validate'},
        {header: 'HTTP Method', val: 'GET'}
    ],
    querystring: [
        {name: 'Line1', default: '1100 2nd Ave', required: true},
        {name: 'Line2', default: 'Suite 300', required: false},
        {name: 'Line3', default: '', required: false},
        {name: 'City', default: 'Seattle', required: true},
        {name: 'Region', default: 'WA', required: false},
        {name: 'Country', default: 'United States', required: true},
        {name: 'PostalCode', default: '', required: true}
    ],
    postBody: null
};

var getTax = {
    title: 'Get Tax',
    metadata: [
        {header: 'Description', val: 'Calculates taxes on a document such as a sales order, sales invoice or purchase order'},
        {header: 'Endpoint', val: 'https://developer.avalara.com/1.0/tax/get'},
        {header: 'HTTP Method', val: 'POST'}
    ],
    querystring: [],
    postBody: {
        "context": {
            "resource-path": "/tax/get",
            "http-method": "POST"
        },
        "params": {
            "header": {
                "api-key": ""
            }
        },
        "body-json": {
            "DocDate": "2016-02-11",
            "CustomerCode": "0000",
            "CompanyCode": "APITrialCompany",
            "Addresses": [
                {
                    "AddressCode": "1",
                    "Line1": "435 Ericksen Avenue Northeast",
                    "Line2": "#250",
                    "PostalCode": "98110"
                }
            ],
            "Lines": [
                {
                    "LineNo": "1",
                    "DestinationCode": "1",
                    "OriginCode": "1",
                    "Qty": 1,
                    "Amount": 10
                }
            ]
        }
    }
};

$(function() {
    $('.validateAddress').on('submit', function(e) {
        e.preventDefault();
        var isValid = true;
        $('input[data-required]').each(function() {
            $(this).parent().removeClass('error');
            if (!$(this).val()) {
                $(this).parent().addClass('error');
                isValid = false;
            }
        });

        console.log('isValid', isValid);
        if (isValid) {
            var addressData = {};
            $('.validateAddress input').each(function() {
                addressData[$(this).attr('name')] = $(this).val()
            });
            console.log('addressData', addressData);
            
            $.ajax({
                type: 'GET',
                url: 'https://swn36zl7ba.execute-api.us-west-2.amazonaws.com/prod/address/validate',
                headers: {
                    'api-key': 'b24757b69083fa34d27a7d814ea3a59c'
                },
                data: addressData,
                dataType:'jsonp',
                success:function(data) {
                    console.log('success', data)
                },
                error: function(err) {
                    console.log('ajax error', err)
                }
            });
        }
    });

    $('.showGetTaxSamplePost').on('click', function(e) {
        e.preventDefault();
        $('.getTaxPostBody').val(JSON.stringify(getTax.postBody['body-json'], null, 2));
    });


{'fraction_non_alphanumeric': 0.169638475380337, 'fraction_numerical': 0.019793881891051857, 'mean_word_length': 1.5581589958158997, 'pattern_counts': {'":': 42, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 5, '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': '3924508', 'n_tokens_mistral': 1812, 'n_tokens_neox': 1698, 'n_words': 361}