Repository navigation
Pysdksls 01 saved locations #115
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
870c3f3
Introduce Saved_Locations support.
b92f76b
Correction to use of Optionals
5ac107e
Minor version bump
8b73e9c
removed import StrEnum
d984246
Unions used for compatability with older Python versions
7b8af7c
Optionals further used for compatability with older Python versions
8eaa188
list to List (for older Python compatability).
baedf12
data refinement
e045a0a
various fixes:
c2fb833
tests ensure saved_location_id is sent as expected where relevant.
fc04f2a
line-length set to 120
0cf43f8
saved_location_id moved into Location.
a72a7fc
test_search_event_result_set modified
55309d7
ruff format
c49bd87
format change in README.md
17f1ce9
removed duplicate definitions
33d007a
All Beam Location fields become Optional
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -12,7 +12,6 @@ | |
|
|
||
|
|
||
| class Config(object): | ||
|
|
||
| _config_sections = ( | ||
| "endpoint", | ||
| "oauth2", | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,9 +1,17 @@ | ||
| from predicthq.endpoints.base import BaseEndpoint | ||
| from predicthq.endpoints.decorators import returns | ||
| from .schemas import Account | ||
| from deprecated import deprecated | ||
|
|
||
|
|
||
| class AccountsEndpoint(BaseEndpoint): | ||
| @deprecated( | ||
| reason=( | ||
| "The Accounts endpoint in the SDK is deprecated and will be removed in future releases. " | ||
| "Account information can be managed via the PredictHQ dashboard." | ||
| ), | ||
| category=FutureWarning, | ||
| ) | ||
| @returns(Account) | ||
| def self(self): | ||
| return self.client.get(self.build_url("v1", "accounts/self")) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| from .endpoint import SavedLocationsEndpoint | ||
| from .schemas import SavedLocation | ||
|
|
||
|
|
||
| __all__ = ["SavedLocationsEndpoint", "SavedLocation"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,168 @@ | ||
| from predicthq.endpoints.base import UserBaseEndpoint, BaseEndpoint | ||
| from predicthq.endpoints.decorators import accepts, returns | ||
| from typing import overload, List, Optional | ||
| from .schemas import ( | ||
| SavedLocation, | ||
| SavedLocationResultSet, | ||
| CreateSavedLocationResponse, | ||
| PostSharingEnableResponse, | ||
| SuggestedRadiusResponse, | ||
| Location, | ||
| ) | ||
| from ..events.schemas import EventResultSet | ||
|
|
||
|
|
||
| class SavedLocationsEndpoint(UserBaseEndpoint): | ||
| @overload | ||
| def search( | ||
| self, | ||
| location_id: Optional[List[str]] = None, | ||
| location_code: Optional[List[str]] = None, | ||
| labels: Optional[List[str]] = None, | ||
| user_id: Optional[List[str]] = None, | ||
| subscription_valid_types: Optional[List[str]] = None, | ||
| q: Optional[str] = None, | ||
| sort: Optional[List[str]] = None, | ||
| offset: Optional[int] = None, | ||
| limit: Optional[int] = None, | ||
| **params, | ||
| ): ... | ||
| @accepts() | ||
| @returns(SavedLocationResultSet) | ||
| def search(self, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| result = self.client.get( | ||
| self.build_url("v1", "saved-locations"), | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
| return result | ||
|
|
||
| @overload | ||
| def create( | ||
| self, | ||
| name: str, | ||
| geojson: dict, | ||
| labels: Optional[List[str]] = None, | ||
| location_code: Optional[str] = None, | ||
| formatted_address: Optional[str] = None, | ||
| description: Optional[str] = None, | ||
| place_ids: Optional[List[str]] = None, | ||
| **params, | ||
| ): ... | ||
| @accepts(query_string=False) | ||
| @returns(CreateSavedLocationResponse) | ||
| def create(self, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
|
|
||
| result = self.client.post( | ||
| f"{self.build_url('v1', 'saved-locations')}", | ||
| json=params, | ||
| verify=verify_ssl, | ||
| ) | ||
| return result | ||
|
|
||
| @accepts() | ||
| @returns(SavedLocation) | ||
| def get(self, location_id, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| return self.client.get( | ||
| f"{self.build_url('v1', 'saved-locations')}{location_id}", | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
|
|
||
| @overload | ||
| def search_event_result_set( | ||
| location_id: str, | ||
| date_range_type: Optional[str] = None, | ||
| offset: Optional[int] = None, | ||
| limit: Optional[int] = None, | ||
| **params, | ||
| ): ... | ||
| @returns(EventResultSet) | ||
| def search_event_result_set(self, location_id, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| url = f"{self.build_url('v1', 'saved-locations')}{location_id}/insights/events" | ||
| response = self.client.get( | ||
| url, | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
| return response | ||
|
|
||
| @accepts() | ||
| def refresh_location_insights(self, location_id: str, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| return self.client.post( | ||
| f"{self.build_url('v1', 'saved-locations')}{location_id}/insights/refresh", | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
|
|
||
| @overload | ||
| def replace_location_data( | ||
| self, | ||
| location_id: str, | ||
| name: str, | ||
| geojson: dict, | ||
| labels: Optional[List[str]] = None, | ||
| location_code: Optional[str] = None, | ||
| formatted_address: Optional[str] = None, | ||
| description: Optional[str] = None, | ||
| place_ids: Optional[List[str]] = None, | ||
| external_id: Optional[str] = None, | ||
| **params, | ||
| ): ... | ||
| @accepts(query_string=False) | ||
| def replace_location_data(self, location_id: str, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| params.pop("location_id", None) # Remove location_id from payload | ||
| response = self.client.put( | ||
| f"{self.build_url('v1', 'saved-locations')}{location_id}", | ||
| json=params, | ||
| verify=verify_ssl, | ||
| ) | ||
| return response | ||
|
|
||
| @accepts() | ||
| def delete_location(self, location_id: str, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| return self.client.delete( | ||
| f"{self.build_url('v1', 'saved-locations')}{location_id}", | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
|
|
||
| @accepts() | ||
| @returns(PostSharingEnableResponse) | ||
| def sharing_enable(self, location_id: str, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| return self.client.post( | ||
| f"{self.build_url('v1', 'saved-locations')}{location_id}/sharing/enable", | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
|
|
||
| @overload | ||
| def suggested_radius( | ||
| self, | ||
| location_origin: Location, | ||
| radius_unit: str, | ||
| industry: str, | ||
| **params, | ||
| ): ... | ||
| @accepts(query_string=False) | ||
| @returns(SuggestedRadiusResponse) | ||
| def suggested_radius(self, **params): | ||
| verify_ssl = params.pop("config.verify_ssl", True) | ||
| loc = params.pop("location_origin", None) | ||
| if isinstance(loc, Location): | ||
| params["location.origin"] = loc.as_geopoint() | ||
| elif isinstance(loc, str): | ||
| params["location.origin"] = loc | ||
| return self.client.get( | ||
| f"{self.build_url('v1', 'suggested-radius')}", | ||
| params=params, | ||
| verify=verify_ssl, | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.