Skip to content

JNUC2019 Lab Session C Connecting

Chris Lasell edited this page Oct 31, 2019 · 7 revisions

Hands On, Real-time Classic API Using ruby-jss

(Home)

Lab Session Contents - 2 - IRB and Connecting to the JSS

Previous           TOC           Next


Jumping into IRB

  • Switch to terminal window
  • Run irb
% irb
irb(main):001:0>

A little about irb

  • 'irb' stands for interactive ruby, a real-time 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 #, so irb 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 returns false, it just means 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.

  • In this lab, lots of ruby commands we'll paste into irb will end with ;0

    • This makes the irb responses even easier to read - the return value of the line of code is just 0
    • When writing scripts there's no need to do it

Connecting to the Classic API

JSS.api.connect server: 'tryitout.jamfcloud.com', user: 'jnuc2019', pw: :prompt

# Enter the password for JSS user [email protected]:
# => "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, passing in 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

Previous           TOC           Next

Clone this wiki locally