Skip to content

Commit 87f9dab

Browse files
Merge pull request #519 from planetlabs/update-requesting-orders-366
Update requesting orders
2 parents 7852644 + 12a0104 commit 87f9dab

File tree

3 files changed

+361
-107
lines changed

3 files changed

+361
-107
lines changed

README.md

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,25 +60,33 @@ The email address and password you use should be the same as your login to
6060
[Planet Explorer](https://planet.com/explorer). The `auth init` command
6161
will automatically get your API key and store it locally.
6262

63-
Now that you're initialized let's start with creating an order with the
63+
Now that you're initialized let's start with creating an order request with the
6464
Orders API:
6565

6666
```console
67-
$ planet orders create --name my-first-order --id <scene-ids> \
68-
--item-type PSScene --bundle visual
67+
$ planet orders request --name my-first-order --id <scene-ids> \
68+
--item-type PSScene --bundle visual > my_order.json
6969
```
7070

7171
You should supply a unique name after `--name` for each new order, to help
72-
you identify what oder. The `--id` is one or more scene ids (separated by
72+
you identify the order. The `--id` is one or more scene ids (separated by
7373
commas). These can be obtained from the data API, and you can also grab them
7474
from any search in Planet Explorer. Just be sure the scene id matches the
7575
[item-type](https://developers.planet.com/docs/apis/data/items-assets/#item-types)
7676
to get the right type of image. And then be sure to specify a
7777
[bundle](https://developers.planet.com/docs/orders/product-bundles-reference/).
7878
The most common ones are `visual` and `analytic`.
7979

80+
Next, you may create an order with the Orders API:
81+
```console
82+
$ planet orders create my_order.json
83+
```
8084
This will give you an order response JSON as shown in the 'example response' in
81-
[the Order API docs](https://developers.planet.com/docs/orders/ordering/#basic-ordering).
85+
[the Order API docs](https://developers.planet.com/docs/orders/ordering/#basic-ordering). You may also pipe the `request` command to the `create` command to avoid the creation of a request.json file:
86+
```console
87+
$ planet orders request -name my-first-order --id <scene-ids> \
88+
--item-type PSScene --bundle visual | planet orders create -
89+
```
8290
You can grab the `id` from that response, which will look something like
8391
`dfdf3088-73a2-478c-a8f6-1bad1c09fa09`. You can then use that order-id in a
8492
single command to wait for the order and download it when you are ready:

planet/cli/orders.py

Lines changed: 68 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -247,36 +247,53 @@ def read_file_json(ctx, param, value):
247247
@click.pass_context
248248
@translate_exceptions
249249
@coro
250-
@click.option('--name', required=True)
251-
@click.option('--id',
252-
'ids',
253-
help='One or more comma-separated item IDs',
254-
type=click.STRING,
255-
callback=split_list_arg,
256-
required=True)
257-
# @click.option('--ids_from_search',
258-
# help='Embedded data search')
250+
@click.argument("request", default="-", required=False)
251+
@pretty
252+
async def create(ctx, request: str, pretty):
253+
''' Create an order.
254+
255+
This command creates an order from an order request.
256+
It outputs the created order description, optionally pretty-printed.
257+
258+
Arguments:
259+
260+
Order request as stdin, str, or file name. Full description of order
261+
to be created.
262+
'''
263+
request_json = json.load(click.open_file(request))
264+
265+
async with orders_client(ctx) as cl:
266+
order = await cl.create_order(request_json)
267+
268+
echo_json(order, pretty)
269+
270+
271+
@orders.command()
272+
@click.pass_context
273+
@translate_exceptions
274+
@coro
275+
@click.option('--name',
276+
required=True,
277+
help='Order name. Does not need to be unique.',
278+
type=click.STRING)
259279
@click.option(
260280
'--bundle',
261281
multiple=False,
262282
required=True,
263-
help='Specify bundle',
283+
help='Product bundle.',
264284
type=click.Choice(planet.specs.get_product_bundles(),
265285
case_sensitive=False),
266286
)
287+
@click.option('--id',
288+
help='One or more comma-separated item IDs',
289+
type=click.STRING,
290+
callback=split_list_arg,
291+
required=True)
267292
@click.option('--item-type',
268293
multiple=False,
269294
required=True,
270295
help='Specify an item type',
271296
type=click.STRING)
272-
@click.option('--email',
273-
default=False,
274-
is_flag=True,
275-
help='Send email notification when Order is complete')
276-
@click.option('--cloudconfig',
277-
help='Cloud delivery config json file.',
278-
type=click.File('rb'),
279-
callback=read_file_json)
280297
@click.option('--clip',
281298
help='Clip GeoJSON file.',
282299
type=click.File('rb'),
@@ -285,20 +302,35 @@ def read_file_json(ctx, param, value):
285302
help='Toolchain json file.',
286303
type=click.File('rb'),
287304
callback=read_file_json)
305+
@click.option('--email',
306+
default=False,
307+
is_flag=True,
308+
help='Send email notification when Order is complete')
309+
@click.option(
310+
'--cloudconfig',
311+
help='Credentials for cloud storage provider to enable cloud delivery'
312+
'of data.',
313+
type=click.File('rb'),
314+
callback=read_file_json)
288315
@pretty
289-
async def create(ctx,
290-
name,
291-
ids,
292-
bundle,
293-
item_type,
294-
email,
295-
cloudconfig,
296-
clip,
297-
tools,
298-
pretty):
299-
'''Create an order.'''
316+
async def request(ctx,
317+
name,
318+
bundle,
319+
id,
320+
clip,
321+
tools,
322+
item_type,
323+
email,
324+
cloudconfig,
325+
pretty):
326+
"""Generate an order request.
327+
328+
This command provides support for building an order description used
329+
in creating an order. It outputs the order request, optionally pretty-
330+
printed.
331+
"""
300332
try:
301-
product = planet.order_request.product(ids, bundle, item_type)
333+
product = planet.order_request.product(id, bundle, item_type)
302334
except planet.specs.SpecificationException as e:
303335
raise click.BadParameter(e)
304336

@@ -307,11 +339,6 @@ async def create(ctx,
307339
else:
308340
notifications = None
309341

310-
if cloudconfig:
311-
delivery = planet.order_request.delivery(cloud_config=cloudconfig)
312-
else:
313-
delivery = None
314-
315342
if clip and tools:
316343
raise click.BadParameter("Specify only one of '--clip' or '--tools'")
317344
elif clip:
@@ -322,13 +349,15 @@ async def create(ctx,
322349

323350
tools = [planet.order_request.clip_tool(clip)]
324351

352+
if cloudconfig:
353+
delivery = planet.order_request.delivery(cloud_config=cloudconfig)
354+
else:
355+
delivery = None
356+
325357
request = planet.order_request.build_request(name,
326358
products=[product],
327359
delivery=delivery,
328360
notifications=notifications,
329361
tools=tools)
330362

331-
async with orders_client(ctx) as cl:
332-
order = await cl.create_order(request)
333-
334-
echo_json(order, pretty)
363+
echo_json(request, pretty)

0 commit comments

Comments
 (0)