Skip to content

Instantly share code, notes, and snippets.

@nogweii
Created July 10, 2010 22:19
Show Gist options
  • Save nogweii/471074 to your computer and use it in GitHub Desktop.
Save nogweii/471074 to your computer and use it in GitHub Desktop.
Simple CLI client for imgfave.
#!/usr/bin/ruby
# A simple CLI client to save images to imgfave.com
# It's kind of like an undocumented API but that doesn't matter so much, right?
# They've hit inertia beyond what they can easily manage. This so-called 'API'
# will be available for a good while anyways.
require 'net/http'
# 3 parameters passed.
# i: Absolute URL to the image
# u: URL of the page the image is on
# t: The title of the page.
# - Normal pages: Substitute all '|' for '/'
# - If the page is an image, use just the file name
# n: 1 if the image contains nudity. Otherwise, don't include it.
#
# API Endpoint: http://imgfave.com/add
# GET the above parameters to the endpoint
ENDPOINT="http://imgfave.com/add?"
file = ARGV[0]
if !ARGV[0] || !file =~ /\.(png|jpe?g|gif)/
warn "Need an absolute URL to a picture."
exit 1
end
parameters = {i: file, t: File.basename(file)}#, u: nil}
foo = parameters.map do |param, value|
["#{URI.escape(param.to_s)}=#{URI.escape(value.to_s)}"]
end
ENDPOINT << foo.flatten.join('&')
system("open #{ENDPOINT}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment