tiny_url 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,40 @@
1
- = tiny_url
1
+ # TinyUrl
2
2
 
3
3
  A gem for tinifying urls
4
4
 
5
- == Installation
5
+ ## Installation
6
6
 
7
- $ gem install tiny_url
7
+ `$ gem install tiny_url`
8
8
 
9
9
  Or in the Gemfile
10
10
 
11
- gem "tiny_url"
12
-
13
- == Usage
11
+ ```ruby
12
+
13
+ gem "tiny_url"
14
+
15
+ ```
16
+
17
+ ## Usage
14
18
 
15
19
  From the command-line:
16
20
 
17
- $ tiny_url http://accidentalchinesehipsters.tumblr.com/
21
+ `$ tiny_url http://accidentalchinesehipsters.tumblr.com/`
22
+
23
+ `$ tiny_url -o http://accidentalchinesehipsters.tumbler.com/` - Opens the page in the browser
18
24
 
19
25
  Anywhere else in Ruby:
20
-
21
- TinyUrl.silently_tinify "http://thereifixedit.failblog.org/"
22
26
 
23
- == Licence
27
+ ```ruby
28
+
29
+ require "tiny_url"
30
+
31
+ TinyUrl.make_request "http://thereifixedit.failblog.org/"
32
+
33
+ ```
34
+
35
+ ## Licence
24
36
 
25
- Copyright 2011 Rodrigo Vieira. http://www.rodrigoalvesvieira.com
37
+ Copyright 2011-2012 Rodrigo Alves Vieira. http://www.rodrigoalvesvieira.com
26
38
 
27
39
  Permission is hereby granted, free of charge, to any person obtaining
