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.
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
5
+ script: bundle exec rspec
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
@@ -20,5 +20,6 @@ Gem::Specification.new do |s|
20
20
 
21
21
  # specify any dependencies here; for example:
22
22
  s.add_development_dependency "rspec"
23
+ s.add_development_dependency "rake"
23
24
  # s.add_runtime_dependency "rest-client"
24
25
  end
@@ -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 = {}.tap do |hash|
15
- hash[:url] = url
16
- hash[:code] = code if code
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 short_url = response["Location"]
24
- return short_url
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
 
@@ -7,7 +7,7 @@ module Gitio
7
7
  def initialize(arguments)
8
8
  url, options = parse!(arguments)
9
9
 
10
- if options[:code]
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
@@ -1,3 +1,3 @@
1
1
  module Gitio
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
- Gitio::CLI.new ["http://github.com/jgorset/git.io"]
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
- Gitio::CLI.new ["http://github.com/jgorset/git.io", "git.io"]
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
@@ -0,0 +1,7 @@
1
+ def capture_stdout
2
+ $stdout = StringIO.new
3
+ yield
4
+ $stdout.string
5
+ ensure
6
+ $stdout = STDOUT
7
+ end
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.2
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-01-17 00:00:00.000000000 Z
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: &70294673264120 !ruby/object:Gem::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: *70294673264120
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