Add 'apps/arv-web/' from commit 'f9732ad8460d013c2f28363655d0d1b91894dca5'
[arvados.git] / doc / sdk / ruby / index.html.textile.liquid
1 ---
2 layout: default
3 navsection: sdk
4 navmenu: Ruby
5 title: "Ruby SDK"
6
7 ...
8
9 The Ruby SDK provides a generic set of wrappers so you can make API calls easily.
10
11 h3. Installation
12
13 If you are logged in to an Arvados VM, the Ruby SDK should be installed.
14
15 To use it elsewhere, you can either install the @arvados@ gem via RubyGems or build and install the package using the arvados source tree.
16
17 h4. Prerequisites: Ruby >= 2.0.0
18
19 You can use "RVM":http://rvm.io/rvm/install to install and manage Ruby versions.
20
21 h4. Option 1: install with RubyGems
22
23 <notextile>
24 <pre>
25 $ <code class="userinput">sudo gem install arvados</code>
26 </pre>
27 </notextile>
28
29 h4. Option 2: build and install from source
30
31 <notextile>
32 <pre>
33 $ <code class="userinput">git clone https://github.com/curoverse/arvados.git</code>
34 $ <code class="userinput">cd arvados/sdk/ruby</code>
35 $ <code class="userinput">gem build arvados.gemspec</code>
36 $ <code class="userinput">sudo gem install arvados-*.gem</code>
37 </pre>
38 </notextile>
39
40 h4. Test installation
41
42 If the SDK is installed, @ruby -r arvados -e 'puts "OK!"'@ should produce no errors.
43
44 If your @ARVADOS_API_HOST@ and @ARVADOS_API_TOKEN@ environment variables are set up correctly (see "api-tokens":{{site.baseurl}}/user/reference/api-tokens.html for details), the following test script should work:
45
46 <notextile>
47 <pre>$ <code class="userinput">ruby -r arvados &lt;&lt;'EOF'
48 arv = Arvados.new api_version: 'v1'
49 my_full_name = arv.user.current[:full_name]
50 puts "arvados.v1.users.current.full_name = '#{my_full_name}'"
51 EOF</code>
52 arvados.v1.users.current.full_name = 'Your Name'
53 </pre>
54 </notextile>
55
56 h3. Examples
57
58 Import the module (we skipped this step above by using "ruby -r arvados"):
59
60 <notextile>
61 <pre><code class="userinput">require 'arvados'
62 </code></pre>
63 </notextile>
64
65 Set up an API client user agent:
66
67 <notextile>
68 <pre><code class="userinput">arv = Arvados.new(apiVersion: 'v1')
69 </code></pre>
70 </notextile>
71
72 Get the User object for the current user:
73
74 <notextile>
75 <pre><code class="userinput">current_user = arv.user.current
76 </code></pre>
77 </notextile>
78
79 Get the UUID of an object that was retrieved using the SDK:
80
81 <notextile>
82 <pre><code class="userinput">current_user_uuid = current_user[:uuid]
83 </code></pre>
84 </notextile>
85
86 Retrieve an object by ID:
87
88 <notextile>
89 <pre><code class="userinput">some_user = arv.user.get(uuid: current_user_uuid)
90 </code></pre>
91 </notextile>
92
93 Create an object:
94
95 <notextile>
96 <pre><code class="userinput">new_link = arv.link.create(link: {link_class: 'test', name: 'test'})
97 </code></pre>
98 </notextile>
99
100 Update an object:
101
102 <notextile>
103 <pre><code class="userinput">updated_link = arv.link.update(uuid: new_link[:uuid],
104                                link: {properties: {foo: 'bar'}})
105 </code></pre>
106 </notextile>
107
108 Delete an object:
109
110 <notextile>
111 <pre><code class="userinput">arv.link.delete(uuid: new_link[:uuid])
112 </code></pre>
113 </notextile>
114
115 Get a list of objects:
116
117 <notextile>
118 <pre><code class="userinput">repos = arv.repository.list
119 first_repo = repos[:items][0]
120 puts "UUID of first repo returned is #{first_repo[:uuid]}"</code>
121 UUID of first repo returned is qr1hi-s0uqq-b1bnybpx3u5temz
122 </pre>
123 </notextile>
124
125 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.