Skip to content

Instantly share code, notes, and snippets.

@michaelparenteau
Last active December 15, 2015 22:28
Show Gist options
  • Save michaelparenteau/5332755 to your computer and use it in GitHub Desktop.
Save michaelparenteau/5332755 to your computer and use it in GitHub Desktop.
A Bash script that takes an argument to fetch gem data from ruby gems.org. Stick it on your path run. The script uses a ruby gem "jazor" to parse json data, so you will need to have that installed for this to work.
#!/bin/bash
# INFO:
# This script makes a request to rubygems.org for JSON data on a gem
# It uses the ruby gem JAZOR to parse json and then we format the CL
# KEY/VALUE output.
#
# DEPENDENCIES
# Ruby, Rubygems, Bash
#
# gem install jazor
# create a temporary json file and put gem data from rubygems.org into it
touch tmp.json
curl -s http://rubygems.org/api/v1/gems/$1.json > tmp.json
# make space
echo ""
# Say if the gem doesn't exist or else give us some info
if grep -Fxq "This rubygem could not be found." tmp.json
then
echo -e "\033[31m> No gem named '$1' on rubygems.org\033[m"
else
# Print the gem info in the terminal
echo -e "\033[1;32m> Success!\033[m - Info re: \033[1;36m$1\033[m from rubygems.org"
echo "---"
# call jazor against the tmp.json file and use Ruby to do stuff with the keys:values
jazor tmp.json 'each{|key, value| next unless value.is_a?(String); puts key.capitalize+": " + value.to_s};return ""'
fi
echo ""
# REMOVE TEMPORARY JSON FILE
rm -rf tmp.json
@michaelparenteau
Copy link
Author

I just discovered gemwhois... it is way better at doing this than what I wrote above. Faster and everything. Seems like the above gives more info... but really, not everyone is adding the info so you might end up with a bunch of blank labels.

https://github.com/jnunemaker/gemwhois is just better. Thank you @jnunemaker for that.

@michaelparenteau
Copy link
Author

@ldenman is an 👼 for pairing on the jazor ruby stuffs here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment