Skip to content

Commit

Permalink
[review] Review DOC; Bump version
Browse files Browse the repository at this point in the history
  • Loading branch information
mtulio committed May 27, 2017
1 parent 4609c4a commit 8bbd3c0
Show file tree
Hide file tree
Showing 7 changed files with 144 additions and 155 deletions.
63 changes: 63 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Questions

If you are having difficulties using the APIs or have a question about the GLPI-SDK-PYTHON, please ask a question.

# Issues

If you encounter an issue with the Python SDK, you are welcome to submit a [bug report](https://github.com/truly-systems/glpi-sdk-python/issues).
Before that, please search for similar issues. It's possible somebody has encountered this issue already.

## Pull Requests

If you want to contribute to the repository, here's a quick guide:
1. Fork the repository
2. develop and test your code changes with [pytest].
* Respect the original code [style guide][styleguide].
* Only use spaces for indentation.
* Create minimal diffs - disable on save actions like reformat source code or organize imports. If you feel the source code should be reformatted create a separate PR for this change.
* Check for unnecessary whitespace with git diff --check before committing.
3. Make the test pass
4. Commit your changes
5. Push to your fork and submit a pull request to the `dev` branch

## Running the tests

You probably want to set up a [virtualenv].

1. Clone this repository:
```
git clone https://github.com/truly-systems/glpi-sdk-python.git
```
2. Install the sdk as an editable package using the current source:
```
pip install --editable .
```
3. Install the test dependencies with:
```
pip install -r requirements-dev.txt
```
4. Run the test cases with (now we're only testing PEP8):
```
make check-syntax
```
## Aditional tests
* Install tests dependencies
`make dependencies`
* Test PEP8 syntax
`make check-syntax`
* Test installation setup
`make test-setup`
## Additional Resources
+ [General GitHub documentation](https://help.github.com/)
+ [GitHub pull request documentation](https://help.github.com/send-pull-requests/)
[styleguide]: http://google.github.io/styleguide/pyguide.html
[virtualenv]: http://virtualenv.readthedocs.org/en/latest/index.html
224 changes: 73 additions & 151 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,198 +8,120 @@ GLPI SDK written in Python.

## Description

This SDK is written in Python to help developers integrate their apps, APIS
and scripts in GLPI infrastructure. This SDK abstract the [GLPI Rest API](https://github.com/glpi-project/glpi/blob/9.1/bugfixes/apirest.md)
This SDK is written in Python to help developers integrate their apps, APIS and scripts in GLPI infrastructure. This SDK abstract
the [GLPI Rest API](https://github.com/glpi-project/glpi/blob/9.1/bugfixes/apirest.md).

To usage it, you should have username, password and API-Token from your GLPI
server.
To usage it, you should have username, password and API-Token from your GLPI server.

See also:
* [GLPI Rest API](https://github.com/glpi-project/glpi/blob/9.1/bugfixes/apirest.md#list-searchoptions)

## SDK supported items

* Ticket: get, get all, create
* Knowledge Base: get, get all, create

## Install

Just install using pip, from:
Just install from:

* PyPi:

* Repository:
```bash
pip install glpi
```

`pip install -e git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi`
* repository (development):

* requirements.txt
``bash
pip install -e git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi
```

```shell
$ echo '-e git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi`'\
> requirements.txt
* requirements.txt (development)

$ pip install -r requirements.txt
```
```shell
pip install -r requirements-dev.txt
```

## Usage

You should enable the GLPI API and generate an App Token. TO create one follow these steps:
You should enable the GLPI API and generate an App Token.

* TODO
Please, export these environments variables with yours config:

Please, change the vars bellow with yours:
```python
export username = "GLPI_USER"
password = "GLPI_USER"
url = 'http://glpi.example.com/apirest.php'
glpi_app_token = "GLPI_API_TOKEN"
```

```python
username = "GLPI_USER"
password = "GLPI_USER"
url = 'http://glpi.example.com/apirest.php'
glpi_app_token = "GLPI_API_TOKEN"
Then import it in your script and create a `glpi` API connection:

```
```python
import os
from glpi import GLPI
### Tickets
url = os.getenv("GLPI_API_URL") or None
user = os.getenv("GLPI_USERNAME") or None
password = os.getenv("GLPI_PASSWORD") or None
token = os.getenv("GLPI_APP_TOKEN") or None
* Get all Tickets
glpi = GLPI(url, token, (user, password))
```

```python
from glpi import GlpiTicket
### Tickets

glpi_ticket = GlpiTicket(url, glpi_app_token,
username=username,
password=password)
* Get all Tickets

tickets_all = glpi_ticket.get_all()
print "Retrieving all tickets: %s" % json.dumps(tickets_all,
indent=4,
separators=(',', ': '),
sort_keys=True)
```
```python
print "Getting all Tickets: "
print json.dumps(glpi.get_all('ticket'),
indent=4,
separators=(',', ': '),
sort_keys=True)
```

* Create an Ticket

```python
from glpi import GlpiTicket, Ticket

glpi_ticket = GlpiTicket(url, glpi_app_token,
username=username,
password=password)
```python
ticket = Ticket(name='New ticket from SDK',
content='>>>> Content of ticket created by SDK API <<<')
ticket_payload = {
'name': 'New ticket from SDK',
'content': '>>>> Content of ticket created by SDK API <<<'
}
ticket_dict = glpi_ticket.create(ticket_data=ticket)
print "Created the ticket: %s" % ticket_dict
ticket_dict = glpi.create('ticket', ticket_payload)
if isinstance(ticket_dict, dict):
print "The ticket request was sent. See results: "
```
print json.dumps(ticket_dict,
indent=4,
separators=(',', ': '),
sort_keys=True)
```
* Get ticket by ID
```python
from glpi import GlpiTicket, Ticket

glpi_ticket = GlpiTicket(url, glpi_app_token,
username=username,
password=password)

ticket_dict = {}
ticket_dict['id'] = 1
ticket_get = glpi_ticket.get(ticket_dict['id'])
print "Got this ticket: %s" % json.dumps(ticket_get,
indent=4,
separators=(',', ': '),
sort_keys=True)

```
```python
print "Getting Ticket with ID 1: "
print json.dumps(glpi.get('ticket', 1),
indent=4,
separators=(',', ': '),
sort_keys=True)
```
* Profile information
```python
from glpi import GlpiProfile

glpi_pfl = GlpiProfile(url,
glpi_app_token, username=username,
password=password)

print "Getting profile "
print json.dumps(glpi_pfl.get_my_profiles(),
indent=4, separators=(',', ': '))
```

* Reusing session token

```python
token_session = glpi_pfl.get_session_token()
print "Update session for Ticket object: %s" %\
glpi_ticket.update_session_token(token_session)

```
```python
print "Getting 'My' profile: "
print json.dumps(glpi.get('getMyProfiles'),
indent=4,
separators=(',', ': '),
sort_keys=True)
```
* Full example
```python
from glpi import GlpiProfile
from glpi import GlpiTicket, Ticket


username = "GLPI_USER"
password = "GLPI_USER"
url = 'http://glpi.example.com/apirest.php'
glpi_app_token = "GLPI_API_TOKEN"


if __name__ == '__main__':

glpi_pfl = GlpiProfile(url,
glpi_app_token, username=username,
password=password)

print "Getting profile "
print json.dumps(glpi_pfl.get_my_profiles(),
indent=4, separators=(',', ': '))

token_session = glpi_pfl.get_session_token()
print "Current session is: %s" % token_session

glpi_ticket = GlpiTicket(url, glpi_app_token,
username=username,
password=password)

print "Update Ticket object to session: %s" %\
glpi_ticket.update_session_token(token_session)

tickets_all = glpi_ticket.get_all()
print "Retrieving all tickets: %s" % json.dumps(tickets_all,
indent=4,
separators=(',', ': '),
sort_keys=True)

ticket = Ticket(name='New ticket from SDK',
content=' Content of ticket created by SDK API ')
ticket_dict = glpi_ticket.create(ticket_data=ticket)
print "Created the ticket: %s" % ticket_dict

print "Getting ticket recently created with id %d ..." % ticket_dict['id']
ticket_get = glpi_ticket.get(ticket_dict['id'])
print "Got this ticket: %s" % json.dumps(ticket_get,
indent=4,
separators=(',', ': '),
sort_keys=True)

```

* TODO: Update with new generic function. See more in tests script `tests/test_glpi_module.py`
>> TODO: create an full example with various Items available in GLPI Rest API.
## CONTRIBUTING
### TEST the code

* Install tests dependencies

`make dependencies`

* Test PEP syntax

`make check-syntax`

* Test installation setup

`make test-setup`
See [CONTRIBUTING.md](CONTRIBUTING.md)
2 changes: 2 additions & 0 deletions glpi/glpi.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class GlpiInvalidArgument(GlpiException):

class GlpiService(object):
""" Polymorphic class of GLPI REST API Service. """
__version__ = __version__

def __init__(self, url_apirest, token_app, uri,
username=None, password=None, token_auth=None,
Expand Down Expand Up @@ -371,6 +372,7 @@ class GLPI(object):
can reuse API sessions.
To support new items you should create the dict key/value in item_map.
"""
__version__ = __version__

def __init__(self, url, app_token, auth_token,
item_map=None):
Expand Down
2 changes: 1 addition & 1 deletion glpi/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '0.1.1'
__version__ = '0.2.0'
3 changes: 3 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pep8
codecov
python-dotenv
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def readme():
description='GLPI API SDK',
#long_description=readme(),
url='https://github.com/truly-systems/glpi-sdk-python',
download_url='https://github.com/truly-systems/glpi-sdk-python/archive/0.1.1.tar.gz',
download_url='https://github.com/truly-systems/glpi-sdk-python/archive/%s.tar.gz' % __version__,
author='Marco Tulio R Braga',
author_email='[email protected]',
license='Apache-2.0',
Expand Down
3 changes: 1 addition & 2 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
pep8
codecov
python-dotenv
git+https://github.com/truly-systems/glpi-sdk-python.git@master#egg=glpi

0 comments on commit 8bbd3c0

Please sign in to comment.