28
40
  a copy of this software and associated documentation files (the
data/Rakefile CHANGED
@@ -1,15 +1,21 @@
1
- #require "bundler/gem_tasks"
2
-
3
1
  require 'rake'
4
2
  require 'rdoc/task'
5
3
  require 'fileutils'
6
4
 
7
- task :test => :spec
5
+ task test: :spec
8
6
 
9
- task :default => :spec
7
+ task default: :spec
10
8
 
11
9
  require "rspec/core/rake_task"
12
10
  RSpec::Core::RakeTask.new(:spec) do |t|
13
11
  t.rspec_opts = '--backtrace --color'
14
12
  end
15
13
 
14
+ desc 'Generate documentation for TinyUrl.'
15
+ Rake::RDocTask.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'TinyUrl'
18
+ rdoc.options << '--line-numbers' << '--inline-source'
19
+ rdoc.rdoc_files.include('README.md')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
data/bin/tiny_url CHANGED
@@ -1,10 +1,12 @@
1
1
  #!/usr/bin/env ruby
2
-
3
2
  $:.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
4
3
 
4
+ require 'tiny_url'
5
+
6
+ if(ARGV.empty? || ["-h","--help"].include?(ARGV.first))
5
7
  help = <<HELP
6
8
 
7
- NAME
9
+ TinyURL Ruby CLI
8
10
 
9
11
  A command line tool for tinifying urls
10
12
 
@@ -13,22 +15,20 @@ BASIC USAGE
13
15
  tiny_url [OPTIONS].. [URL]
14
16
 
15
17
  OPTIONS:
16
- --open
17
- -o # Opens the web site in the browser immediately after getting the tiny url.
18
-
18
+ [-o/--open] # Opens the web site in the browser immediately after getting the tiny url.
19
+ [-c/--copy] # Copy the shortened tiny url to your clipboard
20
+ [-h/--help] # Show this help message and quit
21
+
19
22
  EXAMPLES:
20
23
 
21
- tiny_url http://accidentalchinesehipsters.tumblr.com/ # Returns the tinified version of the url, copies it to the clipboard and opens the webpage in your browser.
22
- tiny_url -o http://google.com
24
+ tiny_url http://accidentalchinesehipsters.tumblr.com/ # Returns the tinified version of the url
25
+ tiny_url -o http://google.com # Returns the tinified version of the url and open it in default browser
26
+ tiny_url -c -o http://defidelis.com # Returns the tinified version of the url , open it in browser and copy the tiny url to clipboard
23
27
 
24
28
  HELP
25
-
26
- require 'tiny_url'
27
-
28
- if ARGV.size.zero?
29
- puts help
30
- elsif ARGV[0] == "-o" || ARGV[0] == "--open"
31
- TinyUrl.tinify(ARGV[0], op="o")
29
+ puts help and exit
32
30
  else
33
- TinyUrl.tinify(ARGV[0])
31
+ open = !(["-o","--open"] & ARGV).empty?
32
+ copy = !(["-c","--copy"] & ARGV).empty?
33
+ TinyUrl.tinify(ARGV.last, open, copy)
34
34
  end
data/lib/tiny_url.rb CHANGED
@@ -1,33 +1,29 @@
1
+ # encoding: UTF-8
1
2
  require "tiny_url/version"
2
3
  require "net/http"
3
4
  require "clipboard"
4
5
 
5
6
  module TinyUrl
6
- def self.tinify(url, op=nil)
7
-
8
- uri = URI.parse "http://tinyurl.com/api-create.php?url=http://#{url}"
9
- http = Net::HTTP.new(uri.host, uri.port)
10
- request = Net::HTTP::Get.new(uri.request_uri)
11
- response = http.request(request)
12
- tiny_url = response.body
13
-
14
- Clipboard.copy tiny_url
15
-
16
- puts "Copied tiny url to clipboard!"
17
- puts "The generated tiny url is #{tiny_url}" if op.nil?
18
-
19
- if op
20
- puts "The generated tiny url is #{tiny_url}, you're gonna see the page..."
21
- sleep 1
22
- `open #{tiny_url}`
7
+ # API Base URL
8
+ BASE_URL = "http://tinyurl.com/api-create.php?url=%s"
9
+
10
+ module_function
11
+ def tinify(url, open=nil, copy_to_clipboard=true)
12
+ if tiny_url = make_request(url)
13
+ sucess_message(tiny_url, open, copy_to_clipboard)
14
+ return true
23
15
  end
16
+ puts "Something wrong..." and return false
17
+ end
18
+
19
+ def sucess_message(tiny_url,open,copy)
20
+ Clipboard.copy(tiny_url) and puts "Copied the shortened tinyurl to clipboard!" if copy
21
+ puts "The generated tiny url is #{tiny_url}"
22
+ system("open",tiny_url) if open
24
23
  end
25
-
26
- def self.silently_tinify(url)
27
- uri = URI.parse "http://tinyurl.com/api-create.php?url=http://#{url}"
28
- http = Net::HTTP.new(uri.host, uri.port)
29
- request = Net::HTTP::Get.new(uri.request_uri)
30
- response = http.request(request)
31
- tiny_url = response.body
24
+
25
+ def make_request(url)
26
+ URI.parse(url) rescue raise(ArgumentError.new("Invalid URL"))
27
+ Net::HTTP.get(URI.parse(BASE_URL % url)) rescue return false
32
28
  end
33
29
  end
@@ -1,3 +1,3 @@
1
1
  module TinyUrl
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -7,7 +7,7 @@ describe TinyUrl do
7
7
  end
8
8
 
9
9
  it "can tinify url" do
10
- url = TinyUrl.silently_tinify "google.com"
10
+ url = TinyUrl.make_request "google.com"
11
11
  url.should_not be_nil
12
12
  end
13
13
  end
data/tiny_url.gemspec CHANGED
@@ -5,9 +5,9 @@ require "tiny_url/version"
5
5
  Gem::Specification.new do |s|
6
6
  s.name = "tiny_url"
7
7
  s.version = TinyUrl::VERSION
8
- s.authors = ["Rodrigo Vieira"]
8
+ s.authors = ["Rodrigo Alves Vieira"]
9
9
  s.email = ["rodrigovieira1994@gmail.com"]
10
- s.homepage = "http://rodrigoalvesvieira.com/tiny_url"
10
+ s.homepage = "http://www.rodrigoalvesvieira.com"
11
11
  s.summary = %q{A gem for tinifying urls}
12
12
  s.description = %q{A gem for tinifying urls. With a command-line interface.}
13
13
 
metadata CHANGED
@@ -1,19 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tiny_url
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - Rodrigo Vieira
8
+ - Rodrigo Alves Vieira
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-11 00:00:00.000000000 Z
12
+ date: 2012-08-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: clipboard
16
- requirement: &70107717076440 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70107717076440
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rspec
27
- requirement: &70107717075940 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,7 +37,12 @@ dependencies:
32
37
  version: '2'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70107717075940
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '2'
36
46
  description: A gem for tinifying urls. With a command-line interface.
37
47
  email:
38
48
  - rodrigovieira1994@gmail.com
@@ -43,7 +53,7 @@ extra_rdoc_files: []
43
53
  files:
44
54
  - .gitignore
45
55
  - Gemfile
46
- - README.rdoc
56
+ - README.md
47
57
  - Rakefile
48
58
  - bin/tiny_url
49
59
  - lib/tiny_url.rb
@@ -51,7 +61,7 @@ files:
51
61
  - spec/spec_helper.rb
52
62
  - spec/tiny_url_spec.rb
53
63
  - tiny_url.gemspec
54
- homepage: http://rodrigoalvesvieira.com/tiny_url
64
+ homepage: http://www.rodrigoalvesvieira.com
55
65
  licenses: []
56
66
  post_install_message:
57
67
  rdoc_options: []
@@ -71,7 +81,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
71
81
  version: '0'
72
82
  requirements: []
73
83
  rubyforge_project: tiny_url
74
- rubygems_version: 1.8.13
84
+ rubygems_version: 1.8.23
75
85
  signing_key:
76
86
  specification_version: 3
77
87
  summary: A gem for tinifying urls