mirror of
				https://github.com/brygphilomena/pysimplesat.git
				synced 2025-11-04 08:47:29 +00:00 
			
		
		
		
	Update pagination to take the variable "body" since simplesat does their searches with the filter in the body instead of parameters
This commit is contained in:
		
							parent
							
								
									ff5a913114
								
							
						
					
					
						commit
						c2b02bbf27
					
				@ -1,6 +1,6 @@
 | 
			
		||||
[project]
 | 
			
		||||
name = "pysimplesat"
 | 
			
		||||
version = "0.1.7"
 | 
			
		||||
version = "0.1.8"
 | 
			
		||||
authors = [
 | 
			
		||||
  { name="Peter Annabel", email="peter.annabel@gmail.com" },
 | 
			
		||||
]
 | 
			
		||||
 | 
			
		||||
@ -77,7 +77,7 @@ class SimpleSatClient(ABC):
 | 
			
		||||
                method,
 | 
			
		||||
                url,
 | 
			
		||||
                headers=headers,
 | 
			
		||||
                data=data,
 | 
			
		||||
                json=data,
 | 
			
		||||
                params=cast(dict[str, Any], params or {}),
 | 
			
		||||
                stream=stream,
 | 
			
		||||
            )
 | 
			
		||||
 | 
			
		||||
