git.io 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +9 -0
- data/git.io.gemspec +1 -0
- data/lib/gitio.rb +11 -5
- data/lib/gitio/cli.rb +4 -1
- data/lib/gitio/version.rb +1 -1
- data/spec/cli_spec.rb +11 -6
- data/spec/support.rb +7 -0
- metadata +18 -4
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -1,8 +1,17 @@
|
|
1
1
|
# Git.io
|
2
2
|
|
3
|
+
[![Build Status](https://secure.travis-ci.org/jgorset/git.io.png)](http://travis-ci.org/jgorset/git.io)
|
4
|
+
|
3
5
|
Command-line client for GitHub's URL shortener.
|
4
6
|
|
5
7
|
## Usage
|
6
8
|
|
7
9
|
$ git.io http://github.com/jgorset/git.io
|
8
10
|
http://git.io/J6MbsQ
|
11
|
+
|
12
|
+
$ git.io http://github.com/jgorset/git.io --code=git.io
|
13
|
+
http://git.io/git.io
|
14
|
+
|
15
|
+
## Installation
|
16
|
+
|
17
|
+
$ gem install git.io
|
data/git.io.gemspec
CHANGED
data/lib/gitio.rb
CHANGED
@@ -6,28 +6,34 @@ module Gitio
|
|
6
6
|
autoload :Error, "gitio/errors"
|
7
7
|
autoload :CLI, "gitio/cli"
|
8
8
|
|
9
|
+
# Shorten the given <tt>url</tt> with git.io.
|
10
|
+
#
|
11
|
+
# If <tt>code</tt> is given, git.io will attempt
|
12
|
+
# to use it in place of a random value for the
|
13
|
+
# shortened URL.
|
9
14
|
def self.shorten(url, code=nil)
|
10
15
|
Net::HTTP.start "git.io", 80 do |http|
|
11
16
|
request = Net::HTTP::Post.new "/"
|
12
17
|
request.content_type = "application/x-www-form-urlencoded"
|
13
18
|
|
14
|
-
query =
|
15
|
-
|
16
|
-
|
19
|
+
query = Hash.new.tap do |h|
|
20
|
+
h[:url] = url
|
21
|
+
h[:code] = code if code
|
17
22
|
end
|
18
23
|
|
19
24
|
request.body = URI.encode_www_form(query)
|
20
25
|
|
21
26
|
response = http.request(request)
|
22
27
|
|
23
|
-
if
|
24
|
-
return
|
28
|
+
if response.key? "Location"
|
29
|
+
return response["Location"]
|
25
30
|
else
|
26
31
|
raise Error, response.body
|
27
32
|
end
|
28
33
|
end
|
29
34
|
end
|
30
35
|
|
36
|
+
# Expand the given <tt>url</tt> to its original form.
|
31
37
|
def self.lengthen(url)
|
32
38
|
url = URI(url)
|
33
39
|
|
data/lib/gitio/cli.rb
CHANGED
@@ -7,7 +7,7 @@ module Gitio
|
|
7
7
|
def initialize(arguments)
|
8
8
|
url, options = parse!(arguments)
|
9
9
|
|
10
|
-
if options
|
10
|
+
if options.include? :code
|
11
11
|
puts Gitio.shorten(url, options[:code])
|
12
12
|
else
|
13
13
|
puts Gitio.shorten(url)
|
@@ -36,8 +36,11 @@ module Gitio
|
|
36
36
|
error "You must specify an URL to shorten" if arguments.empty?
|
37
37
|
|
38
38
|
[arguments.first, options]
|
39
|
+
rescue OptionParser::InvalidOption => e
|
40
|
+
error e
|
39
41
|
end
|
40
42
|
|
43
|
+
# Print <tt>message</tt> and exit with the given <tt>code</tt>.
|
41
44
|
def error(message, code=1)
|
42
45
|
puts "git.io: #{message}"
|
43
46
|
exit code
|
data/lib/gitio/version.rb
CHANGED
data/spec/cli_spec.rb
CHANGED
@@ -1,17 +1,22 @@
|
|
1
1
|
require "gitio"
|
2
|
+
require "support"
|
2
3
|
|
3
4
|
describe Gitio::CLI do
|
4
|
-
|
5
|
-
before do
|
6
|
-
$stdout = StringIO.new
|
7
|
-
end
|
8
5
|
|
9
6
|
it "accepts an URL" do
|
10
|
-
|
7
|
+
output = capture_stdout do
|
8
|
+
Gitio::CLI.new ["https://github.com/jgorset/git.io"]
|
9
|
+
end
|
10
|
+
|
11
|
+
output.should eq "http://git.io/git.io\n"
|
11
12
|
end
|
12
13
|
|
13
14
|
it "accepts an URL with a code" do
|
14
|
-
|
15
|
+
output = capture_stdout do
|
16
|
+
Gitio::CLI.new ["https://github.com/jgorset/git.io", "git.io"]
|
17
|
+
end
|
18
|
+
|
19
|
+
output.should eq "http://git.io/git.io\n"
|
15
20
|
end
|
16
21
|
|
17
22
|
end
|
data/spec/support.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: git.io
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-23 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &70281193489480 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,18 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70281193489480
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: rake
|
27
|
+
requirement: &70281193488180 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :development
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *70281193488180
|
25
36
|
description: Command-line client for GitHub's URL shortener, git.io.
|
26
37
|
email:
|
27
38
|
- jgorset@gmail.com
|
@@ -31,6 +42,7 @@ extensions: []
|
|
31
42
|
extra_rdoc_files: []
|
32
43
|
files:
|
33
44
|
- .gitignore
|
45
|
+
- .travis.yml
|
34
46
|
- Gemfile
|
35
47
|
- README.md
|
36
48
|
- Rakefile
|
@@ -42,6 +54,7 @@ files:
|
|
42
54
|
- lib/gitio/version.rb
|
43
55
|
- spec/cli_spec.rb
|
44
56
|
- spec/gitio_spec.rb
|
57
|
+
- spec/support.rb
|
45
58
|
homepage: http://github.com/jgorset/git.io
|
46
59
|
licenses: []
|
47
60
|
post_install_message:
|
@@ -69,3 +82,4 @@ summary: Command-line client for git.io
|
|
69
82
|
test_files:
|
70
83
|
- spec/cli_spec.rb
|
71
84
|
- spec/gitio_spec.rb
|
85
|
+
- spec/support.rb
|