shortly 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -2,21 +2,60 @@ h1. Shortly
2
2
 
3
3
  A Ruby wrapper for various url shortener services
4
4
 
5
- h2. Getting Started
5
+ h2. Installation
6
6
 
7
7
  create a dependency in your Gemfile
8
+ @gem 'shortly'@ then run
9
+ @bundle install@
10
+ and shortly will be up and running. or @gem install shortly@
8
11
 
9
- @gem 'shortly'@
12
+ h2. Uses
10
13
 
11
- then run
14
+ Currently Shortly supports three services (Bit.ly, Goo.gl, is.gd, tinyurl). All supported methods have been provided for all services, so you can expect at least one method(shorten) will be available for every service.
12
15
 
13
- @bundle install@
16
+ *Bit.ly*
14
17
 
15
- and shortly will be up and running.
18
+ @bitly = Shortly::Clients::Bitly
19
+ bitly.shorten('http://justatest.com', {:apiKey => 'R_your_api_key', :login => 'your_login'})@
16
20
 
17
- h2. Uses
21
+ Optionally you can set apiKey and login beforehand (it would be more DRY i think if you only gonna use bitly services).
22
+
23
+ @bitly = Shortly::Clients::Bitly@
24
+ @bitly.apiKey = 'your_api_key'@
25
+ @bitly.login = 'your_login'@
26
+ @bitly.shorten('http://justatest.com').url@
27
+ @bitly.expand('http://bit.ly/imshort').long_url@
28
+
29
+ *Goo.gl*
30
+
31
+ @googl = Shortly::Clients::Googl@
32
+ @googl.shorten('http://justatest.com').short_url@
33
+
34
+ *Is.gd*
35
+
36
+ @isgd = Shortly::Clients::Isgd@
37
+ @isgd.shorten('http://justatest.com').shorturl@
38
+
39
+ *Tinyurl.com*
40
+
41
+ @tinyurl = Shortly::Clients::Tinyurl@
42
+ @tinyurl.shorten('http://justatest.com').shorturl@
43
+
44
+ h4. Command Line Utility
45
+
46
+ Shortly also provides command line utility. See some uses below.
47
+ @shortly 'http://shortme.com/'@
48
+
49
+ By default it uses Googl to short urls but you can specify which service to use. Type @shortly -h@ for more info
50
+ @shortly 'http://shortme.com/' -s bitly -l '<your-login>' -p '<your-apiKey>' -m method-to-use@
51
+
52
+ here are options and there possible values:
18
53
 
19
- Coming Shortly(or see the code)
54
+ | *Options* | *What value do they take* |
55
+ | -s or --service | Service to use(e.g. bitly, isgd(default)) |
56
+ | -m or --method | Method to use(e.g. expand or shorten(default)) |
57
+ | -l or --login | Login credential(required for bitly) |
58
+ | -p or --apiKey | API Key credentials (for bitly only) |
20
59
 
21
60
  h2. More Info
22
61
 
@@ -10,7 +10,12 @@ require 'shortly'
10
10
 
11
11
  ORIG_ARGV = ARGV.dup
12
12
 
13
- services = {:googl => Shortly::Clients::Googl, :isgd => Shortly::Clients::Isgd, :bitly => Shortly::Clients::Bitly}
13
+ services = {
14
+ :googl => Shortly::Clients::Googl,
15
+ :isgd => Shortly::Clients::Isgd,
16
+ :bitly => Shortly::Clients::Bitly,
17
+ :tinyurl => Shortly::Clients::Tinyurl
18
+ }
14
19
 
15
20
  options = {:service => :googl, :method => :shorten}
16
21
 
@@ -75,10 +80,11 @@ end
75
80
  response = command.send(options[:method], options[:url])
76
81
 
77
82
  output = case options[:service]
78
- when :bitly then response.url || response.long_url
79
- when :googl then response.short_url
80
- when :isgd then response.shorturl
81
- else abort("Something went wrong. Please raise an issue on Github")
83
+ when :bitly then response.url || response.long_url
84
+ when :googl then response.short_url
85
+ when :isgd then response.shorturl
86
+ when :tinyurl then response.shorturl
87
+ else abort("Something went wrong. Please raise an issue on Github")
82
88
  end
83
89
 
84
90
  puts output
@@ -8,6 +8,7 @@ require 'shortly/client'
8
8
  require 'shortly/clients/bitly'
9
9
  require 'shortly/clients/googl'
10
10
  require 'shortly/clients/isgd'
11
+ require 'shortly/clients/tinyurl'
11
12
 
12
13
  module Shortly
13
14
 
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2011 Bagwan Pankaj
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.
21
+
22
+ module Shortly
23
+
24
+ module Clients
25
+
26
+ class Tinyurl < Client
27
+
28
+ base_uri 'tinyurl.com'
29
+
30
+ #shorts provided url by making call to tinyurl api with given options.
31
+ def self.shorten(url, options = {})
32
+ raise InvalidURIError.new("provided URI is invalid.") unless valid_uri?(url)
33
+ response = post("/api-create.php", {:body => {:url => url}}).chomp
34
+ OpenStruct.new({:shorturl => response})
35
+ end
36
+
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -103,4 +103,35 @@ describe "Shortly" do
103
103
 
104
104
  end
105
105
 
106
+ #tests for client tinyurl
107
+ describe "TinyUrl" do
108
+ before(:all) do
109
+ @long_url = "http://bagwanpankaj.com"
110
+ @invalid_url = "bagwanpankaj.com"
111
+ end
112
+
113
+ it "should get a short url from TinyUrl(provided valid url)" do
114
+ res = Shortly::Clients::Tinyurl.shorten(@long_url)
115
+ res.shorturl.should_not be_empty
116
+ res.shorturl.should == "http://tinyurl.com/6jt3pjr"
117
+ end
118
+
119
+ it "result should be an instance of OpenStruct" do
120
+ res = Shortly::Clients::Tinyurl.shorten(@long_url)
121
+ res.should be_an_instance_of(OpenStruct)
122
+ end
123
+
124
+ it "should throw an error on wrong uri format" do
125
+ lambda do
126
+ Shortly::Clients::Tinyurl.shorten(@invalid_url)
127
+ end.should raise_error(Shortly::Errors::InvalidURIError)
128
+ end
129
+
130
+ it "should raise MethodNotAvailableError if method is not implemented for" do
131
+ lambda do
132
+ Shortly::Clients::Tinyurl.expand(@long_url)
133
+ end.should raise_error(Shortly::Errors::MethodNotAvailableError)
134
+ end
135
+ end
136
+
106
137
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shortly
3
3
  version: !ruby/object:Gem::Version
4
- hash: 31
4
+ hash: 29
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 4
10
- version: 0.2.4
9
+ - 5
10
+ version: 0.2.5
11
11
  platform: ruby
12
12
  authors:
13
13
  - Bagwan Pankaj
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-01-16 00:00:00 +05:30
18
+ date: 2011-01-17 00:00:00 +05:30
19
19
  default_executable: shortly
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -111,6 +111,7 @@ files:
111
111
  - lib/shortly/clients/googl.rb
112
112
  - lib/shortly/clients/isgd.rb
113
113
  - lib/shortly/clients/rubyurl.rb
114
+ - lib/shortly/clients/tinyurl.rb
114
115
  - lib/shortly/errors.rb
115
116
  - lib/shortly/helper.rb
116
117
  - LICENSE.txt