Skip to content

Commit

Permalink
added search.alerts endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
anisbhsl committed Sep 13, 2023
1 parent 241eaea commit 4b988bf
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 8 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ config = {
"query_name": ""
}
#initialize a Sinequa connector instance
sinequa=pynequa.Sinequa(config=config)
# initialize a Sinequa connector instance
sinequa = pynequa.Sinequa(config=config)
params = QueryParams()
params.search_text = "<your_search_text>"
..... #other params
..... # other params
#perform a search query operation
results=sinequa.search_query(params)
# perform a search query operation
results = sinequa.search_query(params)
```


Expand Down
22 changes: 19 additions & 3 deletions pynequa/core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pynequa.api import API
from typing import Optional, List, Dict
from pynequa.models import QueryParams, TreeParams
from pynequa.models import QueryParams, TreeParams, AlertParams


class Sinequa(API):
Expand Down Expand Up @@ -329,11 +329,27 @@ def search_profile_subtree(self, profile: str, query_params: QueryParams,
}
return self.post(endpoint=endpoint, payload=payload)

def search_alerts(self):
def search_alerts(self, action: str, alert: AlertParams, name: str = "", old_name: str = ""):
'''
This method makes it possible to manage alerts in search.alerts endpoint.
Args:
action(str): action name, options: [list, create, read, update, delete]
alert_params(AlertParams): parameters for alert configuration
name(str): name of alert to be read [OPTIONAL]
old_name(str): name of alert before you change it [OPTIONAL]
Returns:
Dict: returns a JSON response with listing alerts
'''
endpoint = "search.alerts"
pass
payload = {
"action": action,
"alert": alert._prepare_alert_params_payload(),
"name": name,
"oldName": old_name
}
return self.post(endpoint=endpoint, payload=payload)

def search_baskets(self):
'''
Expand Down
50 changes: 50 additions & 0 deletions pynequa/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,53 @@ def _prepare_query_args(self, query_name: str) -> Dict:
params["advanced"] = self.advanced._generate_advanced_params_payload()

return params


class AlertParams:
name: str = ""
description: str = ""
profile: str = ""
timezone: str = ""
frequency: str = ""
days: str = ""
alert_from: str = ""
alert_to: str = ""
times: str = "" # format: HH:mm
active: bool = False
combine_with_other_alerts: bool = False
respect_tab_selection: bool = False

def __init__(self) -> None:
return

def _prepare_alert_params_payload(self) -> Dict:
params = {
"name": self.name,
"description": self.description,
"active": self.active,
"combineWithOtherAlerts": self.combine_with_other_alerts,
"respectTabSelection": self.respect_tab_selection
}

if self.profile is not None:
params["profile"] = self.profile

if self.timezone is not None:
params["timezone"] = self.timezone

if self.frequency is not None:
params["frequency"] = self.frequency

if self.days is not None:
params["days"] = self.days

if self.alert_from is not None:
params["from"] = self.alert_from

if self.alert_to is not None:
params["to"] = self.alert_to

if self.times is not None:
params["times"] = self.times

return params

0 comments on commit 4b988bf

Please sign in to comment.