Skip to content

Commit 2204c86

Browse files
authored
Merge pull request #11 from fasteiner/feature/people
Feature/people
2 parents d16de65 + 7bbea69 commit 2204c86

File tree

6 files changed

+159
-26
lines changed

6 files changed

+159
-26
lines changed

ChangeLog.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,16 @@
11
# Change Log
22

3+
## v0.0.2.10
4+
5+
### New Features
6+
7+
- Core: add enum LogLevel
8+
- Core: add method set_log_level to change the log level
9+
10+
### Breaking Changes
11+
12+
- Core: init: parameter for logger has been added, if not provided, a new logger will be created
13+
314
## v0.0.2.9
415

516
### New Features

README.md

Lines changed: 75 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,46 @@ This module is used to interact with the Xurrent API. It provides a set of class
2222
baseUrl = "https://api.4me.qa/v1"
2323
account = "account-name"
2424

25-
logger = setup_logger(verbose=True)
26-
2725
x_api_helper = XurrentApiHelper(baseUrl, apitoken, account)
2826

27+
# change log level (default: INFO)
28+
x_api_helper.set_log_level("DEBUG")
29+
2930
# Plain API Call
3031
uri = "/requests?subject=Example Subject"
3132
connection_object.api_call(uri, 'GET')
3233

3334
```
3435

35-
### Requests
36+
#### People
37+
38+
```python
39+
from xurrent.people import Person
40+
41+
people = Person.get_by_id(x_api_helper, <id>)
42+
43+
api_user = Person.get_me(x_api_helper)
44+
45+
# get all people with a specific subject
46+
people = Person.get_people(x_api_helper,queryfilter={
47+
"name": "Werner"
48+
})
49+
50+
# enable
51+
people.enable()
52+
53+
#disable
54+
people.disable()
55+
#archive
56+
people.archive()
57+
#trash
58+
people.trash()
59+
#restore
60+
people.restore()
61+
62+
```
63+
64+
#### Requests
3665

3766
```python
3867
from xurrent.requests import Request
@@ -60,7 +89,7 @@ This module is used to interact with the Xurrent API. It provides a set of class
6089

6190
```
6291

63-
#### Request Notes
92+
##### Request Notes
6493

6594
```python
6695
from xurrent.requests import Request
@@ -80,24 +109,7 @@ This module is used to interact with the Xurrent API. It provides a set of class
80109

81110
```
82111

83-
### Workflows
84-
85-
```python
86-
87-
from xurrent.workflows import Workflow
88-
89-
workflow = Workflow.get_by_id(x_api_helper, <id>)
90-
91-
#close
92-
workflow.close() # completion reason: completed, note: closed
93-
# close with completion reason
94-
workflow.close(completion_reason="withdrawn")
95-
#close with completion reason and note
96-
workflow.close(completion_reason="withdrawn", note="This is a test note")
97-
98-
```
99-
100-
### Tasks
112+
#### Tasks
101113

102114
```python
103115
from xurrent.tasks import Task
@@ -125,3 +137,44 @@ This module is used to interact with the Xurrent API. It provides a set of class
125137

126138

