mush 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +67 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/bin/bitly +67 -0
- data/bin/isgd +40 -0
- data/bin/mush +3 -0
- data/bin/unu +40 -0
- data/lib/mush.rb +12 -0
- data/lib/mush/authenticated_service.rb +33 -0
- data/lib/mush/errors.rb +6 -0
- data/lib/mush/service.rb +37 -0
- data/lib/mush/services/bitly.rb +34 -0
- data/lib/mush/services/isgd.rb +21 -0
- data/lib/mush/services/unu.rb +20 -0
- data/mush.gemspec +65 -0
- data/test/helper.rb +11 -0
- data/test/test_mush.rb +113 -0
- metadata +104 -0
data/.document
ADDED
data/.gitignore
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2010 Rafael Magana
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
= MUSh
|
2
|
+
|
3
|
+
A multiple service URL shortener gem with command-line utilities
|
4
|
+
|
5
|
+
NOTE: This gem only supports url shortening, nothing else, no stats, no info, no expand and it won't support any of them.
|
6
|
+
|
7
|
+
== Supported services
|
8
|
+
|
9
|
+
* bit.ly
|
10
|
+
* is.gd
|
11
|
+
* u.nu
|
12
|
+
|
13
|
+
== Usage as a command line utility
|
14
|
+
|
15
|
+
$ bitly -l login -l apikey -u http://foo.raflabs.com
|
16
|
+
|
17
|
+
$ isgd http://foo.raflabs.com
|
18
|
+
|
19
|
+
$ unu foo.raflabs.com
|
20
|
+
|
21
|
+
Sorry, but at this moment, if you want to use the bitly command line without -l and -k do this:
|
22
|
+
|
23
|
+
Add the following alias to your ~/.bash_profile or ~/.bashrc
|
24
|
+
|
25
|
+
alias bitly='bitly -l your_login -k your_apikey'
|
26
|
+
|
27
|
+
then use it this way (you won't need the -u)
|
28
|
+
|
29
|
+
$ bitly http://google.com
|
30
|
+
|
31
|
+
== Usage as a Gem
|
32
|
+
|
33
|
+
require 'mush'
|
34
|
+
|
35
|
+
bitly = Mush::Services::Bitly.new
|
36
|
+
|
37
|
+
bitly.login = "login"
|
38
|
+
bitly.apikey = "apikey"
|
39
|
+
|
40
|
+
bitly.shorten "http://foo.raflabs.com"
|
41
|
+
|
42
|
+
isgd = Mush::Services::IsGd.new
|
43
|
+
isgd.shorten "http://foo.raflabs.com"
|
44
|
+
|
45
|
+
unu = Mush::Services:Unu.new
|
46
|
+
unu.shorten "http://foo.raflabs.com"
|
47
|
+
|
48
|
+
== ToDo
|
49
|
+
|
50
|
+
* Use bitly commmand without -l and -k, save config in home folder (.mush file)
|
51
|
+
* Make shorten method to accept multiple URLs
|
52
|
+
* add j.mp and maybe other services
|
53
|
+
* Cache
|
54
|
+
|
55
|
+
== Note on Patches/Pull Requests
|
56
|
+
|
57
|
+
* Fork the project.
|
58
|
+
* Make your feature/service addition or bug fix.
|
59
|
+
* Add tests for it. This is important so I don't break it in a
|
60
|
+
future version unintentionally.
|
61
|
+
* Commit, do not mess with rakefile, version, or history.
|
62
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
63
|
+
* Send me a pull request. Bonus points for topic branches.
|
64
|
+
|
65
|
+
== Copyright
|
66
|
+
|
67
|
+
Copyright (c) 2010 Rafael Magana. See LICENSE for details.
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems'
|
3
|
+
require 'rake'
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'jeweler'
|
7
|
+
Jeweler::Tasks.new do |gem|
|
8
|
+
gem.name = "mush"
|
9
|
+
gem.summary = %Q{A multiple service URL shortener gem with command-line utility}
|
10
|
+
gem.description = %Q{A gem to shorten URLs using different services, it has one command-line utility for each supported service.}
|
11
|
+
gem.email = "raf.magana@gmail.com"
|
12
|
+
gem.homepage = "http://github.com/rafmagana/mush"
|
13
|
+
gem.authors = ["Rafael Magaña"]
|
14
|
+
gem.add_development_dependency "shoulda", ">= 0"
|
15
|
+
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
20
|
+
end
|
21
|
+
|
22
|
+
require 'rake/testtask'
|
23
|
+
Rake::TestTask.new(:test) do |test|
|
24
|
+
test.libs << 'lib' << 'test'
|
25
|
+
test.pattern = 'test/**/test_*.rb'
|
26
|
+
test.verbose = true
|
27
|
+
end
|
28
|
+
|
29
|
+
begin
|
30
|
+
require 'rcov/rcovtask'
|
31
|
+
Rcov::RcovTask.new do |test|
|
32
|
+
test.libs << 'test'
|
33
|
+
test.pattern = 'test/**/test_*.rb'
|
34
|
+
test.verbose = true
|
35
|
+
end
|
36
|
+
rescue LoadError
|
37
|
+
task :rcov do
|
38
|
+
abort "RCov is not available. In order to run rcov, you must: sudo gem install spicycode-rcov"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
task :test => :check_dependencies
|
43
|
+
|
44
|
+
task :default => :test
|
45
|
+
|
46
|
+
require 'rake/rdoctask'
|
47
|
+
Rake::RDocTask.new do |rdoc|
|
48
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
49
|
+
|
50
|
+
rdoc.rdoc_dir = 'rdoc'
|
51
|
+
rdoc.title = "mush #{version}"
|
52
|
+
rdoc.rdoc_files.include('README*')
|
53
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
54
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/bin/bitly
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
STDOUT.sync = true
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
require 'mush'
|
10
|
+
|
11
|
+
ORIGINAL_ARGV = ARGV.dup
|
12
|
+
|
13
|
+
#the defaults
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
opts = OptionParser.new do |opts|
|
17
|
+
opts.banner = <<-EOF
|
18
|
+
Usage:
|
19
|
+
bitly -l login -k apikey -u url
|
20
|
+
|
21
|
+
Options:
|
22
|
+
EOF
|
23
|
+
|
24
|
+
opts.on("-lLOGIN", "--login LOGIN", "The login to access the bit.ly API") do |login|
|
25
|
+
options[:login] = login
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-kAPIKEY", "--apikey APIKEY", "API Key") do |apikey|
|
29
|
+
options[:apikey] = apikey
|
30
|
+
end
|
31
|
+
|
32
|
+
opts.on("-uURL", "--url URL", "The long URL to be shortened") do |url|
|
33
|
+
options[:url] = url
|
34
|
+
end
|
35
|
+
|
36
|
+
opts.on("-v", "--version", "Print the version number and exit") do
|
37
|
+
options[:version] = true
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
opts.parse!
|
42
|
+
|
43
|
+
if options[:version]
|
44
|
+
abort("Version " + Mush.version)
|
45
|
+
end
|
46
|
+
|
47
|
+
options[:url] = ARGV.first if ARGV.length == 1
|
48
|
+
|
49
|
+
#validate
|
50
|
+
unless options[:login]
|
51
|
+
abort("You must specify a login to access the Bit.ly API")
|
52
|
+
end
|
53
|
+
|
54
|
+
unless options[:apikey]
|
55
|
+
abort("You must specify an API Key to access the Bit.ly API")
|
56
|
+
end
|
57
|
+
|
58
|
+
unless options[:url]
|
59
|
+
abort("Please provide a valid URL, including http://")
|
60
|
+
end
|
61
|
+
|
62
|
+
bitly = Mush::Services::Bitly.new
|
63
|
+
|
64
|
+
bitly.login = options[:login]
|
65
|
+
bitly.apikey = options[:apikey]
|
66
|
+
|
67
|
+
puts bitly.shorten options[:url]
|
data/bin/isgd
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
STDOUT.sync = true
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
require 'mush'
|
10
|
+
|
11
|
+
ORIGINAL_ARGV = ARGV.dup
|
12
|
+
|
13
|
+
#the defaults
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
opts = OptionParser.new do |opts|
|
17
|
+
opts.banner = <<-EOF
|
18
|
+
Usage:
|
19
|
+
isgd url
|
20
|
+
EOF
|
21
|
+
|
22
|
+
opts.on("-v", "--version", "Print the version number and exit") do
|
23
|
+
options[:version] = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.parse!
|
28
|
+
|
29
|
+
if options[:version]
|
30
|
+
abort("Version " + Mush.version)
|
31
|
+
end
|
32
|
+
|
33
|
+
options[:url] = ARGV.first if ARGV.length == 1
|
34
|
+
|
35
|
+
# validate
|
36
|
+
unless options[:url]
|
37
|
+
abort("You must specify a URL to use the is.gd service")
|
38
|
+
end
|
39
|
+
|
40
|
+
puts Mush::Services::IsGd.new.shorten options[:url]
|
data/bin/mush
ADDED
data/bin/unu
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
STDOUT.sync = true
|
4
|
+
|
5
|
+
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), *%w[.. lib])
|
6
|
+
|
7
|
+
require 'rubygems'
|
8
|
+
require 'optparse'
|
9
|
+
require 'mush'
|
10
|
+
|
11
|
+
ORIGINAL_ARGV = ARGV.dup
|
12
|
+
|
13
|
+
#the defaults
|
14
|
+
options = {}
|
15
|
+
|
16
|
+
opts = OptionParser.new do |opts|
|
17
|
+
opts.banner = <<-EOF
|
18
|
+
Usage:
|
19
|
+
unu url
|
20
|
+
EOF
|
21
|
+
|
22
|
+
opts.on("-v", "--version", "Print the version number and exit") do
|
23
|
+
options[:version] = true
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
opts.parse!
|
28
|
+
|
29
|
+
if options[:version]
|
30
|
+
abort("Version " + Mush.version)
|
31
|
+
end
|
32
|
+
|
33
|
+
options[:url] = ARGV.first if ARGV.length == 1
|
34
|
+
|
35
|
+
# validate
|
36
|
+
unless options[:url]
|
37
|
+
abort("You must specify a URL to use the u.nu service")
|
38
|
+
end
|
39
|
+
|
40
|
+
puts Mush::Services::Unu.new.shorten options[:url]
|
data/lib/mush.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'httparty'
|
2
|
+
require 'mush/errors'
|
3
|
+
require 'mush/service'
|
4
|
+
require 'mush/authenticated_service'
|
5
|
+
|
6
|
+
Dir[File.dirname(__FILE__)+"/mush/services/*"].each { |service| require service }
|
7
|
+
|
8
|
+
module Mush
|
9
|
+
def self.version
|
10
|
+
File.read(File.join(File.dirname(__FILE__), *%w[.. VERSION]))
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module Mush
|
2
|
+
|
3
|
+
class AuthenticatedService < Service
|
4
|
+
|
5
|
+
attr_accessor :login, :apikey
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@login = ''
|
9
|
+
@apikey = ''
|
10
|
+
end
|
11
|
+
|
12
|
+
def authorize(args = {})
|
13
|
+
raise InvalidAuthorizationData.new("Invalid Authorization Data, please provide both login and apikey") unless valid_authorization_data? args
|
14
|
+
@login = options[:login]
|
15
|
+
@apikey = options[:apikey]
|
16
|
+
end
|
17
|
+
|
18
|
+
protected
|
19
|
+
def valid_authorization_data?(data)
|
20
|
+
[:login, :apikey].all? { |key| data.key? key }
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.authorizable_with(*options)
|
24
|
+
raise InvalidAuthorizationFields.new("Should provide fields to authorize with") if options.empty?
|
25
|
+
@params_to_authorize = options
|
26
|
+
class_eval do
|
27
|
+
options.each { |o| attr_accessor o.to_sym }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
data/lib/mush/errors.rb
ADDED
data/lib/mush/service.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module Mush
|
2
|
+
|
3
|
+
# This is the class all the services must inherit from.
|
4
|
+
class Service
|
5
|
+
include HTTParty
|
6
|
+
|
7
|
+
#wrapper for HTTParty.get
|
8
|
+
def get(path, options = {})
|
9
|
+
self.class.get(path, options)
|
10
|
+
end
|
11
|
+
|
12
|
+
def shorten(*)
|
13
|
+
raise InterfaceMethodNotImplementedError.new("Service#shorten must be overridden in subclasses")
|
14
|
+
end
|
15
|
+
|
16
|
+
def authorize(args = {})
|
17
|
+
raise InvalidAuthorizationData.new("Invalid Authorization Data, please provide both login and apikey") unless valid_authorization_data? args
|
18
|
+
@login = options[:login]
|
19
|
+
@apikey = options[:apikey]
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
def valid_authorization_data?(data)
|
24
|
+
[:login, :apikey].all? { |key| data.key? key }
|
25
|
+
end
|
26
|
+
|
27
|
+
def self.authorizable_with(*options)
|
28
|
+
raise InvalidAuthorizationFields.new("Should provide fields to authorize with") if options.empty?
|
29
|
+
@params_to_authorize = options
|
30
|
+
class_eval do
|
31
|
+
options.each { |o| attr_accessor o.to_sym }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mush
|
2
|
+
|
3
|
+
module Services
|
4
|
+
|
5
|
+
## bit.ly and j.mp
|
6
|
+
# login=bitlyapidemo
|
7
|
+
# apiKey=R_0da49e0a9118ff35f52f629d2d71bf07
|
8
|
+
# longUrl=http%3A%2F%2Fbetaworks.com%2F
|
9
|
+
# format=json
|
10
|
+
# domain=j.mp
|
11
|
+
class Bitly < AuthenticatedService
|
12
|
+
|
13
|
+
base_uri 'http://api.bit.ly/v3'
|
14
|
+
|
15
|
+
def shorten(url)
|
16
|
+
invalid_uri_msg = "Please provide a valid URI, including http://"
|
17
|
+
invalid_auth_msg = "Invalid Authorization Data, please provide both login and apikey"
|
18
|
+
|
19
|
+
raise InvalidURI.new invalid_uri_msg if url.empty?
|
20
|
+
raise InvalidAuthorizationData.new(invalid_auth_msg) if login.empty? or apikey.empty?
|
21
|
+
|
22
|
+
options = {}
|
23
|
+
options[:query] = {:login => self.login, :apiKey => self.apikey, :longUrl => url}
|
24
|
+
|
25
|
+
response = get('/shorten', options)
|
26
|
+
|
27
|
+
response["status_code"] == 200 ? response["data"]["url"].chomp : response["status_txt"]
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Mush
|
2
|
+
|
3
|
+
module Services
|
4
|
+
|
5
|
+
class IsGd < Service
|
6
|
+
base_uri 'http://is.gd'
|
7
|
+
|
8
|
+
def shorten(url)
|
9
|
+
raise InvalidURI.new("Please provide a valid URI") if url.empty?
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
options[:query] = {:longurl => url}
|
13
|
+
get('/api.php', options).body.chomp
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Mush
|
2
|
+
|
3
|
+
module Services
|
4
|
+
|
5
|
+
class Unu < Service
|
6
|
+
base_uri 'http://u.nu/'
|
7
|
+
|
8
|
+
def shorten(url)
|
9
|
+
raise InvalidURI.new("Please provide a valid URI") if url.empty?
|
10
|
+
|
11
|
+
options = {}
|
12
|
+
options[:query] = {:url => url}
|
13
|
+
get('/unu-api-simple', options).body.chomp
|
14
|
+
end
|
15
|
+
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
data/mush.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{mush}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Rafael Maga\303\261a"]
|
12
|
+
s.date = %q{2010-08-26}
|
13
|
+
s.description = %q{A gem to shorten URLs using different services, it has one command-line utility for each supported service.}
|
14
|
+
s.email = %q{raf.magana@gmail.com}
|
15
|
+
s.executables = ["bitly", "isgd", "mush", "unu"]
|
16
|
+
s.extra_rdoc_files = [
|
17
|
+
"LICENSE",
|
18
|
+
"README.rdoc"
|
19
|
+
]
|
20
|
+
s.files = [
|
21
|
+
".document",
|
22
|
+
".gitignore",
|
23
|
+
"LICENSE",
|
24
|
+
"README.rdoc",
|
25
|
+
"Rakefile",
|
26
|
+
"VERSION",
|
27
|
+
"bin/bitly",
|
28
|
+
"bin/isgd",
|
29
|
+
"bin/mush",
|
30
|
+
"bin/unu",
|
31
|
+
"lib/mush.rb",
|
32
|
+
"lib/mush/authenticated_service.rb",
|
33
|
+
"lib/mush/errors.rb",
|
34
|
+
"lib/mush/service.rb",
|
35
|
+
"lib/mush/services/bitly.rb",
|
36
|
+
"lib/mush/services/isgd.rb",
|
37
|
+
"lib/mush/services/unu.rb",
|
38
|
+
"mush.gemspec",
|
39
|
+
"test/helper.rb",
|
40
|
+
"test/test_mush.rb"
|
41
|
+
]
|
42
|
+
s.homepage = %q{http://github.com/rafmagana/mush}
|
43
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
44
|
+
s.require_paths = ["lib"]
|
45
|
+
s.rubygems_version = %q{1.3.7}
|
46
|
+
s.summary = %q{A multiple service URL shortener gem with command-line utility}
|
47
|
+
s.test_files = [
|
48
|
+
"test/helper.rb",
|
49
|
+
"test/test_mush.rb"
|
50
|
+
]
|
51
|
+
|
52
|
+
if s.respond_to? :specification_version then
|
53
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
54
|
+
s.specification_version = 3
|
55
|
+
|
56
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
57
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
60
|
+
end
|
61
|
+
else
|
62
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/test/helper.rb
ADDED
data/test/test_mush.rb
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
require 'helper'
|
2
|
+
|
3
|
+
class TestMush < Test::Unit::TestCase
|
4
|
+
|
5
|
+
context "Mush::Service class" do
|
6
|
+
should "include HTTParty module" do
|
7
|
+
assert Mush::Service.include? HTTParty
|
8
|
+
end
|
9
|
+
|
10
|
+
should "define a #shorten method" do
|
11
|
+
assert Mush::Service.new.respond_to? :shorten
|
12
|
+
end
|
13
|
+
|
14
|
+
should "raise and exception if use tries to use #shorten method" do
|
15
|
+
assert_raise Mush::InterfaceMethodNotImplementedError do
|
16
|
+
Mush::Service.new.shorten
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
should "add an instance method called 'get' that wrappes the HTTParty#get method" do
|
21
|
+
assert Mush::Service.new.respond_to? :get
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
context "All Services" do
|
26
|
+
setup do
|
27
|
+
s = Mush::Services
|
28
|
+
@services = [s::IsGd, s::Bitly, s::Unu]
|
29
|
+
end
|
30
|
+
|
31
|
+
should "be subclasses of Mush::Service" do
|
32
|
+
@services.each do |service|
|
33
|
+
assert Mush::Service, service.superclass
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
should "raise an exception if shorten is called with an empty url" do
|
38
|
+
@services.each do |service|
|
39
|
+
assert_raise Mush::InvalidURI do
|
40
|
+
service.new.shorten('')
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
|
47
|
+
context "Service" do
|
48
|
+
setup do
|
49
|
+
@long_url = "http://www.a_very_long_url.com"
|
50
|
+
@shortened_url = "http://is.gd/test"
|
51
|
+
@httparty_response = stub('HTTParty::Reponse', :body => @shortened_url)
|
52
|
+
end
|
53
|
+
|
54
|
+
context "not authorizable" do
|
55
|
+
|
56
|
+
setup do
|
57
|
+
@httparty_response = stub('HTTParty::Reponse', :body => @shortened_url)
|
58
|
+
end
|
59
|
+
|
60
|
+
context "IsGd" do
|
61
|
+
|
62
|
+
should "return a shortened url" do
|
63
|
+
Mush::Services::IsGd.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(@httparty_response)
|
64
|
+
|
65
|
+
isgd = Mush::Services::IsGd.new
|
66
|
+
isgd_result = isgd.shorten(@long_url)
|
67
|
+
|
68
|
+
assert_equal @shortened_url, isgd_result
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
context "Unu" do
|
74
|
+
should "return a shortened url" do
|
75
|
+
Mush::Services::Unu.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(@httparty_response)
|
76
|
+
|
77
|
+
unu = Mush::Services::Unu.new
|
78
|
+
unu_result = unu.shorten(@long_url)
|
79
|
+
|
80
|
+
assert_equal @shortened_url, unu_result
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
context "authorizable" do
|
86
|
+
setup do
|
87
|
+
@response = @shortened_url
|
88
|
+
end
|
89
|
+
|
90
|
+
context "Bitly" do
|
91
|
+
should "has authentication credentials to return a shortened url" do
|
92
|
+
|
93
|
+
httparty_response = stub('HTTParty::Response', :[] => @shortened_url)
|
94
|
+
bitly = Mush::Services::Bitly.new
|
95
|
+
|
96
|
+
assert_raise Mush::InvalidAuthorizationData do
|
97
|
+
bitly.shorten(@long_url)
|
98
|
+
end
|
99
|
+
|
100
|
+
bitly.login = "login"
|
101
|
+
bitly.apikey = "apikey"
|
102
|
+
|
103
|
+
assert_nothing_raised do
|
104
|
+
bitly.shorten(@long_url)
|
105
|
+
end
|
106
|
+
|
107
|
+
Mush::Services::Bitly.any_instance.stubs(:get).with(instance_of(String), instance_of(Hash)).returns(httparty_response)
|
108
|
+
assert_equal @shortened_url, bitly.shorten(@long_url)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mush
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
- 0
|
10
|
+
version: 0.1.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- "Rafael Maga\xC3\xB1a"
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2010-08-26 00:00:00 -05:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: shoulda
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
description: A gem to shorten URLs using different services, it has one command-line utility for each supported service.
|
36
|
+
email: raf.magana@gmail.com
|
37
|
+
executables:
|
38
|
+
- bitly
|
39
|
+
- isgd
|
40
|
+
- mush
|
41
|
+
- unu
|
42
|
+
extensions: []
|
43
|
+
|
44
|
+
extra_rdoc_files:
|
45
|
+
- LICENSE
|
46
|
+
- README.rdoc
|
47
|
+
files:
|
48
|
+
- .document
|
49
|
+
- .gitignore
|
50
|
+
- LICENSE
|
51
|
+
- README.rdoc
|
52
|
+
- Rakefile
|
53
|
+
- VERSION
|
54
|
+
- bin/bitly
|
55
|
+
- bin/isgd
|
56
|
+
- bin/mush
|
57
|
+
- bin/unu
|
58
|
+
- lib/mush.rb
|
59
|
+
- lib/mush/authenticated_service.rb
|
60
|
+
- lib/mush/errors.rb
|
61
|
+
- lib/mush/service.rb
|
62
|
+
- lib/mush/services/bitly.rb
|
63
|
+
- lib/mush/services/isgd.rb
|
64
|
+
- lib/mush/services/unu.rb
|
65
|
+
- mush.gemspec
|
66
|
+
- test/helper.rb
|
67
|
+
- test/test_mush.rb
|
68
|
+
has_rdoc: true
|
69
|
+
homepage: http://github.com/rafmagana/mush
|
70
|
+
licenses: []
|
71
|
+
|
72
|
+
post_install_message:
|
73
|
+
rdoc_options:
|
74
|
+
- --charset=UTF-8
|
75
|
+
require_paths:
|
76
|
+
- lib
|
77
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
78
|
+
none: false
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
hash: 3
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
94
|
+
version: "0"
|
95
|
+
requirements: []
|
96
|
+
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 1.3.7
|
99
|
+
signing_key:
|
100
|
+
specification_version: 3
|
101
|
+
summary: A multiple service URL shortener gem with command-line utility
|
102
|
+
test_files:
|
103
|
+
- test/helper.rb
|
104
|
+
- test/test_mush.rb
|