Skip to content

Instantly share code, notes, and snippets.

@mikkpr
Last active August 29, 2015 14:06
Show Gist options
  • Save mikkpr/ef2950db7de16b4c2d27 to your computer and use it in GitHub Desktop.
Save mikkpr/ef2950db7de16b4c2d27 to your computer and use it in GitHub Desktop.
ZSH function to start a Voog API session in the pry interpreter
# prerequisites:
# * installed gem 'voog_api'
# * ZSH
# * RBENV
# * existing ~/.voog file
# add to ~/.zshrc:
# returns the API token for the given Voog site
voog-token() {
grep -A 3 -e $1 ~/.voog | grep -E 'api_token=.*' | awk -F\api_token= '{print $2}'
}
# returns the hostname for the given Voog site
voog-host() {
grep -A 3 -e $1 ~/.voog | grep -E 'host=.*' | awk -F\host= '{print $2}'
}
# starts a pry session that loads the 'voog_api' gem and creates an API session with the hostname and token for the given site
voog-api-session() {
local RUBY=2.1.0
RBENV_VERSION=${RUBY} pry -e "
require 'voog_api';
client = Voog::Client.new(
'$(voog-host $1)',
'$(voog-token $1)'
)
"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment