Skip to content

Commit 195d6b0

Browse files
committed
Simplified configuration of analytics client to be consistent
1 parent 2632849 commit 195d6b0

File tree

7 files changed

+62
-92
lines changed

7 files changed

+62
-92
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
1.4.3 (2019-10-21)
2+
3+
- Simplified configuration of analytics client to be consistent
4+
15
1.4.2 (2019-10-04)
26

37
- added new asset type

planet/api/__version__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
__version__ = '1.4.2'
1+
__version__ = '1.4.3'

planet/api/client.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -369,14 +369,14 @@ def check_analytics_connection(self):
369369
to test environments.
370370
:returns: :py:Class:`planet.api.models.JSON`
371371
'''
372-
return self._get(self._url('health')).get_body()
372+
return self._get(self._url('analytics/health')).get_body()
373373

374374
def wfs_conformance(self):
375375
'''
376376
Details about WFS3 conformance
377377
:returns: :py:Class:`planet.api.models.JSON`
378378
'''
379-
return self._get(self._url('conformance')).get_body()
379+
return self._get(self._url('analytics/conformance')).get_body()
380380

381381
def list_analytic_subscriptions(self, feed_id):
382382
'''
@@ -387,7 +387,7 @@ def list_analytic_subscriptions(self, feed_id):
387387
:returns: :py:Class:`planet.api.models.Subscriptions`
388388
'''
389389
params = {'feedID': feed_id}
390-
url = self._url('subscriptions')
390+
url = self._url('analytics/subscriptions')
391391
return self._get(url, models.Subscriptions, params=params).get_body()
392392

393393
def get_subscription_info(self, subscription_id):
@@ -397,7 +397,7 @@ def get_subscription_info(self, subscription_id):
397397
:raises planet.api.exceptions.APIException: On API error.
398398
:returns: :py:Class:`planet.api.models.JSON`
399399
'''
400-
url = self._url('subscriptions/{}'.format(subscription_id))
400+
url = self._url('analytics/subscriptions/{}'.format(subscription_id))
401401
return self._get(url, models.JSON).get_body()
402402

403403
def list_analytic_feeds(self, stats):
@@ -407,7 +407,7 @@ def list_analytic_feeds(self, stats):
407407
:returns: :py:Class:`planet.api.models.Feeds`
408408
'''
409409
params = {'stats': stats}
410-
url = self._url('feeds')
410+
url = self._url('analytics/feeds')
411411
return self._get(url, models.Feeds, params=params).get_body()
412412

413413
def get_feed_info(self, feed_id):
@@ -417,7 +417,7 @@ def get_feed_info(self, feed_id):
417417
:raises planet.api.exceptions.APIException: On API error.
418418
:returns: :py:Class:`planet.api.models.JSON`
419419
'''
420-
url = self._url('feeds/{}'.format(feed_id))
420+
url = self._url('analytics/feeds/{}'.format(feed_id))
421421
return self._get(url, models.JSON).get_body()
422422

423423
def list_analytic_collections(self):
@@ -427,7 +427,7 @@ def list_analytic_collections(self):
427427
:returns: :py:Class:`planet.api.models.WFS3Collections`
428428
'''
429429
params = {}
430-
url = self._url('collections')
430+
url = self._url('analytics/collections')
431431
return self._get(url, models.WFS3Collections,
432432
params=params).get_body()
433433

@@ -438,7 +438,7 @@ def get_collection_info(self, subscription_id):
438438
:raises planet.api.exceptions.APIException: On API error.
439439
:returns: :py:Class:`planet.api.models.JSON`
440440
'''
441-
url = 'collections/{}'.format(subscription_id)
441+
url = 'analytics/collections/{}'.format(subscription_id)
442442
return self._get(self._url(url), models.JSON).get_body()
443443