127139
```
140+
141+
#### Teams
142+
143+
```python
144+
from xurrent.teams import Team
145+
146+
team = Team.get_by_id(x_api_helper, <id>)
147+
148+
# get all teams with a specific subject
149+
teams = Team.get_team(x_api_helper,predifinedFilter="enabled")
150+
151+
# enable
152+
team.enable()
153+
154+
#disable
155+
team.disable()
156+
#archive
157+
team.archive()
158+
#trash
159+
team.trash()
160+
#restore
161+
team.restore()
162+
163+
```
164+
165+
#### Workflows
166+
167+
```python
168+
169+
from xurrent.workflows import Workflow
170+
171+
workflow = Workflow.get_by_id(x_api_helper, <id>)
172+
173+
#close
174+
workflow.close() # completion reason: completed, note: closed
175+
# close with completion reason
176+
workflow.close(completion_reason="withdrawn")
177+
#close with completion reason and note
178+
workflow.close(completion_reason="withdrawn", note="This is a test note")
179+
180+
```

pyproject.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "xurrent"
3-
version = "0.0.2.9"
3+
version = "0.0.2.10"
44
authors = [
55
{ name="Fabian Steiner", email="fabian@stei-ner.net" },
66
]
@@ -18,7 +18,7 @@ Homepage = "https://github.com/fasteiner/xurrent-python"
1818
Issues = "https://github.com/fasteiner/xurrent-python/issues"
1919
[tool.poetry]
2020
name = "xurrent"
21-
version = "0.0.2.9"
21+
version = "0.0.2.10"
2222
description = "A python module to interact with the Xurrent API."
2323
authors = ["Ing. Fabian Franz Steiner BSc. <fabian.steiner@tttech.com>"]
2424
readme = "README.md"

src/xurrent/core.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
11
from __future__ import annotations # Needed for forward references
22
from datetime import datetime
3+
from enum import Enum
34
import time
45
import requests
56
import logging
67
import json
78
import re
89

10+
class LogLevel(Enum):
11+
DEBUG = logging.DEBUG
12+
INFO = logging.INFO
13+
WARNING = logging.WARNING
14+
ERROR = logging.ERROR
15+
CRITICAL = logging.CRITICAL
16+
917
class JsonSerializableDict(dict):
1018
def __init__(self, **kwargs):
1119
# Initialize with keyword arguments as dictionary items
@@ -37,11 +45,23 @@ class XurrentApiHelper:
3745
api_user: Person # Forward declaration with a string
3846
api_user_teams: List[Team] # Forward declaration with a string
3947

40-
def __init__(self, base_url, api_key, api_account, resolve_user=True):
48+
def __init__(self, base_url, api_key, api_account,resolve_user=True, logger: Logger=None):
49+
"""
50+
Initialize the Xurrent API helper.
51+
52+
:param base_url: Base URL of the Xurrent API
53+
:param api_key: API key to authenticate with
54+
:param api_account: Account name to use
55+
:param resolve_user: Resolve the API user and their teams (default: True)
56+
:param logger: Logger to use (optional), otherwise a new logger is created
57+
"""
4158
self.base_url = base_url
4259
self.api_key = api_key
4360
self.api_account = api_account
44-
self.logger = logging.getLogger(__name__)
61+
if logger:
62+
self.logger = logger
63+
else:
64+
self.logger = self.create_logger(False)
4565
if resolve_user:
4666
# Import Person lazily
4767
from .people import Person
@@ -77,6 +97,37 @@ def __append_per_page(self, uri, per_page=100):
7797
return f'{uri}?per_page={per_page}'
7898
return uri
7999

100+
def create_logger(self, verbose) -> Logger:
101+
"""
102+
Create a logger for the API helper.
103+
:param verbose: Enable verbose logging (debug level)
104+
:return: Logger instance
105+
"""
106+
logger = logging.getLogger()
107+
log_stream = logging.StreamHandler()
108+
109+
if verbose:
110+
logger.setLevel(logging.DEBUG)
111+
log_stream.setLevel(logging.DEBUG)
112+
else:
113+
logger.setLevel(logging.INFO)
114+
log_stream.setLevel(logging.INFO)
115+
116+
formatter = logging.Formatter('%(levelname)s - %(message)s')
117+
log_stream.setFormatter(formatter)
118+
logger.addHandler(log_stream)
119+
return logger
120+
121+
def set_log_level(self, level: LogLevel):
122+
"""
123+
Set the log level for the logger and all handlers.
124+
125+
:param level: Log level to set
126+
"""
127+
self.logger.setLevel(level)
128+
for handler in self.logger.handlers:
129+
handler.setLevel(level)
130+
80131

81132
def api_call(self, uri: str, method='GET', data=None, per_page=100):
82133
"""

src/xurrent/requests.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,9 @@ class RequestStatus(str, Enum):
3333
project_pending = "project_pending" # Project Pending
3434
completed = "completed" # Completed
3535

36+
def __str__(self):
37+
return self.value
38+
3639
class CompletionReason(str, Enum):
3740
solved = "solved" # Solved - Root Cause Analysis Not Required
3841
workaround = "workaround" # Workaround - Root Cause Not Removed
@@ -45,6 +48,9 @@ class CompletionReason(str, Enum):
4548
declined = "declined" # Declined - Declined by Service Provider
4649
unsolvable = "unsolvable" # Unsolvable - Unable to Solve
4750

51+
def __str__(self):
52+
return self.value
53+
4854

4955
class PredefinedFilter(str, Enum):
5056
completed = "completed" # /requests/completed
@@ -56,6 +62,9 @@ class PredefinedFilter(str, Enum):
5662
problem_management_review = "problem_management_review" # /requests/problem_management_review
5763
sla_accountability = "sla_accountability" # /requests/sla_accountability
5864

65+
def __str__(self):
66+
return self.value
67+
5968
class PredefinedNotesFilter(str, Enum):
6069
public = "public" # /requests/public
6170
internal = "internal" # /requests/internal

tests/integration/core_test.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import os
33
import sys
44
from dotenv import load_dotenv
5+
import logging
56

67
# Add the `../src` directory to sys.path
78
sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), "../../src")))
@@ -46,5 +47,13 @@ def test_api_helper_setup(x_api_helper):
4647
assert isinstance(x_api_helper.api_user_teams, list)
4748
for team in x_api_helper.api_user_teams:
4849
assert isinstance(team, Team)
50+
51+
assert x_api_helper.logger.level == logging.INFO
52+
53+
def test_set_log_level(x_api_helper):
54+
x_api_helper.set_log_level("DEBUG")
55+
assert x_api_helper.logger.level == logging.DEBUG
56+
x_api_helper.set_log_level(logging.WARNING)
57+
assert x_api_helper.logger.level == logging.WARNING
4958

5059

0 commit comments

Comments
 (0)