<commit_before># -*- coding: utf-8 -*-
"""
Created on Sun Mar 06 00:27:21 2016
@author: maheshwa
"""

from __future__ import print_function
import requests
import time
import binascii
import hashlib
import json


# Authentication
class AdobeAnalytics:

    def __init__(self, user_name, shared_secret, endpoint='', debug=False):
        """
        Entry point for making authenticated API calls to the Adobe Report API's
        """
        self.__user_name = user_name
        self.__shared_secret = shared_secret
        self.__company = self.__user_name.split(":")[1]
        self.__debug = debug

        # If user doesn't specify their own endpoint, call API to get proper endpoint
        # Most users should never do this, but some have requested capability in RSiteCatalyst
        self.__api_url = 'https://api.omniture.com/admin/1.4/rest/'
        if endpoint != '':
            self.__api_url = endpoint
        else:
            self.__api_url = self.GetEndpoint(company=self.__company)

    def __buildheader(self):
        """
        Returns required header for authenticating API calls. This is an internal method to be used
        by other public method calls.
        """
        nonce = str(time.time())
        base64nonce = binascii.b2a_base64(binascii.a2b_qp(nonce))
        created_date = time.strftime("%Y-%m-%dT%H:%M:%SZ",  time.gmtime())
        sha_object = hashlib.sha1((nonce + created_date + '%s' % (self.__shared_secret)).encode('ascii'))
        password_64 = binascii.b2a_base64(sha_object.digest())
        X_str = 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"' % (
            '%s:%s' % (self.__user_name, self.__company), password_64.strip(), base64nonce.strip(), created_date)
        return {'X-WSSE': X_str}

    def __callapi(self, endpoint, verb="POST", **kwargs):
        """
        Calls the Adobe Analytics API at a given endpoint and variable arguments
        """

        # Automatically convert an rsid_list string type to list as required by API
        if "rsid_list" in kwargs and isinstance(kwargs["rsid_list"], str):
            kwargs["rsid_list"] = [kwargs["rsid_list"]]

        header = self.__buildheader()
        if verb == "GET":<commit_msg>bytes byte bytes<commit_after># -*- coding: utf-8 -*-
"""
Created on Sun Mar 06 00:27:21 2016
@author: maheshwa
"""

from __future__ import print_function
import requests
import time
import binascii
import hashlib
import json


# Authentication
class AdobeAnalytics:

    def __init__(self, user_name, shared_secret, endpoint='', debug=False):
        """
        Entry point for making authenticated API calls to the Adobe Report API's
        """
        self.__user_name = user_name
        self.__shared_secret = shared_secret
        self.__company = self.__user_name.split(":")[1]
        self.__debug = debug

        # If user doesn't specify their own endpoint, call API to get proper endpoint
        # Most users should never do this, but some have requested capability in RSiteCatalyst
        self.__api_url = 'https://api.omniture.com/admin/1.4/rest/'
        if endpoint != '':
            self.__api_url = endpoint
        else:
            self.__api_url = self.GetEndpoint(company=self.__company)

    def __buildheader(self):
        """
        Returns required header for authenticating API calls. This is an internal method to be used
        by other public method calls.
        """
        nonce = str(time.time())
        base64nonce = binascii.b2a_base64(binascii.a2b_qp(nonce))
        created_date = time.strftime("%Y-%m-%dT%H:%M:%SZ",  time.gmtime())
        sha_object = hashlib.sha1((nonce + created_date + '%s' % (self.__shared_secret)))
        password_64 = binascii.b2a_base64(bytes(sha_object.digest()))
        X_str = 'UsernameToken Username="%s", PasswordDigest="%s", Nonce="%s", Created="%s"' % (
            '%s:%s' % (self.__user_name, self.__company), password_64.strip(), base64nonce.strip(), created_date)
        return {'X-WSSE': X_str}

    def __callapi(self, endpoint, verb="POST", **kwargs):
        """
        Calls the Adobe Analytics API at a given endpoint and variable arguments
        """

        # Automatically convert an rsid_list string type to list as required by API
        if "rsid_list" in kwargs and isinstance(kwargs["rsid_list"], str):
            kwargs["rsid_list"] = [kwargs["rsid_list"]]

        header = self.__buildheader()
        if verb == "GET":
{'fraction_non_alphanumeric': 0.11715949820788531, 'fraction_numerical': 0.014336917562724014, 'mean_word_length': 2.869150779896014, 'pattern_counts': {'":': 4, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6170884', 'n_tokens_mistral': 1372, 'n_tokens_neox': 1292, 'n_words': 369}