imageurl 0.1.0
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.
- data/.gitignore +1 -0
- data/.rvmrc +21 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/imageurl.gemspec +17 -0
- data/lib/imageurl.rb +37 -0
- data/spec/imageurl_spec.rb +91 -0
- metadata +65 -0
data/.gitignore
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
pkg
|
data/.rvmrc
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
environment_id="ruby-1.9.2-p290@imageurl"
|
4
|
+
|
5
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
6
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]]
|
7
|
+
then
|
8
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
9
|
+
|
10
|
+
if [[ -s "${rvm_path:-$HOME/.rvm}/hooks/after_use" ]]
|
11
|
+
then
|
12
|
+
. "${rvm_path:-$HOME/.rvm}/hooks/after_use"
|
13
|
+
fi
|
14
|
+
else
|
15
|
+
if ! rvm --create "$environment_id"
|
16
|
+
then
|
17
|
+
echo "Failed to create RVM environment '${environment_id}'."
|
18
|
+
exit 1
|
19
|
+
fi
|
20
|
+
fi
|
21
|
+
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# installation
|
2
|
+
|
3
|
+
$ gem install imageurl
|
4
|
+
|
5
|
+
# usage
|
6
|
+
|
7
|
+
require 'imageurl'
|
8
|
+
|
9
|
+
valid_url = ImageURL.valid_url?("http://yfrog.com/kjugqgbj")
|
10
|
+
# => true
|
11
|
+
|
12
|
+
valid_url = ImageURL.valid_url?("PUT A TWITPIC URL HERE")
|
13
|
+
# => true
|
14
|
+
|
15
|
+
valid_url = ImageURL.valid_url?("http://google.com")
|
16
|
+
# => false
|
17
|
+
|
18
|
+
|
19
|
+
example of usage in a Rails view:
|
20
|
+
|
21
|
+
image_tag ImageURL.image_url_for("http://yfrog.com/kjugqgbj")
|
22
|
+
|
23
|
+
# license
|
24
|
+
|
25
|
+
MIT dude!
|
26
|
+
|
27
|
+
# contributing
|
28
|
+
|
29
|
+
please do.
|
data/Rakefile
ADDED
data/imageurl.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "imageurl"
|
5
|
+
s.version = "0.1.0"
|
6
|
+
s.date = Time.now.strftime('%Y-%m-%d')
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ["Sean Moon"]
|
9
|
+
s.email = ["seanmoon@seanmoon.com"]
|
10
|
+
s.homepage = "http://github.com/seanmoon/imageurl"
|
11
|
+
s.summary = %Q{image hosting to asset URL gem}
|
12
|
+
s.description = %Q{work with yfrog and twitpic urls to get image urls}
|
13
|
+
s.has_rdoc = false
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.require_paths = ['lib']
|
16
|
+
s.add_development_dependency 'rspec'
|
17
|
+
end
|
data/lib/imageurl.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
module ImageURL
|
2
|
+
class << self
|
3
|
+
|
4
|
+
def valid_url?(url)
|
5
|
+
yfrog_url?(url) || twitpic_url?(url)
|
6
|
+
end
|
7
|
+
|
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
|
+
|
13
|
+
if yfrog_url?(url)
|
14
|
+
suffix = case options.delete(:format)
|
15
|
+
when :medium; ":medium"
|
16
|
+
when :iphone; ":iphone"
|
17
|
+
when :small; ":small"
|
18
|
+
when :thumb; ":small"
|
19
|
+
end
|
20
|
+
raise ArgumentError unless suffix
|
21
|
+
url + suffix
|
22
|
+
else
|
23
|
+
"https://twitpic.com/show/large/#{url.gsub(/^.*\//, "")}"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
private
|
28
|
+
|
29
|
+
def yfrog_url?(url)
|
30
|
+
!!url.match("yfrog")
|
31
|
+
end
|
32
|
+
|
33
|
+
def twitpic_url?(url)
|
34
|
+
!!url.match("twitpic")
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,91 @@
|
|
1
|
+
require 'imageurl'
|
2
|
+
|
3
|
+
describe ImageURL do
|
4
|
+
|
5
|
+
describe "some basics" do
|
6
|
+
subject { ImageURL }
|
7
|
+
it { should be }
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "#valid_url?" do
|
11
|
+
subject { ImageURL.valid_url?(url) }
|
12
|
+
context "with a non-yfrog, non-twitpic 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
|
+
context "with a twitpic url" do
|
23
|
+
let(:url) { "http://twitpic.com/304k8h" }
|
24
|
+
it { should == true }
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe "#image_url_for" do
|
29
|
+
|
30
|
+
context "with a non-yfrog, non-twitpic url" do
|
31
|
+
let(:url) { "http://yfrawg.com/kjugqgbj" }
|
32
|
+
it "should raise an error" do
|
33
|
+
expect { ImageURL.image_url_for(url) }.to raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
context "with a yfrog url" do
|
38
|
+
let(:url) { "http://yfrog.com/kjugqgbj" }
|
39
|
+
|
40
|
+
context "without http://" do
|
41
|
+
let(:url) { "yfrog.com/kjugqgbj" }
|
42
|
+
subject { ImageURL.image_url_for(url) }
|
43
|
+
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
44
|
+
end
|
45
|
+
|
46
|
+
context "without arguments" do
|
47
|
+
subject { ImageURL.image_url_for(url) }
|
48
|
+
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with a format specified" do
|
52
|
+
subject { ImageURL.image_url_for(url, :format => format) }
|
53
|
+
context "medium" do
|
54
|
+
let(:format) { :medium }
|
55
|
+
it { should == "http://yfrog.com/kjugqgbj:medium" }
|
56
|
+
end
|
57
|
+
|
58
|
+
context "iphone" do
|
59
|
+
let(:format) { :iphone }
|
60
|
+
it { should == "http://yfrog.com/kjugqgbj:iphone" }
|
61
|
+
end
|
62
|
+
|
63
|
+
context "small" do
|
64
|
+
let(:format) { :small }
|
65
|
+
it { should == "http://yfrog.com/kjugqgbj:small" }
|
66
|
+
end
|
67
|
+
|
68
|
+
context "thumb" do
|
69
|
+
let(:format) { :thumb }
|
70
|
+
it { should == "http://yfrog.com/kjugqgbj:small" }
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
context "with an unsupported format" do
|
75
|
+
let(:format) { :omgwtfbbq }
|
76
|
+
it "should raise an exception" do
|
77
|
+
expect { ImageURL.image_url_for(url, :format => format) }.to raise_error(ArgumentError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "with a twitpic url" do
|
83
|
+
let(:url) { "http://twitpic.com/304k8h" }
|
84
|
+
|
85
|
+
context "without arguments" do
|
86
|
+
subject { ImageURL.image_url_for(url) }
|
87
|
+
it { should == "https://twitpic.com/show/large/304k8h" }
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: imageurl
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Sean Moon
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-10-24 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: rspec
|
17
|
+
requirement: &2156973600 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ! '>='
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '0'
|
23
|
+
type: :development
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2156973600
|
26
|
+
description: work with yfrog and twitpic urls to get image urls
|
27
|
+
email:
|
28
|
+
- seanmoon@seanmoon.com
|
29
|
+
executables: []
|
30
|
+
extensions: []
|
31
|
+
extra_rdoc_files: []
|
32
|
+
files:
|
33
|
+
- .gitignore
|
34
|
+
- .rvmrc
|
35
|
+
- README.md
|
36
|
+
- Rakefile
|
37
|
+
- imageurl.gemspec
|
38
|
+
- lib/imageurl.rb
|
39
|
+
- spec/imageurl_spec.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: http://github.com/seanmoon/imageurl
|
42
|
+
licenses: []
|
43
|
+
post_install_message:
|
44
|
+
rdoc_options: []
|
45
|
+
require_paths:
|
46
|
+
- lib
|
47
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
48
|
+
none: false
|
49
|
+
requirements:
|
50
|
+
- - ! '>='
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '0'
|
53
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
54
|
+
none: false
|
55
|
+
requirements:
|
56
|
+
- - ! '>='
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: '0'
|
59
|
+
requirements: []
|
60
|
+
rubyforge_project:
|
61
|
+
rubygems_version: 1.6.2
|
62
|
+
signing_key:
|
63
|
+
specification_version: 3
|
64
|
+
summary: image hosting to asset URL gem
|
65
|
+
test_files: []
|