Skip to content

Legato and IRB

Tony Pitale edited this page Jan 8, 2014 · 1 revision

Legato provides a CLI to start an IRB session and give access to a legato_user.

To start, simply run legato. If you haven't configured ~/.legato.yml with your OAuth2 ID and Secret, you'll be prompted to enter them.

Next, you'll be presented with an authorization url to open in a browser. After giving permission in Google, you'll be redirected to http://localhost/?code=********. Copy what follows code= and paste it at the prompt.

Finally, you'll be given dump of the YAML you could save inside of ~/.legato.yml. Be careful, the value for the token will expire relatively soon (maybe 30 minutes), and you'll have to complete the last portion of the process again.

And now, you're in an irb session. You have access to a legato_user which lets you do things like:

require 'pp' # just so we can pretty-print things

legato_user.profiles.each {|profile| puts [profile.id, profile.name].join(': ')}
profile = legato_user.profiles.detect {|profile| profile.id = 12345}

class Visitors
  extend Legato::Model

  metrics :visitors, :goal_1_completions
  dimensions :pagePath
end

pp Visitors.results(profile).to_a
Clone this wiki locally