fetch_meizi 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/fetch_meizi.rb CHANGED
@@ -9,8 +9,21 @@ class Meizi
9
9
  def self.fetch
10
10
  open(URL) do |rss|
11
11
  feed = RSS::Parser.parse(rss)
12
- $1 if feed.items.first.description =~ /src=\"(\S*)\"/
12
+ feed.items.each do |item|
13
+ if item.description =~ /src=\"(\S*)\"/
14
+ @image_url = $1
15
+ break if image_url_avaliable?
16
+ end
17
+ end
18
+ @image_url
13
19
  end
14
20
  end
15
21
 
22
+ private
23
+ def self.image_url_avaliable?
24
+ res = Net::HTTP.get_response(URI(@image_url))
25
+ res['content-type'].match(/image\/(jpeg|png|)/)
26
+ end
27
+
28
+
16
29
  end
@@ -1,3 +1,3 @@
1
1
  module FetchMeizi
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.2"
3
3
  end
@@ -1,4 +1,5 @@
1
1
  require 'test/unit'
2
+ require 'net/http'
2
3
  require_relative '../lib/fetch_meizi'
3
4
 
4
5
  class FetchMeiziTest < Test::Unit::TestCase
@@ -7,4 +8,9 @@ class FetchMeiziTest < Test::Unit::TestCase
7
8
  assert Meizi.fetch.match(/\Ahttp.*(jpeg|jpg|gif|png)\Z/)
8
9
  end
9
10
 
11
+ def test_fetch_meizi_should_return_a_visiable_image
12
+ res = Net::HTTP.get_response(URI(Meizi.fetch))
13
+ assert res['content-type'].match(/image\/(jpeg|png|)/)
14
+ end
15
+
10
16
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fetch_meizi
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
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: 2013-05-17 00:00:00.000000000 Z
12
+ date: 2013-05-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler