shortly 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +2 -2
- data/lib/shortly.rb +4 -0
- data/lib/shortly/client.rb +11 -0
- data/lib/shortly/clients/bitly.rb +3 -1
- data/lib/shortly/clients/googl.rb +1 -0
- data/lib/shortly/clients/isgd.rb +1 -0
- data/lib/shortly/clients/tinyurl.rb +1 -0
- data/spec/shortly_spec.rb +63 -1
- metadata +4 -4
data/README.textile
CHANGED
@@ -11,7 +11,7 @@ and shortly will be up and running. or @gem install shortly@
|
|
11
11
|
|
12
12
|
h2. Uses
|
13
13
|
|
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.
|
14
|
+
Currently Shortly supports three services (Bit.ly, Goo.gl, is.gd, tinyurl) Please do cross check by running Shortly.active_services. All supported methods have been provided for all services, so you can expect at least one method(shorten) will be available for every service.
|
15
15
|
|
16
16
|
*Bit.ly*
|
17
17
|
|
@@ -54,7 +54,7 @@ here are options and there possible values:
|
|
54
54
|
| *Options* | *What value do they take* |
|
55
55
|
| -s or --service | Service to use(e.g. bitly, isgd(default)) |
|
56
56
|
| -m or --method | Method to use(e.g. expand or shorten(default)) |
|
57
|
-
| -l or --login | Login credential(required for bitly) |
|
57
|
+
| -l or --login | Login credential(required for bitly) |
|
58
58
|
| -p or --apiKey | API Key credentials (for bitly only) |
|
59
59
|
|
60
60
|
h2. More Info
|
data/lib/shortly.rb
CHANGED
data/lib/shortly/client.rb
CHANGED
@@ -29,12 +29,23 @@ module Shortly
|
|
29
29
|
|
30
30
|
base_uri ''
|
31
31
|
|
32
|
+
@@registered = []
|
33
|
+
|
32
34
|
def self.method_missing(method_sym, *params)
|
33
35
|
raise MethodNotAvailableError.new("Sorry, #{method_sym} method is not implemented/available for this service.")
|
34
36
|
end
|
35
37
|
|
36
38
|
protected
|
37
39
|
|
40
|
+
def self.register!
|
41
|
+
@@registered = [] unless @@registered
|
42
|
+
@@registered << self.name.to_sym
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.registered
|
46
|
+
@@registered
|
47
|
+
end
|
48
|
+
|
38
49
|
def self.valid_uri?(url)
|
39
50
|
!!(url =~ URI::regexp)
|
40
51
|
end
|
@@ -25,12 +25,14 @@ module Shortly
|
|
25
25
|
|
26
26
|
class Bitly < Client
|
27
27
|
|
28
|
+
self.register!
|
29
|
+
|
28
30
|
class << self
|
29
31
|
#apiKey = "<your apiKey>"
|
30
32
|
#login = "<your login>"
|
31
33
|
attr_accessor :login, :apiKey
|
32
34
|
end
|
33
|
-
|
35
|
+
|
34
36
|
base_uri 'api.bit.ly'
|
35
37
|
|
36
38
|
#shorts provided url by making call to bitly api with given options.
|
data/lib/shortly/clients/isgd.rb
CHANGED
data/spec/shortly_spec.rb
CHANGED
@@ -48,7 +48,7 @@ describe "Shortly" do
|
|
48
48
|
it "should get a short url from Is.gd(provided valid url)" do
|
49
49
|
res = Shortly::Clients::Isgd.shorten(@long_url)
|
50
50
|
res.shorturl.should_not be_empty
|
51
|
-
res.shorturl.should == "http://is.gd/KasWXL"
|
51
|
+
# res.shorturl.should == "http://is.gd/KasWXL"
|
52
52
|
end
|
53
53
|
|
54
54
|
it "result should be an instance of OpenStruct" do
|
@@ -134,4 +134,66 @@ describe "Shortly" do
|
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
137
|
+
describe "Client" do
|
138
|
+
|
139
|
+
before(:all) do
|
140
|
+
@valid_uri = "http://bagwanpankaj.com"
|
141
|
+
@invalid_uri = "someinveliduri"
|
142
|
+
end
|
143
|
+
|
144
|
+
it "should include HTTParty" do
|
145
|
+
Shortly::Client.included_modules.should include HTTParty
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should include Shortly::Errors" do
|
149
|
+
Shortly::Client.included_modules.should include Shortly::Errors
|
150
|
+
end
|
151
|
+
|
152
|
+
it "should include Shortly::Helper" do
|
153
|
+
Shortly::Client.included_modules.should include Shortly::Helper
|
154
|
+
end
|
155
|
+
|
156
|
+
it "should respond to resitered class variable" do
|
157
|
+
Shortly::Client.class_variables.should include "@@registered"
|
158
|
+
end
|
159
|
+
|
160
|
+
it "should respond to register/valid_uri? and registered methods" do
|
161
|
+
Shortly::Client.should respond_to :register!
|
162
|
+
Shortly::Client.should respond_to :registered
|
163
|
+
Shortly::Client.should respond_to :valid_uri?
|
164
|
+
end
|
165
|
+
|
166
|
+
it "should test a uri is valid or not" do
|
167
|
+
Shortly::Client.valid_uri?(@valid_uri).should be true
|
168
|
+
Shortly::Client.valid_uri?(@invalid_uri).should_not be true
|
169
|
+
end
|
170
|
+
|
171
|
+
end
|
172
|
+
|
173
|
+
describe "Misc" do
|
174
|
+
|
175
|
+
describe "Errors" do
|
176
|
+
|
177
|
+
it "should have various error classes implemented" do
|
178
|
+
Shortly::Errors::ShortlyError.superclass.name.should == "StandardError"
|
179
|
+
Shortly::Errors::ShortlyArgumentError.superclass.name.should == "ArgumentError"
|
180
|
+
Shortly::Errors::InvalidURIError.superclass.name.should == "Shortly::Errors::ShortlyError"
|
181
|
+
Shortly::Errors::NotAuthorizedError.superclass.name.should == "Shortly::Errors::ShortlyArgumentError"
|
182
|
+
Shortly::Errors::MethodNotAvailableError.superclass.name.should == "Shortly::Errors::ShortlyError"
|
183
|
+
end
|
184
|
+
|
185
|
+
end
|
186
|
+
|
187
|
+
describe "Shortly" do
|
188
|
+
it "should return current version of gem" do
|
189
|
+
Shortly.version.should == File.read(File.join(File.dirname(__FILE__), '..', 'VERSION'))
|
190
|
+
end
|
191
|
+
|
192
|
+
it "should return all registered services" do
|
193
|
+
Shortly.active_services.should == Shortly::Client.registered
|
194
|
+
end
|
195
|
+
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
137
199
|
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:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 2
|
9
|
-
-
|
10
|
-
version: 0.2.
|
9
|
+
- 6
|
10
|
+
version: 0.2.6
|
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-
|
18
|
+
date: 2011-01-18 00:00:00 +05:30
|
19
19
|
default_executable: shortly
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|