@ -8,6 +8,7 @@ if TYPE_CHECKING:
 | 
			
		||||
 | 
			
		||||
    from pysimplesat.clients.base_client import SimpleSatClient
 | 
			
		||||
    from pysimplesat.types import (
 | 
			
		||||
        JSON,
 | 
			
		||||
        RequestData,
 | 
			
		||||
        RequestMethod,
 | 
			
		||||
        RequestParams,
 | 
			
		||||
@ -112,7 +113,7 @@ class SimpleSatEndpoint:
 | 
			
		||||
        self,
 | 
			
		||||
        method: RequestMethod,
 | 
			
		||||
        endpoint: SimpleSatEndpoint | None = None,
 | 
			
		||||
        data: RequestData | None = None,
 | 
			
		||||
        data: JSON | None = None,
 | 
			
		||||
        params: RequestParams | None = None,
 | 
			
		||||
        headers: dict[str, str] | None = None,
 | 
			
		||||
        stream: bool = False,  # noqa: FBT001, FBT002
 | 
			
		||||
 | 
			
		||||
@ -26,6 +26,7 @@ class AnswersSearchEndpoint(
 | 
			
		||||
        self,
 | 
			
		||||
        page: int,
 | 
			
		||||
        params: SimpleSatRequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ) -> PaginatedResponse[Answer]:
 | 
			
		||||
        """
 | 
			
		||||
        Performs a POST request against the /answers/search endpoint and returns an initialized PaginatedResponse object.
 | 
			
		||||
@ -41,12 +42,13 @@ class AnswersSearchEndpoint(
 | 
			
		||||
        else:
 | 
			
		||||
            params = {"page": page}
 | 
			
		||||
        return PaginatedResponse(
 | 
			
		||||
            super()._make_request("POST", params=params),
 | 
			
		||||
            super()._make_request("POST", data=body, params=params),
 | 
			
		||||
            Answer,
 | 
			
		||||
            self,
 | 
			
		||||
            "answers",
 | 
			
		||||
            page,
 | 
			
		||||
            params,
 | 
			
		||||
            body,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def post(self, data: JSON | None = None, params: SimpleSatRequestParams | None = None) -> Answer:
 | 
			
		||||
 | 
			
		||||
@ -25,6 +25,7 @@ class QuestionsEndpoint(
 | 
			
		||||
        self,
 | 
			
		||||
        page: int,
 | 
			
		||||
        params: SimpleSatRequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ) -> PaginatedResponse[Question]:
 | 
			
		||||
        """
 | 
			
		||||
        Performs a GET request against the /questions endpoint and returns an initialized PaginatedResponse object.
 | 
			
		||||
@ -40,12 +41,13 @@ class QuestionsEndpoint(
 | 
			
		||||
        else:
 | 
			
		||||
            params = {"page": page}
 | 
			
		||||
        return PaginatedResponse(
 | 
			
		||||
            super()._make_request("GET", params=params),
 | 
			
		||||
            super()._make_request("GET", data=body, params=params),
 | 
			
		||||
            Question,
 | 
			
		||||
            self,
 | 
			
		||||
            "questions",
 | 
			
		||||
            page,
 | 
			
		||||
            params,
 | 
			
		||||
            body,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def get(
 | 
			
		||||
 | 
			
		||||
@ -26,6 +26,7 @@ class ResponsesSearchEndpoint(
 | 
			
		||||
        self,
 | 
			
		||||
        page: int,
 | 
			
		||||
        params: SimpleSatRequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ) -> PaginatedResponse[Response]:
 | 
			
		||||
        """
 | 
			
		||||
        Performs a POST request against the /responses/search endpoint and returns an initialized PaginatedResponse object.
 | 
			
		||||
@ -41,12 +42,13 @@ class ResponsesSearchEndpoint(
 | 
			
		||||
        else:
 | 
			
		||||
            params = {"page[number]": page}
 | 
			
		||||
        return PaginatedResponse(
 | 
			
		||||
            super()._make_request("POST", params=params),
 | 
			
		||||
            super()._make_request("POST", data=body, params=params),
 | 
			
		||||
            Response,
 | 
			
		||||
            self,
 | 
			
		||||
            "responses",
 | 
			
		||||
            page,
 | 
			
		||||
            params,
 | 
			
		||||
            body,
 | 
			
		||||
        )
 | 
			
		||||
 | 
			
		||||
    def post(self, data: JSON | None = None, params: SimpleSatRequestParams | None = None) -> Response:
 | 
			
		||||
 | 
			
		||||
@ -32,6 +32,7 @@ class IPaginateable(IMethodBase, Generic[TModel, TRequestParams]):
 | 
			
		||||
        self,
 | 
			
		||||
        page: int | None = 1,
 | 
			
		||||
        params: TRequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ) -> PaginatedResponse[TModel]:
 | 
			
		||||
        pass
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -11,7 +11,7 @@ if TYPE_CHECKING:
 | 
			
		||||
    from pydantic import BaseModel
 | 
			
		||||
    from requests import Response
 | 
			
		||||
 | 
			
		||||
    from pysimplesat.types import RequestParams
 | 
			
		||||
    from pysimplesat.types import RequestParams, JSON
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
TModel = TypeVar("TModel", bound="BaseModel")
 | 
			
		||||
@ -43,6 +43,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
        endpoint: str,
 | 
			
		||||
        page: int,
 | 
			
		||||
        params: RequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ) -> None:
 | 
			
		||||
        """
 | 
			
		||||
        PaginatedResponse is a wrapper class for handling paginated responses from the
 | 
			
		||||
@ -57,7 +58,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
        expected model type for the response data. This allows for type-safe handling
 | 
			
		||||
        of model instances throughout the class.
 | 
			
		||||
        """
 | 
			
		||||
        self._initialize(response, response_model, endpointmodel, endpoint, page, params)
 | 
			
		||||
        self._initialize(response, response_model, endpointmodel, endpoint, page, body, params)
 | 
			
		||||
 | 
			
		||||
    def _initialize(
 | 
			
		||||
        self,
 | 
			
		||||
@ -67,6 +68,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
        endpoint: str,
 | 
			
		||||
        page: int,
 | 
			
		||||
        params: RequestParams | None = None,
 | 
			
		||||
        body: JSON | None = None,
 | 
			
		||||
    ):
 | 
			
		||||
        """
 | 
			
		||||
        Initialize the instance variables using the provided response, endpointmodel, and page size.
 | 
			
		||||
@ -94,6 +96,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
            self.prev_page = page - 1 if page > 1 else 1
 | 
			
		||||
            self.next_page = page + 1
 | 
			
		||||
        self.params = params
 | 
			
		||||
        self.body = body
 | 
			
		||||
        self.data: list[TModel] = [response_model.model_validate(d) for d in response.json().get(endpoint, {})]
 | 
			
		||||
        self.has_data = self.data and len(self.data) > 0
 | 
			
		||||
        self.index = 0
 | 
			
		||||
@ -110,7 +113,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
            self.has_data = False
 | 
			
		||||
            return self
 | 
			
		||||
 | 
			
		||||
        next_response = self.endpointmodel.paginated(self.next_page, self.params)
 | 
			
		||||
        next_response = self.endpointmodel.paginated(self.next_page, self.params, self.body)
 | 
			
		||||
        self._initialize(
 | 
			
		||||
            next_response.response,
 | 
			
		||||
            next_response.response_model,
 | 
			
		||||
@ -118,6 +121,7 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
            next_response.endpoint,
 | 
			
		||||
            self.next_page,
 | 
			
		||||
            self.params,
 | 
			
		||||
            self.body,
 | 
			
		||||
        )
 | 
			
		||||
        return self
 | 
			
		||||
 | 
			
		||||
@ -133,13 +137,14 @@ class PaginatedResponse(Generic[TModel]):
 | 
			
		||||
            self.has_data = False
 | 
			
		||||
            return self
 | 
			
		||||
 | 
			
		||||
        prev_response = self.endpointmodel.paginated(self.prev_page, self.params)
 | 
			
		||||
        prev_response = self.endpointmodel.paginated(self.prev_page, self.params, self.body)
 | 
			
		||||
        self._initialize(
 | 
			
		||||
            prev_response.response,
 | 
			
		||||
            prev_response.response_model,
 | 
			
		||||
            prev_response.endpointmodel,
 | 
			
		||||
            self.prev_page,
 | 
			
		||||
            self.params,
 | 
			
		||||
            self.body,
 | 
			
		||||
        )
 | 
			
		||||
        return self
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@ -13,8 +13,9 @@ simplesat_api_client = SimpleSatAPIClient(
 | 
			
		||||
 | 
			
		||||
#surveys = simplesat_api_client.surveys.get()
 | 
			
		||||
#print(surveys)
 | 
			
		||||
body = {"start_date": "2025-04-11T17:00:00Z"}
 | 
			
		||||
 | 
			
		||||
page_responses = simplesat_api_client.responses.search.paginated(1)
 | 
			
		||||
page_responses = simplesat_api_client.responses.search.paginated(1, body=body)
 | 
			
		||||
responses = page_responses.all()
 | 
			
		||||
print(responses)
 | 
			
		||||
for response in responses:
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user