<commit_before>import base64
import hashlib
import json
import time

import jwt
import requests
from requests.auth import AuthBase


class JWTAuth(AuthBase):
    """Attaches JSON Web Token to the given Request object."""
    def __init__(self, token):
        # setup any auth-related data here
        self.token = token

    def __call__(self, r):
        # modify and return the request
        r.headers['Authorization'] = "Bearer {}".format(self.token)
        return r

class Client(object):

    def __init__(self, domain, client_id, client_secret):
        self.client_id = client_id
        self.client_secret = client_secret
        self.domain = domain
        self.base_url = "https://{}".format(self.domain)
        self.api_url = "{}/api".format(self.base_url)

    def auth(self, scopes, lifetime=36000):
        t = int(time.time())
        payload = {
            "iat": t,
            "scopes": scopes
        }
        jti = hashlib.md5(json.dumps(payload)).hexdigest()
        payload["jti"] = jti
        payload["exp"] = t + lifetime
        payload["aud"] = self.client_id

        token = jwt.encode(payload, self.client_secret, algorithm='HS256')

        return JWTAuth(token)

    def get_rule(self, rule_name):
        pass

    def get_rules(self):
        print "{}/v2/rules".format(self.api_url)
        response = requests.get("{}/v2/rules".format(self.api_url), auth=self.auth(["rules:read"]))
        return response.json()

    def update_rule(self, rule):
        pass

    def delete_rule(self, rule_name):
        pass

    def create_rule(self, rule):
        pass

    def get_connections(self):
        pass

    def get_social_connections(self):
        pass

    def get_enterprise_connections(self):
        pass

    def get_social_users(self, options):
        pass

    def get_enterprise_users(self, options):
        pass

    def get_user(self, user_id):
        pass

    def get_user_by_search(self, search_criteria):<commit_msg>Change how the scopes is getting passed<commit_after>import base64
import hashlib
import json
import time

import jwt
import requests
from requests.auth import AuthBase


class JWTAuth(AuthBase):
    """Attaches JSON Web Token to the given Request object."""
    def __init__(self, token):
        # setup any auth-related data here
        self.token = token

    def __call__(self, r):
        # modify and return the request
        r.headers['Authorization'] = "Bearer {}".format(self.token)
        return r

class Client(object):

    def __init__(self, domain, client_id, client_secret):
        self.client_id = client_id
        self.client_secret = client_secret
        self.domain = domain
        self.base_url = "https://{}".format(self.domain)
        self.api_url = "{}/api".format(self.base_url)

    def auth(self, scopes, lifetime=36000):
        t = int(time.time())
        payload = {
            "iat": t,
            "scopes": scopes
        }
        jti = hashlib.md5(json.dumps(payload)).hexdigest()
        payload["jti"] = jti
        payload["aud"] = self.client_id

        token = jwt.encode(payload, self.client_secret, algorithm='HS256')

        print payload
        print token

        return JWTAuth(token)

    def get_rule(self, rule_name):
        pass

    def get_rules(self):
        response = requests.get("{}/v2/rules".format(self.api_url), auth=self.auth({"rules":{"actions":["read"]}}))
        return response.json()

    def update_rule(self, rule):
        pass

    def delete_rule(self, rule_name):
        pass

    def create_rule(self, rule):
        pass

    def get_connections(self):
        pass

    def get_social_connections(self):
        pass

    def get_enterprise_connections(self):
        pass

    def get_social_users(self, options):
        pass

    def get_enterprise_users(self, options):
        pass

    def get_user(self, user_id):
        pass

    def get_user_by_search(self, search_criteria):
{'fraction_non_alphanumeric': 0.11035353535353536, 'fraction_numerical': 0.006313131313131313, 'mean_word_length': 2.4898678414096915, 'pattern_counts': {'":': 6, '<': 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': '4068677', 'n_tokens_mistral': 1240, 'n_tokens_neox': 1180, 'n_words': 288}