-
Notifications
You must be signed in to change notification settings - Fork 30
JNUC2019 Lab Session C Connecting
- Switch to Terminal window
- run
irb
% irb
irb(main):001:0>
A little about irb
-
irb
stands for Interactive Ruby, a realtime ruby interpreter- you can type ruby code into it - just like you type bash code into a shell.
-
Enter a line of ruby code, it runs and displays the 'return value' after a
=>
-
For clarity & easier copy-pasting, in this document:
- the irb examples will use no prompt
- example output will start with a
#
, soirb
will ignore it if you paste it in. - WARNING: Don't copy/paste lines where you need to create a new uniq name, or use one you created earlier
require ruby-jss
- In irb, tell ruby that you want to use ruby-jss:
require 'ruby-jss'
# => true
-
Don't worry if you ever
require
returnsfalse
- the thing has already been required. -
Ruby is now aware of a module called
JSS
which contains all of the ruby-jss. -
While we're requiring, lets do this
require 'pp'
# => true
-
'Pretty Print' allows us to examine ruby objects in irb in a more readable format.
-
Lots of these ruby commands will end with
;0
- Makes the irb responses even easier to read.
- When writing scripts there's no need to do it.
JSS.api.connect server: 'tryitout.jamfcloud.com', user: 'jnuc2019', pw: :prompt
# Enter the password for JSS user jnuc2019@tryitout.jamfcloud.com:
# => "tryitout.jamfcloud.com"
- enter anything you'd like for the password
Here's what we did:
-
The JSS module has a method (function)
api
that returns the default APIConnection -
The APIConnection has a method
connect
that takes the parameters needed to connect to the server -
We call that method with the server name, user name, and we tell it to prompt us for the password
- If you know the password, you can pass it directly, in quotes. Just beware of security issues.
-
If the password is correct, the connection is made, and the
connect
method returns the server name.