Skip to content

Commit e38a71d

Browse files
PaulDDDPaul Duncan
andauthored
Pysdksls 01 saved locations (#115)
* Introduce Saved_Locations support. Deprecate OAUTH, & Accounts * Minor version bump --------- Co-authored-by: Paul Duncan <[email protected]>
1 parent 5e551ff commit e38a71d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+1982
-341
lines changed

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,15 @@ If you are migrating to version 5.0.0 or above from an earlier version, please c
3535

3636
We support all the endpoints available in our API.
3737

38-
* `oauth2`
39-
* `accounts`
38+
* `oauth2` (deprecated, use `access_token` instead)
39+
* `accounts` (deprecated)
4040
* `broadcasts`
4141
* `events`
4242
* `features`
4343
* `places`
4444
* `radius`
4545
* `beam`
46+
* `saved_locations`
4647

4748
Please refer to our [API Documentation](https://docs.predicthq.com/) for a description of each endpoint.
4849

@@ -316,6 +317,27 @@ for event in phq.events.search(config={"verify_ssl": False}):
316317
```
317318

318319

320+
### Saved_Locations endpoints
321+
322+
Additional examples are available in [usecases/saved_locations.py](https://github.com/predicthq/sdk-py/tree/master/usecases/places.py) file.
323+
324+
The following example searches for the saved_locations according to the parameters defined:
325+
326+
```Python
327+
from predicthq import Client
328+
329+
phq = Client(access_token="abc123")
330+
331+
332+
for saved_location in phq.saved_locations.search(
333+
labels=["test", "retail"],
334+
q="London",
335+
sort="-created",
336+
):
337+
print(saved_location.location_id, saved_location.create_dt, saved_location.status)
338+
```
339+
340+
319341
## Running Tests
320342

321343
```Shell

predicthq/client.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ def initialize_endpoints(self):
3636
self.places = endpoints.PlacesEndpoint(proxy(self))
3737
self.radius = endpoints.SuggestedRadiusEndpoint(proxy(self))
3838
self.beam = endpoints.BeamEndpoint(proxy(self))
39+
self.saved_locations = endpoints.SavedLocationsEndpoint(proxy(self))
3940

4041
def get_headers(self, headers):
4142
_headers = {

predicthq/config.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212

1313

1414
class Config(object):
15-
1615
_config_sections = (
1716
"endpoint",
1817
"oauth2",

predicthq/endpoints/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from .v1.places import PlacesEndpoint
77
from .v1.radius import SuggestedRadiusEndpoint
88
from .v1.beam import BeamEndpoint
9+
from .v1.saved_locations import SavedLocationsEndpoint
910

1011

1112
__all__ = [
@@ -17,4 +18,5 @@
1718
"PlacesEndpoint",
1819
"SuggestedRadiusEndpoint",
1920
"BeamEndpoint",
21+
"SavedLocationsEndpoint",
2022
]

predicthq/endpoints/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ def __new__(mcs, name, bases, data):
33
if "Meta" not in data:
44

55
class Meta:
6-
""" Used by decorators when overriding schema classes """
6+
"""Used by decorators when overriding schema classes"""
77

88
pass
99

predicthq/endpoints/oauth2/endpoint.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,17 @@
22
from predicthq.endpoints.decorators import accepts, returns
33
from .decorators import preload_config_defaults
44
from .schemas import AccessToken
5+
from deprecated import deprecated
56

67

78
class OAuth2Endpoint(BaseEndpoint):
9+
@deprecated(
10+
reason=(
11+
"OAuth2 endpoints in the SDK are deprecated and will be removed in future releases. "
12+
"Use TokenAuth (API Access Token) with Client(..., access_token=...)."
13+
),
14+
category=FutureWarning,
15+
)
816
@accepts()
917
@preload_config_defaults(["client_id", "client_secret", "scope", "grant_type"])
1018
@returns(AccessToken)
@@ -22,6 +30,13 @@ def get_token(self, client_id, client_secret, scope, grant_type, **kwargs):
2230
verify=verify_ssl,
2331
)
2432

33+
@deprecated(
34+
reason=(
35+
"OAuth2 endpoints in the SDK are deprecated and will be removed in future releases. "
36+
"Use TokenAuth (API Access Token) with Client(..., access_token=...)."
37+
),
38+
category=FutureWarning,
39+
)
2540
@accepts()
2641
@preload_config_defaults(["client_id", "client_secret", "token_type_hint"])
2742
def revoke_token(self, client_id, client_secret, token, token_type_hint, **kwargs):
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
from predicthq.endpoints.base import BaseEndpoint
22
from predicthq.endpoints.decorators import returns
33
from .schemas import Account
4+
from deprecated import deprecated
45

56

67
class AccountsEndpoint(BaseEndpoint):
8+
@deprecated(
9+
reason=(
10+
"The Accounts endpoint in the SDK is deprecated and will be removed in future releases. "
11+
"Account information can be managed via the PredictHQ dashboard."
12+
),
13+
category=FutureWarning,
14+
)
715
@returns(Account)
816
def self(self):
917
return self.client.get(self.build_url("v1", "accounts/self"))

predicthq/endpoints/v1/beam/endpoint.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
AnalysisGroup,
1010
AnalysisGroupResultSet,
1111
GeoJson,
12-
Place
12+
Place,
1313
)
1414
from predicthq.endpoints.decorators import accepts, returns
1515
from typing import overload, List, Optional, TextIO, Union
@@ -185,8 +185,8 @@ def upload_demand(
185185
self,
186186
analysis_id: str,
187187
json: Optional[Union[str, TextIO]] = None,
188-
ndjson: Optional[Union[str, TextIO]] = None,
189-
csv: Optional[Union[str, TextIO]] = None,
188+
ndjson: Optional[Union[str, TextIO]] = None,
189+
csv: Optional[Union[str, TextIO]] = None,
190190
**params,
191191
): ...
192192
def upload_demand(self, analysis_id: str, **params):

predicthq/endpoints/v1/beam/schemas.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from pydantic import BaseModel, Field, ConfigDict
22
from datetime import datetime
33
from predicthq.endpoints.schemas import ArgKwargResultSet
4-
from typing import Optional, List
4+
from typing import Optional, List, Union
55

66
# Python < 3.11 does not have StrEnum in the enum module
77
import sys
8+
89
if sys.version_info < (3, 11):
910
import enum
1011

@@ -38,7 +39,6 @@ def get_next(self):
3839
return self._more(**self._kwargs)
3940

4041

41-
4242
class CreateAnalysisResponse(BaseModel):
4343
model_config: ConfigDict = ConfigDict(extra="allow")
4444

@@ -55,10 +55,11 @@ class GeoPoint(BaseModel):
5555
class Location(BaseModel):
5656
model_config: ConfigDict = ConfigDict(extra="allow")
5757

58-
geopoint: GeoPoint
59-
radius: float
60-
unit: str
58+
geopoint: Optional[GeoPoint] = None
59+
radius: Optional[float] = None
60+
unit: Optional[str] = None
6161
google_place_id: Optional[str] = None
62+
saved_location_id: Optional[str] = None
6263

6364

6465
class RankLevel(BaseModel):

predicthq/endpoints/v1/features/endpoint.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ class FeaturesEndpoint(UserBaseEndpoint):
1919
def mutate_bool_to_default_for_type(cls, user_request_spec):
2020
for key, val in user_request_spec.items():
2121
if any(key.startswith(x) for x in cls.FIELDS_TO_MUTATE):
22-
user_request_spec[key] = [
23-
cls.BASE_FEATURE_CRITERIA if isinstance(v, bool) else v for v in val
24-
]
22+
user_request_spec[key] = [cls.BASE_FEATURE_CRITERIA if isinstance(v, bool) else v for v in val]
2523

2624
@accepts(query_string=False)
2725
@returns(FeatureResultSet)

0 commit comments

Comments
 (0)