yfrog 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +2 -0
- data/lib/yfrog.rb +9 -0
- data/spec/yfrog_spec.rb +53 -23
- data/yfrog.gemspec +1 -1
- metadata +2 -2
data/README.md
CHANGED
data/lib/yfrog.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
module YFrog
|
2
2
|
class << self
|
3
|
+
|
4
|
+
def valid_url?(url)
|
5
|
+
!!url.match("yfrog")
|
6
|
+
end
|
7
|
+
|
3
8
|
def image_url_for(url, options = {:format => :medium} )
|
9
|
+
raise ArgumentError unless valid_url?(url)
|
10
|
+
|
11
|
+
url = "http://" << url unless url =~ /^http:\/\//
|
12
|
+
|
4
13
|
suffix = case options.delete(:format)
|
5
14
|
when :medium; ":medium"
|
6
15
|
when :iphone; ":iphone"
|
data/spec/yfrog_spec.rb
CHANGED
@@ -7,41 +7,71 @@ describe YFrog do
|
|
7
7
|
it { should be }
|
8
8
|
end
|
9
9
|
|
10
|
+
describe "#valid_url?" do
|
11
|
+
subject { YFrog.valid_url?(url) }
|
12
|
+
context "with a non-yfrog url" do
|
13
|
+
let(:url) { "http://yfrawg.com/kjugqgbj" }
|
14
|
+
it { should == false }
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with a yfrog url" do
|
18
|
+
let(:url) { "http://yfrog.com/kjugqgbj" }
|
19
|
+
it { should == true }
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
|
10
24
|
describe "#image_url_for" do
|
11
|
-
let(:url) { "http://yfrog.com/kjugqgbj" }
|
12
25
|
|
13
|
-
context "
|
14
|
-
|
15
|
-
it
|
26
|
+
context "with a non-yfrog url" do
|
27
|
+
let(:url) { "http://yfrawg.com/kjugqgbj" }
|
28
|
+
it "should raise an error" do
|
29
|
+
expect { YFrog.image_url_for(url) }.to raise_error(ArgumentError)
|
30
|
+
end
|
16
31
|
end
|
17
32
|
|
18
|
-
context "with a
|
19
|
-
|
20
|
-
|
21
|
-
|
33
|
+
context "with a yfrog url" do
|
34
|
+
let(:url) { "http://yfrog.com/kjugqgbj" }
|
35
|
+
|
36
|
+
context "without http://" do
|
37
|
+
let(:url) { "yfrog.com/kjugqgbj" }
|
38
|
+
subject { YFrog.image_url_for(url) }
|
22
39
|
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
23
40
|
end
|
24
41
|
|
25
|
-
context "
|
26
|
-
|
27
|
-
it { should == "http://yfrog.com/kjugqgbj:
|
42
|
+
context "without arguments" do
|
43
|
+
subject { YFrog.image_url_for(url) }
|
44
|
+
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
28
45
|
end
|
29
46
|
|
30
|
-
context "
|
31
|
-
|
32
|
-
|
33
|
-
|
47
|
+
context "with a format specified" do
|
48
|
+
subject { YFrog.image_url_for(url, :format => format) }
|
49
|
+
context "medium" do
|
50
|
+
let(:format) { :medium }
|
51
|
+
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
52
|
+
end
|
34
53
|
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
context "iphone" do
|
55
|
+
let(:format) { :iphone }
|
56
|
+
it { should == "http://yfrog.com/kjugqgbj:iphone" }
|
57
|
+
end
|
58
|
+
|
59
|
+
context "small" do
|
60
|
+
let(:format) { :small }
|
61
|
+
it { should == "http://yfrog.com/kjugqgbj:small" }
|
62
|
+
end
|
63
|
+
|
64
|
+
context "thumb" do
|
65
|
+
let(:format) { :thumb }
|
66
|
+
it { should == "http://yfrog.com/kjugqgbj:small" }
|
67
|
+
end
|
38
68
|
end
|
39
|
-
end
|
40
69
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
70
|
+
context "with an unsupported format" do
|
71
|
+
let(:format) { :omgwtfbbq }
|
72
|
+
it "should raise an exception" do
|
73
|
+
expect { YFrog.image_url_for(url, :format => format) }.to raise_error(ArgumentError)
|
74
|
+
end
|
45
75
|
end
|
46
76
|
end
|
47
77
|
end
|
data/yfrog.gemspec
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yfrog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-10-
|
12
|
+
date: 2011-10-16 00:00:00.000000000 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
description: work with yfrog urls to get image urls and such
|