PHP Classes

File: python/

Recommend this page to a friend!
  Classes of andy honeycutt  >  Crypt Put Client  >  python/  >  Download  
File: python/
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: Crypt Put Client
Encrypt or decrypt data using Crypt client API
Author: By
Last change:
Date: 4 years ago
Size: 2,146 bytes


Class file image Download
import requests
import json

class CryptPutClient:

    _url = '';
    _token = '';

    def __init__(self, url, username, password):
        self._url = url
        self._token = self.pullToken(username=username, password=password)

    def getUrl(self, add):
        return "{}{}".format(self._url, add)

    def getToken(self):
        return self._token

    def pullToken(self, username, password):
        url = self.getUrl('api-auth/');

        data = {
          'username': username,
          'password': password

        headers = {
            'Content-type': 'application/json'

            req =, headers=headers, json=data)
            response_json = json.loads(req.text)
            token = response_json['token']
        except Exception as e:
            print("Could not assign token from {}".format(url))
            token = None
        return token

    def rawRequest(self, data, headers, url,
        response = method(url, headers=headers, json=data)
        return json.loads(response.text)

    def apiRequest(self, data, url,
        headers = {
            "Content-type": "application/json",
            "Authorization": "JWT {}".format(self.getToken())
        return self.rawRequest(data=data, headers=headers, url=url, method=method)

    def get(self, uid, decrypt=False):
        data = {'i': uid}
        if decrypt:
            data['d'] = '1'
        return self.apiRequest(data=data, url=self.getUrl('get/'))

    def put(self, data):
        data = {'d': data}
        url = self.getUrl('put/')
        response = self.apiRequest(data=data, url=self.getUrl('put/'))
        uid = response['id']
        return uid

# Test run
if __name__ == '__main__':
    username = ''
    password = ''
    c = CryptPutClient(
    uid = c.put(data="here is a secret message")
    data = c.get(uid=uid)
    data = c.get(uid=uid, decrypt=True)
For more information send a message to info at phpclasses dot org.