twimage 0.0.5 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -14,11 +14,20 @@ Instantiate the appropriate service and give it the standard URL returned by tha
14
14
 
15
15
  Twimage will create a Ruby tempfile with the image. To get the tempfile:
16
16
 
17
- result.image
17
+ result.tempfile
18
18
 
19
19
  Save the image to your local system, upload to S3, etc. As soon as there are no more references to the
20
20
  tempfile in your code it will be unlinked (deleted). Enjoy!
21
21
 
22
+ ## Support
23
+
24
+ Twimage currently supports the following services:
25
+
26
+ * twitpic - http://twitpic.com
27
+ * yfrog - http://yfrog.com
28
+
22
29
  ## Contributing
23
30
 
24
- To add a parser, fork this repo and then send me a pull request, that's it!
31
+ To add a parser, fork this repo and then send me a pull request. Your parser should make a reasonable attempt to
32
+ retrieve the highest resolution image possible and return errors if the service URL returns a 404 or the proper
33
+ image tag couldn't be found (see twitpic.rb for an example).
data/lib/twimage.rb CHANGED
@@ -8,6 +8,7 @@ $:.unshift(File.dirname(__FILE__)) unless
8
8
 
9
9
  require 'twimage/base'
10
10
  require 'twimage/twitpic'
11
+ require 'twimage/yfrog'
11
12
  require 'twimage/version'
12
13
 
13
14
  module Twimage
@@ -3,8 +3,9 @@ module Twimage
3
3
 
4
4
  def initialize(service_url)
5
5
  @service_url = service_url
6
+ full_res_service_url = @service_url + '/full'
6
7
  begin
7
- image_tag = Nokogiri::HTML(open(@service_url)).css('#photo-display').first
8
+ image_tag = Nokogiri::HTML(open(full_res_service_url)).css('body > img').first
8
9
  rescue OpenURI::HTTPError
9
10
  raise ServiceURLInvalid, "The service URL #{@service_url} was not found (returned a 404)"
10
11
  end
@@ -1,3 +1,3 @@
1
1
  module Twimage
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -0,0 +1,22 @@
1
+ module Twimage
2
+ class Yfrog < Twimage::Base
3
+
4
+ def initialize(service_url)
5
+ @service_url = service_url
6
+ full_res_service_url = @service_url.gsub(/\.com/, '.com/z')
7
+ begin
8
+ image_tag = Nokogiri::HTML(open(full_res_service_url)).css('#the-image img').first
9
+ rescue OpenURI::HTTPError
10
+ raise ServiceURLInvalid, "The service URL #{@service_url} was not found (returned a 404)"
11
+ end
12
+
13
+ if image_tag
14
+ @image_url = image_tag['src']
15
+ super
16
+ else
17
+ raise ImageNotFound, "The service URL #{@service_url} did not contain an identifiable image"
18
+ end
19
+ end
20
+
21
+ end
22
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: twimage
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.5
5
+ version: 0.0.8
6
6
  platform: ruby
7
7
  authors:
8
8
  - Rob Cameron
@@ -54,6 +54,7 @@ files:
54
54
  - lib/twimage/base.rb
55
55
  - lib/twimage/twitpic.rb
56
56
  - lib/twimage/version.rb
57
+ - lib/twimage/yfrog.rb
57
58
  - twimage.gemspec
58
59
  has_rdoc: true
59
60
  homepage: ""