Merge branch '8784-dir-listings'
[arvados.git] / doc / sdk / perl / example.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Perl
5 title: "Examples"
6 ...
7 {% comment %}
8 Copyright (C) The Arvados Authors. All rights reserved.
9
10 SPDX-License-Identifier: CC-BY-SA-3.0
11 {% endcomment %}
12
13 h2. Initialize SDK
14
15 Set up an API client user agent:
16
17 <notextile>
18 <pre><code class="userinput">
19 use Arvados;
20 my $arv = Arvados->new('apiVersion' => 'v1');
21 </code></pre>
22 </notextile>
23
24 The SDK retrieves the list of API methods from the server at run time. Therefore, the set of available methods is determined by the server version rather than the SDK version.
25
26 h2. create
27
28 Create an object:
29
30 <notextile>
31 <pre><code class="userinput">my $test_link = $arv->{'links'}->{'create'}->execute('link' => { 'link_class' => 'test', 'name' => 'test' });
32 </code></pre>
33 </notextile>
34
35 h2. delete
36
37 <notextile>
38 <pre><code class="userinput">my $some_user = $arv->{'collections'}->{'get'}->execute('uuid' => $collection_uuid);
39 </code></pre>
40 </notextile>
41
42 h2. get
43
44 Retrieve an object by ID:
45
46 <notextile>
47 <pre><code class="userinput">my $some_user = $arv->{'users'}->{'get'}->execute('uuid' => $current_user_uuid);
48 </code></pre>
49 </notextile>
50
51 Get the UUID of an object that was retrieved using the SDK:
52
53 <notextile>
54 <pre><code class="userinput">my $current_user_uuid = $current_user->{'uuid'}
55 </code></pre>
56 </notextile>
57
58 h2. list
59
60 Get a list of objects:
61
62 <notextile>
63 <pre><code class="userinput">my $repos = $arv->{'repositories'}->{'list'}->execute;
64 print ("UUID of first repo returned is ", $repos->{'items'}->[0], "\n");
65 </code></pre>
66 </notextile>
67
68 h2. update
69
70 Update an object:
71
72 <notextile>
73 <pre><code class="userinput">my $test_link = $arv->{'links'}->{'update'}->execute(
74         'uuid' => $test_link->{'uuid'},
75         'link' => { 'properties' => { 'foo' => 'bar' } });
76 </code></pre>
77 </notextile>
78
79 h2. Get current user
80
81 Get the User object for the current user:
82
83 <notextile>
84 <pre><code class="userinput">my $current_user = $arv->{'users'}->{'current'}->execute;
85 </code></pre>
86 </notextile>