Coder Social home page Coder Social logo

print-queue-api-client's Introduction

iForge Print Queue API Client Versionmade-with-python

About

This is the repository for the iForge Print Queue API Client. This client is used to interact with the iForge Print Queue API. The API is used to manage print jobs, printers and users in the iForge Print Queue.

Installation

To install the client, run the following command:

(.venv): pip install print_queue_api_client

Basic Usage

To use the client, import the client and create an instance of the client. The client requires a valid API key to be passed in. The API key can be obtained from the iForge Print Queue API.

It is important to note, we employ a standardised Requests response in the following form:

"""
iForge Interpreted Response Standards:
{
    "error": True/False,
    "data": {{ Success-specific data (eg application) / None or optional error payload }},
    "message": {{ None or optional success message / Error-specific data (eg debug) }}
}

:return (bool error, str data, str message):
"""

This means that to access/use the data from a response, the 'data' key must be used. The 'data' for all get() functions is internally converted to a dataframe, resulting in the following recommended usage:

import print_queue_api_client as api

# create database object
db = api.database_api_factory(
    api_key="YOUR_API_KEY",
    server_ip="YOUR_SERVER_IP",
    server_port="YOUR_SERVER_PORT",
)

users = db.users.get()['data']
"""
users = {
            'error': {bool} False
            'data': {DataFrame: (1,15)}
                        completed_count date_added                          ... user_level  user_score
                    0   0               2022-12-15T16:03:34.783852+00:00    ... insane      658
                        [1 rows x 15 columns]
            'message': None
        }
"""

resp = db.users.create(name='Dom RG',
                       email='[email protected]',
                       short_name='Dom RG',
                       user_score=999,
                       is_rep=True,
                       score_editable=True)
"""
resp = {
            'error': False
            'data': 'success'
            'message': None
        }
"""

Documentation

Example usage

import logging
import pandas as pd
import os
from dotenv import load_dotenv, find_dotenv
import print_queue_api_client as api

logging.basicConfig()
logging.getLogger().setLevel(logging.ERROR)

pd.set_option('display.max_columns', 4)

load_dotenv(find_dotenv())
SERVER_IP = os.getenv("SERVER_IP")
SERVER_PORT = os.getenv("SERVER_PORT")
API_KEY = os.getenv("API_KEY")

if __name__ == '__main__':
    # create database object
    db = api.database_api_factory(
        api_key=API_KEY,
        server_ip=SERVER_IP,
        server_port=SERVER_PORT,
    )

    users = db.users.get()

    # === USERS ===
    print("Original:")
    print(db.users.get()['data'][['name', 'email']])

    print("\nNew user:")
    resp = db.users.create(name='Dom RG',
                           email='[email protected]',
                           short_name='Dom RG',
                           user_score=999,
                           is_rep=True,
                           score_editable=True)
    print(db.users.get()['data'][['name', 'email', 'is_rep']])

    print("\nUpdate 'is_rep':")
    resp = db.users.update(key='[email protected]', is_rep=False)
    print(db.users.get()['data'][['name', 'email', 'is_rep', 'user_score']])

    print("\nUpdate with invalid key:")
    resp = db.users.update(key='[email protected]', universial_credit_score=0)
    print(db.users.get()['data'][['name', 'email', 'score_editable', 'user_score']])

    print("\nUpdate 'user_score':")
    resp = db.users.update(key='[email protected]', user_score=995)
    print(db.users.get()['data'][['name', 'email', 'score_editable', 'user_score']])

    print("\nDelete user:")
    resp = db.users.delete(key='[email protected]')
    print(db.users.get()['data'][['name', 'email', 'slice_failed_count']])

    print("\nUpdate 'slice_failed_count' by id")
    db.users.update(key=4, slice_failed_count=10)
    print(db.users.get()['data'][['name', 'email', 'slice_failed_count']])

Dependencies

The client has the following dependencies:

  • Requests (>=2.28.1)
  • Pandas (>=1.5.2)

print-queue-api-client's People

Contributors

domrg avatar sampiiiii avatar

Watchers

Harry Merckel avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.