444444
def list_collection_features(self,
@@ -469,7 +469,8 @@ def list_collection_features(self,
469469
if after:
470470
params['after'] = after
471471

472-
url = self._url('collections/{}/items'.format(subscription_id))
472+
url = self._url('analytics/collections/{}/items'.format(
473+
subscription_id))
473474
return self._get(url, models.WFS3Features, params=params).get_body()
474475

475476
def get_associated_resource_for_analytic_feature(self,
@@ -490,9 +491,8 @@ def get_associated_resource_for_analytic_feature(self,
490491
:py:Class:`planet.api.models.Body` of the resource.
491492
'''
492493
url = self._url(
493-
'collections/{}/items/{}/resources/{}'.format(subscription_id,
494-
feature_id,
495-
resource_type))
494+
'analytics/collections/{}/items/{}/resources/{}'.format(
495+
subscription_id, feature_id, resource_type))
496496
response = self._get(url).get_body()
497497
return response
498498

planet/scripts/cli.py

Lines changed: 1 addition & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,22 +25,9 @@
2525

2626

2727
def clientv1():
28-
client_params.pop('analytics_base_url', None)
2928
return api.ClientV1(**client_params)
3029

3130

32-
def analytics_client_v1():
33-
# Non-default analytics base URL doesn't have the analytics postfix
34-
params = dict(**client_params)
35-
if client_params.get('analytics_base_url') is not None:
36-
params['base_url'] = params.pop('analytics_base_url')
37-
else:
38-
params['base_url'] = 'https://api.planet.com/analytics/'
39-
40-
client = api.ClientV1(**params)
41-
return client
42-
43-
4431
def configure_logging(verbosity):
4532
'''configure logging via verbosity level of between 0 and 2 corresponding
4633
to log levels warning, info and debug respectfully.'''
@@ -75,13 +62,8 @@ def configure_logging(verbosity):
7562
@click.option('-u', '--base-url', envvar='PL_API_BASE_URL',
7663
help='Change the base Planet API URL or ENV PL_API_BASE_URL'
7764
' - Default https://api.planet.com/')
78-
@click.option('-au', '--analytics-base-url',
79-
envvar='PL_ANALYTICS_API_BASE_URL',
80-
help=('Change the base Planet API URL or ENV '
81-
'PL_ANALYTICS_API_BASE_URL'
82-
' - Default https://api.planet.com/analytics'))
8365
@click.version_option(version=__version__, message='%(version)s')
84-
def cli(context, verbose, api_key, base_url, analytics_base_url, workers):
66+
def cli(context, verbose, api_key, base_url, workers):
8567
'''Planet API Client'''
8668

8769
configure_logging(verbose)
@@ -91,8 +73,6 @@ def cli(context, verbose, api_key, base_url, analytics_base_url, workers):
9173
client_params['workers'] = workers
9274
if base_url:
9375
client_params['base_url'] = base_url
94-
if analytics_base_url:
95-
client_params['analytics_base_url'] = analytics_base_url
9676

9777

9878
@cli.command('help')

planet/scripts/v1.py

Lines changed: 23 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from .cli import (
1919
cli,
2020
clientv1,
21-
analytics_client_v1
2221
)
2322
from .opts import (
2423
asset_type_option,
@@ -364,7 +363,7 @@ def analytics():
364363
@pretty
365364
def health(pretty):
366365
'''Check that we can connect to the API'''
367-
cl = analytics_client_v1()
366+
cl = clientv1()
368367
click.echo('Using base URL: {}'.format(cl.base_url))
369368
response = cl.check_analytics_connection()
370369
echo_json_response(response, pretty)
@@ -378,7 +377,7 @@ def conformance(pretty):
378377
:param pretty:
379378
:return:
380379
'''
381-
cl = analytics_client_v1()
380+
cl = clientv1()
382381
response = cl.wfs_conformance()
383382
echo_json_response(response, pretty)
384383

@@ -396,7 +395,7 @@ def feeds():
396395
@pretty
397396
def list_feeds(pretty, limit, stats):
398397
'''List all subscriptions user has access to.'''
399-
cl = analytics_client_v1()
398+
cl = clientv1()
400399
response = cl.list_analytic_feeds(stats)
401400
echo_json_response(response, pretty, limit)
402401

@@ -405,8 +404,8 @@ def list_feeds(pretty, limit, stats):
405404
@click.argument('feed_id')
406405
def get_mosaic_list_for_feed(feed_id):
407406
'''List mosaics linked to feed'''
408-
analytics_client = analytics_client_v1()
409-
feed_info = analytics_client.get_feed_info(feed_id).get()
407+
cl = clientv1()
408+
feed_info = cl.get_feed_info(feed_id).get()
410409

411410
for type_ in ['target', 'source']:
412411
feed_image_conf = feed_info.get(type_)
@@ -418,8 +417,7 @@ def get_mosaic_list_for_feed(feed_id):
418417

419418
mosaic_series = feed_image_conf['config']['series_id']
420419

421-
client = clientv1()
422-
mosaics = client.get_mosaics_for_series(mosaic_series)
420+
mosaics = cl.get_mosaics_for_series(mosaic_series)
423421

424422
click.echo('{} mosaics:'.format(type_))
425423
for mosaic in mosaics.get()['mosaics']:
@@ -431,7 +429,7 @@ def get_mosaic_list_for_feed(feed_id):
431429
@pretty
432430
def get_feed_info(feed_id, pretty):
433431
'''Get metadata for specific feed.'''
434-
cl = analytics_client_v1()
432+
cl = clientv1()
435433
feed_info = cl.get_feed_info(feed_id)
436434
echo_json_response(feed_info, pretty)
437435

@@ -450,7 +448,7 @@ def subscriptions():
450448
@pretty
451449
def list_subscriptions(pretty, limit, feed_id):
452450
'''List all subscriptions user has access to.'''
453-
cl = analytics_client_v1()
451+
cl = clientv1()
454452
response = cl.list_analytic_subscriptions(feed_id)
455453
echo_json_response(response, pretty, limit)
456454

@@ -459,9 +457,9 @@ def list_subscriptions(pretty, limit, feed_id):
459457
@click.argument('subscription_id')
460458
def get_mosaic_list_for_subscription(subscription_id):
461459
'''List mosaics linked to feed'''
462-
analytics_client = analytics_client_v1()
463-
sub_info = analytics_client.get_subscription_info(subscription_id).get()
464-
feed_info = analytics_client.get_feed_info(sub_info['feedID']).get()
460+
cl = clientv1()
461+
sub_info = cl.get_subscription_info(subscription_id).get()
462+
feed_info = cl.get_feed_info(sub_info['feedID']).get()
465463

466464
for type_ in ['target', 'source']:
467465
feed_image_conf = feed_info.get(type_)
@@ -473,8 +471,7 @@ def get_mosaic_list_for_subscription(subscription_id):
473471

474472
mosaic_series = feed_image_conf['config']['series_id']
475473

476-
client = clientv1()
477-
mosaics = client.get_mosaics_for_series(mosaic_series)
474+
mosaics = cl.get_mosaics_for_series(mosaic_series)
478475

479476
click.echo('{} mosaics:'.format(type_))
480477
for mosaic in mosaics.get()['mosaics']:
@@ -486,7 +483,7 @@ def get_mosaic_list_for_subscription(subscription_id):
486483
@pretty
487484
def get_subscription_info(subscription_id, pretty):
488485
'''Get metadata for specific subscription.'''
489-
cl = analytics_client_v1()
486+
cl = clientv1()
490487
sub_info = cl.get_subscription_info(subscription_id)
491488
echo_json_response(sub_info, pretty)
492489

@@ -502,7 +499,7 @@ def collections():
502499
@pretty
503500
def list_collections(pretty, limit):
504501
'''List all collections user has access to.'''
505-
cl = analytics_client_v1()
502+
cl = clientv1()
506503
response = cl.list_analytic_collections()
507504
echo_json_response(response, pretty, limit)
508505

@@ -511,9 +508,9 @@ def list_collections(pretty, limit):
511508
@click.argument('subscription_id')
512509
def get_mosaic_list_for_collection(subscription_id):
513510
'''List mosaics linked to feed'''
514-
analytics_client = analytics_client_v1()
515-
sub_info = analytics_client.get_subscription_info(subscription_id).get()
516-
feed_info = analytics_client.get_feed_info(sub_info['feedID']).get()
511+
cl = clientv1()
512+
sub_info = cl.get_subscription_info(subscription_id).get()
513+
feed_info = cl.get_feed_info(sub_info['feedID']).get()
517514

518515
for type_ in ['target', 'source']:
519516
feed_image_conf = feed_info.get(type_)
@@ -525,8 +522,7 @@ def get_mosaic_list_for_collection(subscription_id):
525522

526523
mosaic_series = feed_image_conf['config']['series_id']
527524

528-
client = clientv1()
529-
mosaics = client.get_mosaics_for_series(mosaic_series)
525+
mosaics = cl.get_mosaics_for_series(mosaic_series)
530526

531527
click.echo('{} mosaics:'.format(type_))
532528
for mosaic in mosaics.get()['mosaics']:
@@ -538,7 +534,7 @@ def get_mosaic_list_for_collection(subscription_id):
538534
@pretty
539535
def get_collection_info(subscription_id, pretty):
540536
'''Get metadata for specific collection.'''
541-
cl = analytics_client_v1()
537+
cl = clientv1()
542538
sub_info = cl.get_collection_info(subscription_id)
543539
echo_json_response(sub_info, pretty)
544540

@@ -548,7 +544,7 @@ def get_collection_info(subscription_id, pretty):
548544
@pretty
549545
def get_resource_types(subscription_id, pretty):
550546
'''Get available resource types.'''
551-
cl = analytics_client_v1()
547+
cl = clientv1()
552548
# Assumes that all features in a collection have the same list of
553549
# associated resource types
554550
features = cl.list_collection_features(subscription_id,
@@ -601,7 +597,7 @@ def features():
601597
def list_features(subscription_id, pretty, limit, rbox, bbox, time_range,
602598
before, after):
603599
'''Request feature list for a particular subscription, 100 at a time.'''
604-
cl = analytics_client_v1()
600+
cl = clientv1()
605601
bbox = bbox or rbox
606602
features = cl.list_collection_features(subscription_id, bbox, time_range,
607603
before, after)
@@ -633,7 +629,7 @@ def list_features(subscription_id, pretty, limit, rbox, bbox, time_range,
633629
def list_features_all(subscription_id, pretty, rbox, bbox, time_range, before,
634630
after):
635631
'''Return every available feature for a particular subscription'''
636-
cl = analytics_client_v1()
632+
cl = clientv1()
637633
bbox = bbox or rbox
638634
features = cl.list_collection_features(subscription_id, bbox, time_range,
639635
before, after)
@@ -653,10 +649,7 @@ def list_features_all(subscription_id, pretty, rbox, bbox, time_range, before,
653649
def get_associated_resource(subscription_id, feature_id, resource_type, pretty,
654650
dest):
655651
'''Request resources for a particular subscription/feature combination.'''
656-
# Note that this command will not work for a custom analytics URL, as the
657-
# underlying API call is a redirect to the Data API and Mosaics API.
658-
# See https://github.com/kennethreitz/requests/issues/2949 for more info.
659-
cl = analytics_client_v1()
652+
cl = clientv1()
660653
if resource_type in ['target-quad', 'source-quad']:
661654
msg_format = 'Requesting {} for {}/{}, destination directory is: {}'
662655
click.echo(msg_format.format(

0 commit comments

Comments
 (0)