Phoebe Yang
01/28/2022, 4:40 PMlass ServicesnowApi(HttpStream):
url_base = "https://.com/api/now/v1/"
# Set this as a noop.
primary_key = None
def __init__(self, limit: str, sys_created_from: str, sys_created_to: str, **kwargs):
super().__init__(**kwargs)
# Here's where we set the variable from our input to pass it down to the source.
self.limit = limit
self.sys_created_from = sys_created_from
self.sys_created_to = sys_created_to
def path(self, **kwargs) -> str:
# This defines the path to the endpoint that we want to hit.
limit = self.limit
sys_created_from = self.sys_created_from
sys_created_to = self.sys_created_to
return f"table/incident?sysparm_offset=0&sysparm_limit={limit}&sysparm_query=sys_created_on>={sys_created_from} 08:00^sys_created_on<{sys_created_to} 08:00^active=ISNOTEMPTY"
def request_params(
self,
stream_state: Mapping[str, Any],
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> MutableMapping[str, Any]:
# The api requires that we include the Pokemon name as a query param so we do that in this method.
limit = self.limit
sys_created_from = self.sys_created_from
sys_created_to = self.sys_created_to
return {"limit": limit, "sys_created_from":sys_created_from, "sys_created_to":sys_created_to}
def parse_response(
self,
response: requests.Response,
stream_state: Mapping[str, Any],
stream_slice: Mapping[str, Any] = None,
next_page_token: Mapping[str, Any] = None,
) -> Iterable[Mapping]:
# The response is a simple JSON whose schema matches our stream's schema exactly,
# so we just return a list containing the response.
return [response.json()]
def next_page_token(self, response: requests.Response) -> Optional[Mapping[str, Any]]:
# While the PokeAPI does offer pagination, we will only ever retrieve one Pokemon with this implementation,
# so we just return None to indicate that there will never be any more pages in the response.
return None
Daniel Eduardo Portugal Revilla
01/28/2022, 5:15 PMflow
01/29/2022, 6:29 PMJordan Velich
01/31/2022, 6:05 AMJordan Velich
01/31/2022, 6:06 AMuser
02/01/2022, 4:49 PMAlessandro Duico
02/02/2022, 11:21 AMAlessandro Duico
02/02/2022, 11:48 AMAlessandro Duico
02/02/2022, 11:52 AMAlessandro Duico
02/02/2022, 12:22 PM"result": [...]
?
maybe this doesn't fit the schema, all results return inside this array