Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
jgorset committed Jan 17, 2012
0 parents commit 77460ab
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*.gem
.bundle
Gemfile.lock
pkg/*
4 changes: 4 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
source "http://rubygems.org"

# Specify your gem's dependencies in git.io.gemspec
gemspec
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Git.io

Command-line client for GitHub's URL shortener.

## Usage

$ git.io http://github.com/jgorset/git.io
http://git.io/J6MbsQ
1 change: 1 addition & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require "bundler/gem_tasks"
1 change: 1 addition & 0 deletions bin/git.io
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#!/usr/bin/env ruby
24 changes: 24 additions & 0 deletions git.io.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
require "gitio/version"

Gem::Specification.new do |s|
s.name = "git.io"
s.version = Git.io::VERSION
s.authors = ["Johannes Gorset"]
s.email = ["[email protected]"]
s.homepage = ""
s.summary = "Command-line client for GitHub's URL shortener"
s.description = "Command-line client for GitHub's URL shortener"

s.rubyforge_project = "git.io"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]

# specify any dependencies here; for example:
# s.add_development_dependency "rspec"
# s.add_runtime_dependency "rest-client"
end
28 changes: 28 additions & 0 deletions lib/gitio.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require "net/http"
require "gitio/version"

module Gitio

def self.shorten(url)
Net::HTTP.start "git.io", 80 do |http|
request = Net::HTTP::Post.new "/"
request.content_type = "application/x-www-form-urlencoded"
request.body = "url=" + url

response = http.request(request)
return response["Location"]
end
end

def self.lengthen(url)
url = URI(url)

Net::HTTP.start url.host, 80 do |http|
request = Net::HTTP::Get.new url.path

response = http.request(request)
return response["Location"]
end
end

end
3 changes: 3 additions & 0 deletions lib/gitio/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Gitio
VERSION = "0.0.1"
end
15 changes: 15 additions & 0 deletions spec/gitio_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "net/http"
require "gitio"

describe Gitio do

it "shortens and lengthens URLs" do
original_url = "http://github.com/jgorset/facepy"

short_url = Gitio.shorten(original_url)
long_url = Gitio.lengthen(short_url)

original_url.should eq long_url
end

end

0 comments on commit 77460ab

Please sign in to comment.