urifetch 0.0.2.rc4 → 0.0.3.rc0
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +1 -0
- data/Gemfile.lock +2 -0
- data/lib/urifetch/strategy.rb +4 -2
- data/lib/urifetch/version.rb +2 -2
- data/lib/urifetch.rb +37 -0
- data/spec/urifetch_spec.rb +24 -0
- data/urifetch.gemspec +4 -1
- metadata +31 -20
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -6,6 +6,7 @@ GEM
|
|
6
6
|
diff-lcs (1.1.3)
|
7
7
|
git (1.2.5)
|
8
8
|
hashie (1.2.0)
|
9
|
+
imagesize (0.1.1)
|
9
10
|
jeweler (1.6.4)
|
10
11
|
bundler (~> 1.0)
|
11
12
|
git (>= 1.2.5)
|
@@ -43,6 +44,7 @@ DEPENDENCIES
|
|
43
44
|
addressable
|
44
45
|
bundler (= 1.1.rc)
|
45
46
|
hashie
|
47
|
+
imagesize
|
46
48
|
jeweler
|
47
49
|
nokogiri
|
48
50
|
pry
|
data/lib/urifetch/strategy.rb
CHANGED
@@ -2,6 +2,8 @@ module Urifetch
|
|
2
2
|
|
3
3
|
require 'open-uri'
|
4
4
|
require 'nokogiri'
|
5
|
+
require 'image_size'
|
6
|
+
require 'stringio'
|
5
7
|
|
6
8
|
class Strategy
|
7
9
|
|
@@ -12,7 +14,7 @@ module Urifetch
|
|
12
14
|
@@layouts
|
13
15
|
end
|
14
16
|
|
15
|
-
attr_reader :layout, :match_data, :layout_key, :uri
|
17
|
+
attr_reader :layout, :match_data, :layout_key, :uri, :filehead
|
16
18
|
|
17
19
|
def initialize(layout_key,match_data)
|
18
20
|
@layout_key = layout_key
|
@@ -38,7 +40,7 @@ module Urifetch
|
|
38
40
|
run_before!
|
39
41
|
begin
|
40
42
|
@uri = Addressable::URI.heuristic_parse(match_data.string)
|
41
|
-
request = open(@uri.to_s)
|
43
|
+
request = open(@uri.to_s,'rb')
|
42
44
|
status = request.status
|
43
45
|
run_on_success!(request)
|
44
46
|
rescue OpenURI::HTTPError => error
|
data/lib/urifetch/version.rb
CHANGED
data/lib/urifetch.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'hashie/mash'
|
2
2
|
require 'addressable/uri'
|
3
|
+
require 'pry'
|
3
4
|
|
4
5
|
module Urifetch
|
5
6
|
|
@@ -35,6 +36,7 @@ module Urifetch
|
|
35
36
|
end
|
36
37
|
|
37
38
|
Urifetch.register do
|
39
|
+
match /\.(PCX|PSD|XPM|TIFF|XBM|PGM|PBM|PPM|BMP|JPEG|JPG||PNG|GIF|SWF)$/i, :image
|
38
40
|
end
|
39
41
|
|
40
42
|
Urifetch::Strategy.layout(:test) do
|
@@ -76,4 +78,39 @@ Urifetch::Strategy.layout(:default) do
|
|
76
78
|
after_failure do |error|
|
77
79
|
end
|
78
80
|
|
81
|
+
end
|
82
|
+
|
83
|
+
Urifetch::Strategy.layout(:image) do
|
84
|
+
|
85
|
+
before_request do
|
86
|
+
end
|
87
|
+
|
88
|
+
after_success do |request|
|
89
|
+
# Works for ["PCX", "PSD", "XPM", "TIFF", "XBM", "PGM", "PBM", "PPM", "BMP", "JPEG", "PNG", "GIF", "SWF"]
|
90
|
+
|
91
|
+
# Match ID
|
92
|
+
data.match_id = request.base_uri.to_s
|
93
|
+
|
94
|
+
# Title
|
95
|
+
data.title = File.basename(request.base_uri.to_s)
|
96
|
+
|
97
|
+
# File Type
|
98
|
+
data.mime_type = request.meta['content-type']
|
99
|
+
|
100
|
+
# Image Size
|
101
|
+
data.image_size = [nil,nil]
|
102
|
+
3.times do |i|
|
103
|
+
data.image_size = ImageSize.new(request).get_size
|
104
|
+
break if data.image_size != [nil,nil]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
|
108
|
+
after_failure do |error|
|
109
|
+
# File Type
|
110
|
+
data.mime_type = 'unknown'
|
111
|
+
|
112
|
+
# Image Size
|
113
|
+
data.image_size = [0,0]
|
114
|
+
end
|
115
|
+
|
79
116
|
end
|
data/spec/urifetch_spec.rb
CHANGED
@@ -40,6 +40,30 @@ describe Urifetch do
|
|
40
40
|
|
41
41
|
end
|
42
42
|
|
43
|
+
describe 'image' do
|
44
|
+
|
45
|
+
it 'should return image properties and file name for valid png file' do
|
46
|
+
@response = Urifetch.fetch_from("http://www.google.com/intl/en_com/images/srpr/logo3w.png")
|
47
|
+
|
48
|
+
# Check Title
|
49
|
+
@response.data.should have_key(:title)
|
50
|
+
@response.data[:title].should == "logo3w.png"
|
51
|
+
|
52
|
+
# Check Match ID
|
53
|
+
@response.data.should have_key(:match_id)
|
54
|
+
@response.data[:match_id].should == "http://www.google.com/intl/en_com/images/srpr/logo3w.png"
|
55
|
+
|
56
|
+
# Check FileType
|
57
|
+
@response.data.should have_key(:mime_type)
|
58
|
+
@response.data[:mime_type].should == "image/png"
|
59
|
+
|
60
|
+
# Check ImageSize
|
61
|
+
@response.data.should have_key(:image_size)
|
62
|
+
@response.data[:image_size].should == [275, 95]
|
63
|
+
end
|
64
|
+
|
65
|
+
end
|
66
|
+
|
43
67
|
end
|
44
68
|
|
45
69
|
end
|
data/urifetch.gemspec
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "urifetch"
|
8
|
-
s.version = "0.0.
|
8
|
+
s.version = "0.0.3.rc0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Philip Vieira"]
|
@@ -54,6 +54,7 @@ Gem::Specification.new do |s|
|
|
54
54
|
s.add_runtime_dependency(%q<addressable>, [">= 0"])
|
55
55
|
s.add_runtime_dependency(%q<hashie>, [">= 0"])
|
56
56
|
s.add_runtime_dependency(%q<nokogiri>, [">= 0"])
|
57
|
+
s.add_runtime_dependency(%q<imagesize>, [">= 0"])
|
57
58
|
s.add_development_dependency(%q<rspec>, [">= 0"])
|
58
59
|
s.add_development_dependency(%q<bundler>, ["= 1.1.rc"])
|
59
60
|
s.add_development_dependency(%q<jeweler>, [">= 0"])
|
@@ -64,6 +65,7 @@ Gem::Specification.new do |s|
|
|
64
65
|
s.add_dependency(%q<addressable>, [">= 0"])
|
65
66
|
s.add_dependency(%q<hashie>, [">= 0"])
|
66
67
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
68
|
+
s.add_dependency(%q<imagesize>, [">= 0"])
|
67
69
|
s.add_dependency(%q<rspec>, [">= 0"])
|
68
70
|
s.add_dependency(%q<bundler>, ["= 1.1.rc"])
|
69
71
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
@@ -75,6 +77,7 @@ Gem::Specification.new do |s|
|
|
75
77
|
s.add_dependency(%q<addressable>, [">= 0"])
|
76
78
|
s.add_dependency(%q<hashie>, [">= 0"])
|
77
79
|
s.add_dependency(%q<nokogiri>, [">= 0"])
|
80
|
+
s.add_dependency(%q<imagesize>, [">= 0"])
|
78
81
|
s.add_dependency(%q<rspec>, [">= 0"])
|
79
82
|
s.add_dependency(%q<bundler>, ["= 1.1.rc"])
|
80
83
|
s.add_dependency(%q<jeweler>, [">= 0"])
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: urifetch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3.rc0
|
5
5
|
prerelease: 6
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -13,7 +13,7 @@ date: 2012-01-19 00:00:00.000000000Z
|
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
16
|
-
requirement: &
|
16
|
+
requirement: &70260333964420 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70260333964420
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &70260333963780 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70260333963780
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: nokogiri
|
38
|
-
requirement: &
|
38
|
+
requirement: &70260333962960 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,10 +43,21 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :runtime
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *70260333962960
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: imagesize
|
49
|
+
requirement: &70260333962260 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *70260333962260
|
47
58
|
- !ruby/object:Gem::Dependency
|
48
59
|
name: rspec
|
49
|
-
requirement: &
|
60
|
+
requirement: &70260333961500 !ruby/object:Gem::Requirement
|
50
61
|
none: false
|
51
62
|
requirements:
|
52
63
|
- - ! '>='
|
@@ -54,10 +65,10 @@ dependencies:
|
|
54
65
|
version: '0'
|
55
66
|
type: :development
|
56
67
|
prerelease: false
|
57
|
-
version_requirements: *
|
68
|
+
version_requirements: *70260333961500
|
58
69
|
- !ruby/object:Gem::Dependency
|
59
70
|
name: bundler
|
60
|
-
requirement: &
|
71
|
+
requirement: &70260333960560 !ruby/object:Gem::Requirement
|
61
72
|
none: false
|
62
73
|
requirements:
|
63
74
|
- - =
|
@@ -65,10 +76,10 @@ dependencies:
|
|
65
76
|
version: 1.1.rc
|
66
77
|
type: :development
|
67
78
|
prerelease: false
|
68
|
-
version_requirements: *
|
79
|
+
version_requirements: *70260333960560
|
69
80
|
- !ruby/object:Gem::Dependency
|
70
81
|
name: jeweler
|
71
|
-
requirement: &
|
82
|
+
requirement: &70260333959600 !ruby/object:Gem::Requirement
|
72
83
|
none: false
|
73
84
|
requirements:
|
74
85
|
- - ! '>='
|
@@ -76,10 +87,10 @@ dependencies:
|
|
76
87
|
version: '0'
|
77
88
|
type: :development
|
78
89
|
prerelease: false
|
79
|
-
version_requirements: *
|
90
|
+
version_requirements: *70260333959600
|
80
91
|
- !ruby/object:Gem::Dependency
|
81
92
|
name: rcov
|
82
|
-
requirement: &
|
93
|
+
requirement: &70260333958880 !ruby/object:Gem::Requirement
|
83
94
|
none: false
|
84
95
|
requirements:
|
85
96
|
- - ! '>='
|
@@ -87,10 +98,10 @@ dependencies:
|
|
87
98
|
version: '0'
|
88
99
|
type: :development
|
89
100
|
prerelease: false
|
90
|
-
version_requirements: *
|
101
|
+
version_requirements: *70260333958880
|
91
102
|
- !ruby/object:Gem::Dependency
|
92
103
|
name: pry
|
93
|
-
requirement: &
|
104
|
+
requirement: &70260333958040 !ruby/object:Gem::Requirement
|
94
105
|
none: false
|
95
106
|
requirements:
|
96
107
|
- - ! '>='
|
@@ -98,10 +109,10 @@ dependencies:
|
|
98
109
|
version: '0'
|
99
110
|
type: :development
|
100
111
|
prerelease: false
|
101
|
-
version_requirements: *
|
112
|
+
version_requirements: *70260333958040
|
102
113
|
- !ruby/object:Gem::Dependency
|
103
114
|
name: rdoc
|
104
|
-
requirement: &
|
115
|
+
requirement: &70260333957300 !ruby/object:Gem::Requirement
|
105
116
|
none: false
|
106
117
|
requirements:
|
107
118
|
- - ! '>='
|
@@ -109,7 +120,7 @@ dependencies:
|
|
109
120
|
version: '0'
|
110
121
|
type: :development
|
111
122
|
prerelease: false
|
112
|
-
version_requirements: *
|
123
|
+
version_requirements: *70260333957300
|
113
124
|
description: Urifetch allows you to fetch data from any URL using pattern matching.
|
114
125
|
The library allows for dynamically adding match handlers as well as build your own
|
115
126
|
strategies.
|
@@ -158,7 +169,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
158
169
|
version: '0'
|
159
170
|
segments:
|
160
171
|
- 0
|
161
|
-
hash:
|
172
|
+
hash: 219273389632171502
|
162
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
163
174
|
none: false
|
164
175
|
requirements:
|