Merge branch '15964-fix-docs' refs #15964
[arvados.git] / doc / sdk / ruby / example.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Python
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 Import the module and set up an API client user agent:
16
17 {% codeblock as ruby %}
18 require 'arvados'
19 arv = Arvados.new(apiVersion: 'v1')
20 {% endcodeblock %}
21
22 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.
23
24 h2. create
25
26 Create an object:
27
28 {% codeblock as ruby %}
29 new_link = arv.link.create(link: {link_class: 'test', name: 'test'})
30 {% endcodeblock %}
31
32 h2. delete
33
34 Delete an object:
35
36 {% codeblock as ruby %}
37 arv.link.delete(uuid: new_link[:uuid])
38 {% endcodeblock %}
39
40 h2. get
41
42 Retrieve an object by ID:
43
44 {% codeblock as ruby %}
45 some_user = arv.user.get(uuid: current_user_uuid)
46 {% endcodeblock %}
47
48 h2. list
49
50 Get a list of objects:
51
52 {% codeblock as ruby %}
53 repos = arv.repository.list
54 first_repo = repos[:items][0]
55 puts "UUID of first repo returned is #{first_repo[:uuid]}"</code>
56 {% endcodeblock %}
57
58 UUID of first repo returned is zzzzz-s0uqq-b1bnybpx3u5temz
59
60 h2. update
61
62 Update an object:
63
64 {% codeblock as ruby %}
65 updated_link = arv.link.update(uuid: new_link[:uuid],
66                                link: {properties: {foo: 'bar'}})
67 {% endcodeblock %}
68
69 h2. Get current user
70
71 Get the User object for the current user:
72
73 {% codeblock as ruby %}
74 current_user = arv.user.current
75 {% endcodeblock %}
76
77 Get the UUID of an object that was retrieved using the SDK:
78
79 {% codeblock as ruby %}
80 current_user_uuid = current_user[:uuid]
81 {% endcodeblock %}