Skip to main content

pegass_auth is a tiny client tool to help you make some HTTP request on Pegass

Project description

pegass_auth

Made Pegass API Request easy !

Tests

French Red Cross is currently using a tool named Pegass to visualize, enroll to activities, monitor them and more... This application is carefully thought out, and the different views give you plenty options to display your data. However, my motivation was to extract Pegass data to analyze it and create some custom views. The application was not designed to let users get data out of the box (closed API, no CSV extract, ...). That's why I made this little module to help whoever wants to extract their data in a simple way through the Pegass API. :red_car: :red_car: :fire_engine: :fire_engine: :rotating_light: :rotating_light:

Features

  • Get authentication cookies to open Pegass API gate with your application credential
  • Create an abstraction for requesting the API

Installing

# Connect to your virtualenv
$  workon projectenv

# Use pip to install the package
$  pip install pegass_auth

Verify now if the package as been successfully installed

$  python
>> import pegass_auth # Should not raise exception

Quick Start

Get authentication cookies to make requests out of the box

import os
import requests
import pegass_auth

username = os.environ['username']
password = os.environ['password']

auth_cookies = pegass_auth.login(username, password)

# When using 'requests' package
r = requests.get('{}/crf/rest/gestiondesdroits'.format(pegass_auth.DEFAULT_PEGASS_URL), cookies=auth_cookies)

if r.status_code == 200:
    print(r.json())
else:
    print('Request went wrong ! Status code returned : {}'.format(r.status_code))

Using package abstraction to make request

The package gives you two ways to make a request to Pegass API :

  • Using cookies :
import os
import pegass_auth as pegass

auth_cookies = login(os.environ['username'], os.environ['password'])
rules = pegass.request('crf/rest/gestiondesdroits', cookies=auth_cookies)
print(rules)
  • Using credentials:
import os
import pegass_auth as pegass

username = os.environ['username']
password = os.environ['password']
rules = pegass.request('crf/rest/gestiondesdroits', username=username, password=password)
print(rules)

Note: The last way to make request (the one with username and password) runs each time the login logic. Make cookies methods your first choice if you need to do multiple API requests.

All the previous codes prints the following response:

{
   'utilisateur':{
      'id':'01XXXXXXXX',
      'structure':{
         'id':1XXX,
         'typeStructure':'UL',
         'libelle':'UNITE LOCALE DE XXXXXXX',
         'libelleCourt':'XX',
         'adresse':'XX XXXXXXXXXXXXXXXX XXXXXX XXXX XXXXXXXX',
         'telephone':'X XX XX XX XX',
         'mail':'ul.XXXXXXXXX@croix-rouge.fr',
         'siteWeb':'XXXXXXXXXXXX.croix-rouge.fr/XXXXXXXX/',
         'parent':{
            'id':XX
         },
         'structureMenantActiviteList':[
            {
               'id':1XXX,
               'libelle':'UNITE LOCALE DE XXXXXXX'
            }
         ]
      },
      'nom':'Foo',
      'prenom':'Bar',
      'actif':True,
      'mineur':False
   },
   'structuresAdministrees':[

   ]
}

Pegass API Endpoints

I've started to do a reverse engineering on Pegass app to list the API endpoints I need in order to achieve my personal app.

Error handler

Their is no error handler implemented yet in the package.

Links

License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pegass_auth-1.0.2.tar.gz (4.2 kB view details)

Uploaded Source

File details

Details for the file pegass_auth-1.0.2.tar.gz.

File metadata

  • Download URL: pegass_auth-1.0.2.tar.gz
  • Upload date:
  • Size: 4.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.9

File hashes

Hashes for pegass_auth-1.0.2.tar.gz
Algorithm Hash digest
SHA256 abe16a3888b03c791b08f690aa5bc4bc0adae7432f6de8aef00328bf2951e6ec
MD5 329180664dfa267e1738d963d11a7941
BLAKE2b-256 3cd55e9d780c807f8a70640f4a71539c8ca71e9af4b0f6a961ddbdc1dec15b93

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page